BCryptOpenAlgorithmProvider

Dev Bon 16 Reputation points
2021-01-30T20:11:18.74+00:00

Hello,
I try to open TPM as algoritm provider for generate random numbers:

  BCRYPT_ALG_HANDLE hAlgorithm;
    NTSTATUS ntStat = BCryptOpenAlgorithmProvider ( &hAlgorithm, BCRYPT_RNG_ALGORITHM, MS_PLATFORM_CRYPTO_PROVIDER, NULL);

I get ntStat = STATUS_NOT_FOUND;

If I use MS_PRIMITIVE_PROVIDER instead of MS_PLATFORM_CRYPTO_PROVIDER everything is OK.

What I do wrong? TPM is enabled on the my computer, and I run the program as Administrator on Windows 10 Professional.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,523 questions
{count} votes

4 answers

Sort by: Most helpful
  1. frank_big 1 Reputation point
    2021-02-02T08:21:40.457+00:00

    Hi All,
    I have the same exact problem.
    Here is my code:

    ntstat = BCryptOpenAlgorithmProvider(&pHandle,BCRYPT_RNG_ALGORITHM,MS_PRIMITIVE_PROVIDER,//MS_PLATFORM_CRYPTO_PROVIDER,
                                                                NULL);
                        if (0 == ntstat)
                        {
                            for (long i = 0; i < filesize; i++) {
                                BCryptGenRandom(pHandle, buf, sizeof(buf), NULL);
                                //outfile.write((char *)&buf[0], _countof(buf));
                            }
                            BCryptCloseAlgorithmProvider(pHandle, NULL);
                        }
                        else
                        {
                            sprintf((char *)text, "error = 0x%08x", (unsigned int)ntstat);
                        }
    

    Best regards,


  2. Cheong00 3,476 Reputation points
    2021-02-02T08:47:49.033+00:00

    Try search the algorithm you want to use under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Cryptography\Providers . If "Microsoft Platform Crypto Provider" is not listed, I think the choice is not provided by the current system.

    You'll need Win8 / Win2012 or above to choose "Microsoft Platform Crypto Provider".

    You may also try to follow this exercise and see if you can get "Microsoft Platform Crypto Provider" working.

    0 comments No comments

  3. frank_big 1 Reputation point
    2021-02-02T09:52:55.133+00:00

    Hi Cheong00,
    thanks for your comment.

    I'm using Win10.
    This is my regedit window, Microsoft Crypto Provider is present. I also checked TPM functionalities with tpm.msc and everything is fine.

    62934-image.png

    However I get an error whenever I try to run certtmpl.msc, translated it is like: "Impossiblle to find the file "certtmpl.msc". Verify the name and retry". Maybe it is related?

    62966-image.png


  4. Bruno Martinez 1 Reputation point
    2021-04-17T03:08:03.857+00:00

    MS_PLATFORM_CRYPTO_PROVIDER fails to open for me too, and the 2 other coworkers I asked to try it.

    0 comments No comments