Hi All,
I'm wondering if you can help me at all. I'm new to cryptography in
general unfortunately, and have been given some code for 'RC4' encryption
using the Windows Cryptography API / WinCrypt.
I can successfully encode and decode on windows, but I can't seem to
find/reproduce the same functionality using Crypto++
The code that I have for windows encryption is the following:
const char* password ="TestPasswd";
LPWSTR simple_encrypt(const char *cleartext, int& numCharacter)
{
numCharacter = 0;
HCRYPTPROV hProv = 0;
HCRYPTHASH hHash = 0;
HCRYPTKEY hSessionKey = 0;
DWORD dw = strlen(cleartext)+1;
BYTE *p = (BYTE*)cleartext;
// crypt using RC4, using session key md5(password)
CryptAcquireContext(&hProv, NULL, MS_DEF_PROV, PROV_RSA_FULL,
CRYPT_VERIFYCONTEXT);
CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash);
CryptHashData(hHash, (BYTE*)password, (DWORD) strlen(password), 0);
CryptDeriveKey(hProv, CALG_RC4, hHash, CRYPT_EXPORTABLE, &hSessionKey);
CryptDestroyHash(hHash);
CryptEncrypt(hSessionKey, NULL, FALSE, 0, p, &dw, dw );
CryptDestroyKey(hSessionKey);
CryptReleaseContext(hProv, 0);
// encode to base64
LPWSTR encoded = 0;
DWORD lencoded = 0;
// this will calculate the buffer size
CryptBinaryToStringW(p, dw, CRYPT_STRING_BASE64, NULL, &lencoded);
encoded= new WCHAR[lencoded];
CryptBinaryToStringW(p, dw, CRYPT_STRING_BASE64, encoded, &lencoded );
numCharacter = lencoded;
return encoded;
}
I think I understand what the issue is, the password is being MD5 hashed
before being used to get the session key that is used for RC4 encryption,
but so far, my attempts at trying to reproduce this functionality using
Crypto++ have proved futile.
Use of RC4 with Crypto++ seems fairly simple with just use of an
CryptoPP::Weak::ARC4, with SetKey and ProcessData, but attempts at using
the MD5 hash of the password as the key, and attempting to then base64
encode the result seems to produce different results.
Has anyone had any experience of migrating WinCrypt code to Crypto++ or can
give me any further guidance?
Thanks in advance
--
--
You received this message because you are subscribed to the "Crypto++ Users"
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at
http://www.cryptopp.com.
---
You received this message because you are subscribed to the Google Groups
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.