Using SHA2-512 (CALG_SHA_512) on Windows 7 returns "Invalid Algorithm",

I am trying to use SHA2-512 on Windows 7 with CryptoAPI, however the call to CryptCreateHash fails with the error GetLastError() = 2148073480 = 0x80090008, i.e. "Invalid algorithm." According to https://msdn.microsoft.com/en-us/library/windows/desktop/aa375549%28v=vs.85%29.aspx SHA2 must be available with Windows XP SP3.

Here is the code I'm using:

 HCRYPTPROV hCryptProv; CryptAcquireContext(&hCryptProv, nullptr, nullptr, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT); HCRYPTHASH hHash; if (!CryptCreateHash(hCryptProv, CALG_SHA_512, 0, 0, &hHash)) { DWORD err = GetLastError(); // -> 2148073480=0x80090008 } 

Using CALG_SHA1 instead of CALG_SHA512 works.

Should I do additional initialization, for example? explicitly activating SHA2?

+5
source share
1 answer

The reason for this is that SHA2 algorithms are not supported by the Microsoft Base Cryptography Provider ( PROV_RSA_FULL or PROV_RSA_SIG ).

CryptAcquireContext requires the use of Microsoft Enhanced RSA and AES Cryptographic Provider ( PROV_RSA_AES ).

+10
source

Source: https://habr.com/ru/post/1202487/


All Articles