Skip to content

Latest commit

 

History

History
151 lines (116 loc) · 5.59 KB

nf-wincrypt-cryptimportpublickeyinfo.md

File metadata and controls

151 lines (116 loc) · 5.59 KB
UID title description helpviewer_keywords old-location tech.root ms.assetid ms.date ms.keywords req.header req.include-header req.target-type req.target-min-winverclnt req.target-min-winversvr req.kmdf-ver req.umdf-ver req.ddi-compliance req.unicode-ansi req.idl req.max-support req.namespace req.assembly req.type-library req.lib req.dll req.irql targetos req.typenames req.redist ms.custom f1_keywords dev_langs topic_type api_type api_location api_name
NF:wincrypt.CryptImportPublicKeyInfo
CryptImportPublicKeyInfo function (wincrypt.h)
Converts and imports the public key information into the provider and returns a handle of the public key.
CryptImportPublicKeyInfo
CryptImportPublicKeyInfo function [Security]
_crypto2_cryptimportpublickeyinfo
security.cryptimportpublickeyinfo
wincrypt/CryptImportPublicKeyInfo
security\cryptimportpublickeyinfo.htm
security
f5f8ebb6-c838-404b-9b61-3ec36fdaef01
12/05/2018
CryptImportPublicKeyInfo, CryptImportPublicKeyInfo function [Security], _crypto2_cryptimportpublickeyinfo, security.cryptimportpublickeyinfo, wincrypt/CryptImportPublicKeyInfo
wincrypt.h
Windows
Windows XP [desktop apps only]
Windows Server 2003 [desktop apps only]
Crypt32.lib
Crypt32.dll
Windows
19H1
CryptImportPublicKeyInfo
wincrypt/CryptImportPublicKeyInfo
c++
APIRef
kbSyntax
DllExport
Crypt32.dll
CryptImportPublicKeyInfo

CryptImportPublicKeyInfo function

-description

Important  This API is deprecated. New and existing software should start using Cryptography Next Generation APIs. Microsoft may remove this API in future releases.
 
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.

-parameters

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

-param 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

-param pInfo [in]

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

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

-returns

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 code Description
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)
}

-see-also

CryptExportPublicKeyInfo

Data Management Functions