2

I have a code that encrypts a file using AES CFB mode. While the code runs correctly in Windows 7, Windows 8 and previous versions of Windows 10, on Windows 10 Creators Update this line fails:

if (!CryptAcquireContext(&hProv, NULL, MS_ENH_RSA_AES_PROV, PROV_RSA_AES, 0))
{

    std::cout << "CryptAcquireContext Error\n";
    return 1;
}

What could be the reason for it?

P.S I saw that it is deprecated on MSDN, but I thought that function was so common.

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
MickCic
  • 145
  • 2
  • 10
  • 1
    What does `GetLastError` return – Martin Bonner supports Monica Feb 05 '18 at 12:13
  • Is there any reason you can't convert to CNG? (Do you still need to support XP?) – Martin Bonner supports Monica Feb 05 '18 at 12:14
  • I receive this number GetLastError() - 2148073494 – MickCic Feb 05 '18 at 12:16
  • 2
    HRESULTs are usually written in hex. That is 0x80090016, and a little bit of googling suggests it corresponds to "Keyset does not exist". You should confirm that with ErrLookup (I can't, because I'm not on Windows at the moment). You should then [edit] the information into the question. – Martin Bonner supports Monica Feb 05 '18 at 12:23
  • 4
    Everything @MartinBonner says plus: _"__NTE_BAD_KEYSET__: The key container could not be opened. A common cause of this error is that the key container does not exist. To create a key container, call CryptAcquireContext using the CRYPT_NEWKEYSET flag. This error code can also indicate that access to an existing key container is denied. Access rights to the container can be granted by the key set creator by using CryptSetProvParam."_ source: https://msdn.microsoft.com/en-us/library/windows/desktop/aa379886(v=vs.85).aspx – Richard Critten Feb 05 '18 at 12:26
  • Yes thanks you helped me to resolve the issue. Found that link already. – MickCic Feb 05 '18 at 12:59

0 Answers0