CertGetSubjectCertificateFromStore

The CertGetSubjectCertificateFromStore function gets the subject certificate context that is uniquely identified by its issuer and serial number from the certificate store.

#include <wincrypt.h>
PCCERT_CONTEXT WINAPI CertGetSubjectCertificateFromStore(
  HCERTSTORE hCertStore,        // in
  DWORD dwCertEncodingType,     // in
  PCERT_INFO pCertId            // in
);
 

Parameters

hCertStore
Handle to the certificate store.
dwCertEncodingType
Type of encoding used on the certificate. Currently defined certificate encoding types are shown in the following table:
Encoding type Value
X509_ASN_ENCODING 0x00000001

pCertId
Pointer to a CERT_INFO structure. Only the Issuer and SerialNumber fields are used.

Return Values

A pointer to a read-only CERT_CONTEXT is returned. The CERT_CONTEXT must be freed by calling CertFreeCertificateContext.

The returned certificate might not be valid. Normally, it would be verified when getting its issuer certificate (CertGetIssuerCertificateFromStore).

Call GetLastError to see the reason for any failures. This function has the following error codes:

Error code Description
CRYPT_E_NOT_FOUND Unable to find the subject certificate in the store.

Remarks

CertDuplicateCertificateContext can be called to make a duplicate certificate.

Example

See Signed Message Example Code.

QuickInfo

  Windows NT: Requires version 4.0 SP3 or later. Available also in IE 3.02 and later.
  Windows: Requires Windows 95 OSR2 or later.
  Windows CE: Unsupported.
  Header: Declared in wincrypt.h.
  Import Library: Use crypt32.lib.

See Also

CertGetIssuerCertificateFromStore