المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Getting this simple crypto function to work in c#?



C# Programming
08-10-2011, 02:22 AM
Hello.

I have these 2 small functions that work together to decrypt a small amount of data, that is also of fixed length, a byte array of length 15;


Does anyone know if it could be re-written for c#?

I have tried a few things but to no avail, for example, I do not know what memset() does, so do not know what to do in place within c#.

I do not want to use some large crypto library, and the reason for this small function is so that the encrypted data is the exact same length of the original data, 15 bytes.

So, here is the code....and thank you.



void DecryptInstID(unsigned char *InstID){ unsigned char *Left, *Right; unsigned char Aux[8]; int i, k; Left = InstID; Right = InstID + 8; for (i = 0; i < 4; i++) { KeyedHash(Left, Aux); for (k = 0; k < 8; k++) Aux[k] ^= Right[k]; memcpy(Right, Left, 8); memcpy(Left, Aux, 8); }}

void KeyedHash(unsigned char *Data, unsigned char *Result){ SHA_CTX Context; unsigned char Digest[20]; static unsigned char Key[4] = { // The key has been removed from the source code. }; SHA1_Init(&Context); SHA1_Update(&Context, Data, 8); SHA1_Update(&Context, Key, 4); SHA1_Final(Digest, &Context); memcpy(Result, Digest, 8);}
Thank you!

Regards,
Stephen