Re: Converting old C++ crypto code to .NET

From: Alek Davis (alek_xDOTx_davis_xATx_intel_xDOTx_com)
Date: 02/05/04


Date: Thu, 5 Feb 2004 08:52:21 -0800

Mark,

I don't think .NET supports RC4 algorithm. Maybe you can find a custom
implementation, such as http://www.codeproject.com/csharp/rc4csharp.asp.

Alek

"Mark Frishman" <mfrishman_nospam@hotmail.com> wrote in message
news:eaLhUn$6DHA.2496@TK2MSFTNGP09.phx.gbl...
> If I have the following C++ code:
>
> HCRYPTPROV hCryptProv;
> HCRYPTHASH hHash;
> HCRYPTKEY hKey;
> CReadOnlyVariant bLocPassword(&bPassword);
> CReadOnlyVariant bLocPlainText(&bPlainText);
>
> *nRC = -1;
>
> if(CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL,
> CRYPT_VERIFYCONTEXT)) {
> if(CryptCreateHash(hCryptProv, CALG_MD5, 0, 0, &hHash)) {
> if(CryptHashData(hHash, bLocPassword.GetData(), bLocPassword.GetSize(),
> 0)) {
> if(CryptDeriveKey(hCryptProv, CALG_RC4, hHash, 0, &hKey)) {
> DWORD dwBufferLen = bLocPlainText.GetSize();
> DWORD dwDataLen = dwBufferLen;
> BYTE *pbBuffer = (BYTE *) malloc(dwBufferLen);
>
> memcpy(pbBuffer, bLocPlainText.GetData(), dwBufferLen);
>
> if(CryptEncrypt(hKey, 0, TRUE, 0, pbBuffer, &dwDataLen, dwBufferLen))
{
>
> What would be the equivalent .NET objects/methods to do this. Obviously I
> want my new encryption algorithm to produce the same results as the old
one.
>
>



Relevant Pages