Note that there are some explanatory texts on larger screens.

plurals
  1. POInvalid Algorithm Specified CryptoAPI
    text
    copied!<p>I am trying to decrypt something using 128BIT AES Decryption. When i attempt to calling CryptDecrypt i get an Error stating "Invalid Algorithm Specified". I get the same problem when using the library posted here: <a href="http://www.codeproject.com/KB/security/WinAES.aspx" rel="nofollow noreferrer">http://www.codeproject.com/KB/security/WinAES.aspx</a></p> <p>What can cause this error?</p> <p>I am using CryptoAPI along on vista64bit with visual studio 2008. I checked in the registry and the AES library is there...</p> <p>EDIT</p> <pre><code>BYTE*&amp; encryptedData /* get data length */ HCRYPTPROV cryptoHandle = NULL; HCRYPTKEY aesKeyHandle = NULL; hr = InitWinCrypt(cryptoHandle); if(FAILED(hr)) { return hr; } AesKeyOffering aesKey = { {PLAINTEXTKEYBLOB, CUR_BLOB_VERSION, 0, CALG_AES_128}, 16, { 0xFF, 0x00, 0xFF, 0x1C, 0x1D, 0x1E, 0x03, 0x04, 0x05, 0x0F, 0x20, 0x21, 0xAD, 0xAF, 0xA4, 0x04 }}; if(CryptImportKey(cryptoHandle, (CONST BYTE*)&amp;aesKey, sizeof(AesKeyOffering), NULL, 0, &amp;aesKeyHandle) == FALSE) { // DO error return HRESULT_FROM_WIN32(GetLastError()); } if(CryptSetKeyParam(aesKeyHandle, KP_IV, { 0xFF, 0x00, 0xFF, 0x1C, 0x1D, 0x1E, 0x03, 0x04, 0x05, 0x0F, 0x20, 0x21, 0xAD, 0xAF, 0xA4, 0x04 } , 0) == FALSE) { return HRESULT_FROM_WIN32(GetLastError()); } BYTE blah2 = CRYPT_MODE_CBC; // set block mode if(CryptSetKeyParam(aesKeyHandle, KP_MODE, &amp;blah2, 0) == FALSE) { // return HRESULT_FROM_WIN32(GetLastError()); } DWORD lol = dataLength / 16 + 1; DWORD lol2 = lol * 16; if(CryptDecrypt(aesKeyHandle, 0, TRUE, 0, encryptedData, &amp;lol2) == FALSE) { return HRESULT_FROM_WIN32(GetLastError()); } </code></pre> <p>InitWinCrypt function</p> <pre><code> if(!CryptAcquireContextW(&amp;cryptoHandle, NULL, L"Microsoft Enhanced RSA and AES Cryptographic Provider", PROV_RSA_AES, CRYPT_VERIFYCONTEXT)) { if(!CryptAcquireContextW(&amp;cryptoHandle, NULL, L"Microsoft Enhanced RSA and AES Cryptographic Provider", PROV_RSA_AES, 0)) { return HRESULT_FROM_WIN32(GetLastError()); } else { return S_OK; } } return S_OK; </code></pre> <p>AesOffering struct:</p> <pre><code>struct AesKeyOffering { BLOBHEADER m_Header; DWORD m_KeyLength; BYTE Key[16]; }; </code></pre> <p>EDIT2</p> <p>After rebooting my computer, and remvoing the CBC chunk. I am now getting Bad Data Errors. The data decrypts fine in C#. But i need to do this using wincrypt.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload