Using SHA2-512 (CALG_SHA_512) on Windows 7 returns "Invalid Algorithm Specified"
Asked Answered
R

1

8

I'm trying to use SHA2-512 on Windows 7 with CryptoAPI, however, calling CryptCreateHash fails with GetLastError()=2148073480=0x80090008, i.e. "Invalid Algorithm Specified". According to https://msdn.microsoft.com/en-us/library/windows/desktop/aa375549%28v=vs.85%29.aspx SHA2 should be available since 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.

Do I have to conduct some further initialization, e.g. explicitely activating SHA2?

Rowlett answered 13/9, 2014 at 11:27 Comment(0)
R
15

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

One needs to use the "Microsoft Enhanced RSA and AES Cryptographic Provider" (PROV_RSA_AES) in CryptAcquireContext.

Rowlett answered 13/9, 2014 at 11:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.