Windows 10: CryptAcquireCertificatePrivateKey fails to retrieve the private key for certificate listed...

Discus and support CryptAcquireCertificatePrivateKey fails to retrieve the private key for certificate listed... in Windows 10 Gaming to solve the problem; //Open Local Machine store NCRYPT_KEY_HANDLE hKey = 0; PCCERT_CONTEXT pCertContext = NULL; HCERTSTORE hCertStore = NULL; DWORD dwKeySpec;... Discussion in 'Windows 10 Gaming' started by Prafulla Shirke, Jun 27, 2024.

  1. CryptAcquireCertificatePrivateKey fails to retrieve the private key for certificate listed...


    //Open Local Machine store NCRYPT_KEY_HANDLE hKey = 0; PCCERT_CONTEXT pCertContext = NULL; HCERTSTORE hCertStore = NULL; DWORD dwKeySpec; BOOL bCallerFreeProv; hCertStore = CertOpenStoreCERT_STORE_PROV_SYSTEM, 0, NULL, CERT_SYSTEM_STORE_LOCAL_MACHINE, L"My"; // Enumerate all certificates. while pCertContext = CertFindCertificateInStorehCertStore, X509_ASN_ENCODING, 0, CERT_FIND_ANY, NULL, pCertContext

    :)
     
    Prafulla Shirke, Jun 27, 2024
    #1
  2. mterrisse Win User

    CryptAcquireCertificatePrivateKey gets a handle to something that knows both the private and the public keys

    Hello,

    CryptAcquireCertificatePrivateKey with the flag CRYPT_ACQUIRE_ONLY_NCRYPT_KEY_FLAG gets a handle (NCRYPT_KEY_HANDLE) to a certificate's private key.

    In the documentation https://learn.microsoft.com/en-us/w...nf-wincrypt-cryptacquirecertificateprivatekey you can read:

    "The CryptAcquireCertificatePrivateKey function obtains the private key for a certificate".

    But I found out that we get a handle to something that knows both the private key and the public key, and if I encrypt something with this handle (NCryptEncrypt), it encrypts with the public key and not the private key as expected.

    The result can indeed be decrypted (NCryptDecrypt) using the same handle (strange for an asymmetric algorithm), but not with a handle to the public key (public key obtained with CryptImportPublicKeyInfoEx2), NCryptDecrypt returns 0xc000000d = STATUS_INVALID_PARAMETER that just means "Can't decrypt".

    Of course, we're supposed to encrypt with a public key and decrypt with a private key, the opposite looks more like a signature than encryption, but I needed to do it in a special case. It seems I can't.

    Can you confirm this analysis? It took me a long time to understand this.

    Regards,

    Michel Terrisse
     
    mterrisse, Jun 27, 2024
    #2
  3. how do I export certificates and/or private keys?

    Hi,

    Thank you for posting your query on Microsoft Community. Let me assist you.

    I suggest you to follow the below steps to export a certificate with a private key

    1. Open the Certificates console for the user, computer, or service you want to manage.

    2. In the console pane, select the certificate store and container holding the certificate that you want to export.

    3. In the details pane, click the certificate you want to export.

    4. On the Action menu, point to
    All Tasks, and then click Export.

    5. In the Certificate Export Wizard, click
    Yes, export the private key. (This option will appear only if the private key is marked as exportable and you have access to the private key.)

    6. Under Export File Format, do one or all of the following, and then click
    Next.

    • To include all certificates in the certification path, select the
      Include all certificates in the certification path if possible check box.
    • To enable strong protection, select the Enable strong protection (requires IE 5.0, NT 4.0 SP4 or above) check box.
    • To delete the private key if the export is successful, select the
      Delete the private key if the export is successful
      check box.
    7.In Password, type a password to encrypt the private key you are exporting. In
    Confirm password, type the same password again, and then click
    Next
    .

    8. In File name, type a file name and path for the PKCS #12 file that will store the exported certificate and private key, click
    Next, and then click Finish.

    Hope this information is helpful. Please do let us know if you need further assistance, we’ll be glad to assist you.
     
    Pawan Dhondiyal, Jun 27, 2024
    #3
  4. mterrisse Win User

    CryptAcquireCertificatePrivateKey fails to retrieve the private key for certificate listed...

    mterrisse, Jun 27, 2024
    #4
Thema:

CryptAcquireCertificatePrivateKey fails to retrieve the private key for certificate listed...

Loading...
  1. CryptAcquireCertificatePrivateKey fails to retrieve the private key for certificate listed... - Similar Threads - CryptAcquireCertificatePrivateKey fails retrieve

  2. Error reading exported certificate private key on some machines.

    in Windows 10 Gaming
    Error reading exported certificate private key on some machines.: //code for testingusing System;using System.Security.Cryptography.X509Certificates;using System.Security.Cryptography;using System.Text;public class Program { public static void Main { string password = "F@dr4PaeE#2a"; byte[] certData; StringBuilder dn = new StringBuilder;...
  3. Error reading exported certificate private key on some machines.

    in Windows 10 Software and Apps
    Error reading exported certificate private key on some machines.: //code for testingusing System;using System.Security.Cryptography.X509Certificates;using System.Security.Cryptography;using System.Text;public class Program { public static void Main { string password = "F@dr4PaeE#2a"; byte[] certData; StringBuilder dn = new StringBuilder;...
  4. CryptAcquireCertificatePrivateKey fails to retrieve the private key for certificate listed...

    in Windows 10 Software and Apps
    CryptAcquireCertificatePrivateKey fails to retrieve the private key for certificate listed...: //Open Local Machine store NCRYPT_KEY_HANDLE hKey = 0; PCCERT_CONTEXT pCertContext = NULL; HCERTSTORE hCertStore = NULL; DWORD dwKeySpec; BOOL bCallerFreeProv; hCertStore = CertOpenStoreCERT_STORE_PROV_SYSTEM, 0, NULL, CERT_SYSTEM_STORE_LOCAL_MACHINE, L"My";...
  5. CryptAcquireCertificatePrivateKey gets a handle to something that knows both the private...

    in Windows 10 Gaming
    CryptAcquireCertificatePrivateKey gets a handle to something that knows both the private...: Hello, CryptAcquireCertificatePrivateKey with the flag CRYPT_ACQUIRE_ONLY_NCRYPT_KEY_FLAG gets a handle NCRYPT_KEY_HANDLE to a certificate's private key.In the documentation...
  6. CryptAcquireCertificatePrivateKey gets a handle to something that knows both the private...

    in Windows 10 Software and Apps
    CryptAcquireCertificatePrivateKey gets a handle to something that knows both the private...: Hello, CryptAcquireCertificatePrivateKey with the flag CRYPT_ACQUIRE_ONLY_NCRYPT_KEY_FLAG gets a handle NCRYPT_KEY_HANDLE to a certificate's private key.In the documentation...
  7. Lost Private key to EFS certificate file -

    in AntiVirus, Firewalls and System Security
    Lost Private key to EFS certificate file -: Hi,I cannot access my encrypted files because the encryption certificate changed. I can still see it in the certificate manager but I cannot export it in Pfx file to install it again only in CER format....
  8. Manual Certificate Request, User can change settings and export Private Key

    in AntiVirus, Firewalls and System Security
    Manual Certificate Request, User can change settings and export Private Key: Hi, today I have recognized that when our users manually request a certificate they can also change the request settings and select the private key to be exportable. How can I prevent this ? [ATTACH] [ATTACH] The situation is the same with users that have local...
  9. File Encryption and Decryption Problem With Certificate Private Key

    in Windows 10 Installation and Upgrade
    File Encryption and Decryption Problem With Certificate Private Key: Hi, so recently i had to do a backup and reset for my laptop and it is just after the reset that i realised that some of my files were encrypted. I had by luck been able to backup the certificates but cannot get access to the files still. It says that the private key is...
  10. Cannot Export / Backup my EFS certificate private key

    in AntiVirus, Firewalls and System Security
    Cannot Export / Backup my EFS certificate private key: Windows 10 Pro 1909 Hi Folks, I am trying to export my EFS certificate as a backup, however I am having no joy. Note: I can encrypt and decrypt files using EFS no problem using my account. Trying in Certificate Manger: certmgr.exe As Administrator Personal /...