Expand Minimize
EN
Tätä sisältöä ei ole saatavilla kielelläsi. Tässä on englanninkielinen versio.

CryptImportPublicKeyInfo function

The CryptImportPublicKeyInfo function converts and imports the public key information into the provider and returns a handle of the public key. CryptImportPublicKeyInfoEx provides a revised version of this function.

Syntax


BOOL WINAPI CryptImportPublicKeyInfo(
  _In_   HCRYPTPROV hCryptProv,
  _In_   DWORD dwCertEncodingType,
  _In_   PCERT_PUBLIC_KEY_INFO pInfo,
  _Out_  HCRYPTKEY *phKey
);

Parameters

hCryptProv [in]

The handle of the cryptographic service provider (CSP) to use when importing the public key. This handle must have already been created using CryptAcquireContext.

dwCertEncodingType [in]

Specifies the encoding type used. It is always acceptable to specify both the certificate and message encoding types by combining them with a bitwise-OR operation as shown in the following example:

X509_ASN_ENCODING | PKCS_7_ASN_ENCODING

Currently defined encoding types are:

  • X509_ASN_ENCODING
  • PKCS_7_ASN_ENCODING
pInfo [in]

The address of a CERT_PUBLIC_KEY_INFO structure that contains the public key to import into the provider.

phKey [out]

The address of an HCRYPTKEY variable that receives the handle of the imported public key. When you have finished using the public key, release the handle by calling the CryptDestroyKey function.

Return value

If the function succeeds, the return value is nonzero (TRUE).

If the function fails, the return value is zero (FALSE). For extended error information, call GetLastError.

Note  Errors from the called functions CryptGetUserKey and CryptExportKey might be propagated to this function. This function has the following error code.

Return codeDescription
ERROR_FILE_NOT_FOUND

An import function that can be installed or registered could not be found for the specified dwCertEncodingType and pInfo->Algorithm.pszObjId parameters.

 

If the function fails, GetLastError may return an Abstract Syntax Notation One (ASN.1) encoding/decoding error. For information about these errors, see ASN.1 Encoding/Decoding Return Values.

Remarks

This function is normally used to retrieve the public key from a certificate. This is done by passing the CERT_PUBLIC_KEY_INFO structure from a filled-in certificate structure as shown in the following pseudocode.

PCCERT_CONTEXT pCertContext

// Get the certificate context structure from a certificate.
pCertContext = CertCreateCertificateContext(...)
if(pCertContext)
{
    HCRYPTKEY hCertPubKey

    // Get the public key information for the certificate.
    CryptImportPublicKeyInfo(
        hCryptProv, 
        X509_ASN_ENCODING, 
        &pCertContext->pCertInfo->SubjectPublicKeyInfo, 
        &hCertPubKey)

    CertFreeCertificateContext(pCertContext)
}

Requirements

Minimum supported client

Windows XP [desktop apps only]

Minimum supported server

Windows Server 2003 [desktop apps only]

Header

Wincrypt.h

Library

Crypt32.lib

DLL

Crypt32.dll

See also

Data Management Functions
CryptExportPublicKeyInfo

 

 

Yhteisösisältö

Lisää
Näytä:
© 2014 Microsoft