Jeff Roder

Jeff Roder

  • NA
  • 4
  • 0

C# encryption reimplementation from C++ legacy code

Jul 24 2009 11:03 AM

Hello all,
 
I'm a new user to this forum, so please bear with me if I make newbie mistakes...
 
THE PROBLEM
 
I have a visual C++ encryption project that I need to reimplement in C# .NET environment using MS VS 2005.  Reimplementing seems manageable, most of the code is fileIO and stream manipulation.  The part I am not sure about is the encryption classes used.  Specifically, are there parallels in C# that will perform the IDENTICAL encryption and decryption?  The encryption and hashing functions used in the VC++ project are the following:
 
   CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, 0)
   CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash)
   CryptHashData(hHash, (unsigned char*)szPassword, strlen(szPassword), 0)
   CryptDeriveKey(hProv, CALG_RC4, hHash, (40 << 16) | CRYPT_EXPORTABLE, &hKey)
   CryptDestroyHash(hHash)
   CryptEncrypt(hKey, 0, eof, 0, pbBuffer, &dwCount, dwBufferLen)   
   CryptDestroyKey(hKey)
   CryptDestroyHash(hHash)
   CryptReleaseContext(hProv, 0)
 
QUESTIONS:
 
  1. For the functions listed above, are there parallel versions in C#?
  2. Does CALG_MD5 hashing exist in C#?
  3. Does CALG_RC4 encryption exist in C#? 
  4. If 2 and 3 are true, will the reimplemented encryption be the same as the C++ version all things being equal?

Thanks much in advance. 

Answers (1)