|
Posted by François on December 5, 2005, 10:36 am
If you were Registered and logged in, you could reply and use other advanced thread options
Got it.
It has to be CALG_3DES_112 , not CALG_3DES.
It was stupid. I should have checked the lentgh of the key fist.
> I have ciphered text from dotNet application.
>
> I need to decrypt it from an ATL app.
>
> The C# decrypting process I have is :
>
> string p = b64 ciphered text 16 bytes len
> string initVector = my b64 value value 8 bytes len
> string strKey = my b64 value 16 bytes len
>
> Decryptor dec = new Decryptor(EncryptionAlgorithm.TripleDes);
> dec.IV = Convert.FromBase64String(initVector);
> byte[] plainText = dec.Decrypt(Convert.FromBase64String(p),
> Convert.FromBase64String(strKey));
> ClearText = Encoding.ASCII.GetString(plainText);
>
>
>
>
> What I have tried in C++ ATL with no luck: 8009005 BAD DATA at
key.decrypt.
> (all other return OK)
>
> CreatePrivateExponentOneKey2 and ImportPlainSessionBlob come from
> CryptAcquireContext by CCryptProv::Initialize)
>
>
>
>
> int passwordLen = 1000;
> BYTE password[1000];
> Base64Decode(strPasswordB64,strPasswordB64.GetLength(),password,
> &passwordLen);
>
> BYTE cipher[1000];
> int cipherLen = 1000;
> Base64Decode(strTexteB64,strTexteB64.GetLength(),cipher, &cipherLen);
>
> CString iv = "my b64 value";
> BYTE IV[8];
> int lenIV = 8;
> Base64Decode(iv,iv.GetLength(),IV, &lenIV);
>
> CCryptProv prov;
> HRESULT hr = prov.Initialize(PROV_RSA_FULL,NULL,MS_STRONG_PROV);
> FAILED(hr)
>
> HCRYPTKEY hPrivateKey;
> HCRYPTPROV hProv = prov.GetHandle();
> DWORD dwKeySpec = AT_KEYEXCHANGE;
> BOOL bRet;
> bRet = CreatePrivateExponentOneKey2(dwKeySpec,hProv,&hPrivateKey);
> ASSERT(bRet)
>
> HCRYPTKEY hSessionKey;
> bRet =
>
ImportPlainSessionBlob(hProv,hPrivateKey,CALG_3DES,password,passwordLen,&hSe
> ssionKey);
> ASSERT(bRet);
>
> CCryptKey key(hSessionKey);
>
> hr = key.SetIV(IV);
> FAILED(hr)
>
> BYTE Final[1000];
> DWORD lenF = 1000;
> hr = key.Decrypt(cipher, cipherLen,Final,&lenF);
> FAILED(hr)
>
>
|