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 development | Windows API - Win32

4 answers

Sort by: Most helpful
  1. 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.

    Was this answer helpful?

    0 comments No comments

  2. 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

    Was this answer helpful?


  3. cheong00 3,491 Reputation points Volunteer Moderator
    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.

    Was this answer helpful?

    0 comments No comments

  4. 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,

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.