How does this translate to c++
-
Hi all, How does this translate to c++:
string key = (string)settingsReader.GetValue("SecurityKey", typeof(String));
HashAlgorithm XHash = HashAlgorithm.Create("MD5");
byte[] keyArray = XHash.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
XHash.Clear();
TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
tdes.Key = keyArray;
tdes.Mode = CipherMode.ECB;
tdes.Padding = PaddingMode.PKCS7;This is what I did but i am not sure if its correct because I didnt do the UTF8Encoding part.
TCHAR szKey[] = _T("Key");
DWORD pwlen = _tcslen(szKey);
result = CryptCreateHash(hProv,CALG_MD5,0,0,&hHash);
result = CryptHashData(hHash,(BYTE *)szKey,pwlen,0);
result = CryptDeriveKey(hProv,CALG_3DES,hHash,0,&hKey);
BYTE PadMode = CRYPT_MODE_ECB;
result = CryptSetKeyParam(hKey, PKCS5_PADDING, &PadMode, 0);Please help me clarify things. Thanks, Jayjay
-
Hi all, How does this translate to c++:
string key = (string)settingsReader.GetValue("SecurityKey", typeof(String));
HashAlgorithm XHash = HashAlgorithm.Create("MD5");
byte[] keyArray = XHash.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
XHash.Clear();
TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
tdes.Key = keyArray;
tdes.Mode = CipherMode.ECB;
tdes.Padding = PaddingMode.PKCS7;This is what I did but i am not sure if its correct because I didnt do the UTF8Encoding part.
TCHAR szKey[] = _T("Key");
DWORD pwlen = _tcslen(szKey);
result = CryptCreateHash(hProv,CALG_MD5,0,0,&hHash);
result = CryptHashData(hHash,(BYTE *)szKey,pwlen,0);
result = CryptDeriveKey(hProv,CALG_3DES,hHash,0,&hKey);
BYTE PadMode = CRYPT_MODE_ECB;
result = CryptSetKeyParam(hKey, PKCS5_PADDING, &PadMode, 0);Please help me clarify things. Thanks, Jayjay
Does it produce the same hash for a sample string as the C# code? That's a good way to tell if it's the same.