CertCreateContext

[This is preliminary documentation and subject to change.]

The CertCreateContext function creates the specified context from the encoded bytes.

#include <wincrypt.h>
const void * WINAPI CertCreateContext(
  DWORD dwContextType,                    // in
  DWORD dwEncodingType,                   // in
  const BYTE *pbEncoded,                  // in
  DWORD cbEncoded,                        // in
  DWORD dwFlags,                          // in
  PCERT_CREATE_CONTEXT_PARA pCreatePara   // in, optional
);
 

Parameters

dwContextType
Specifies the set of allowable contexts. For example, to create either a certificate, CRL, or CTL, set dwContextType to: CERT_STORE_CERTIFICATE_CONTEXT_FLAG | CERT_STORE_CRL_CONTEXT_FLAG

Currently defined context type flags are shown in the following table:
Context type Value
CERT_STORE_ALL_CONTEXT_FLAG 0xFFFFFFFF
CERT_STORE_CERTIFICATE_CONTEXT_FLAG 0x00000001
CERT_STORE_CRL_CONTEXT_FLAG 0x00000002
CERT_STORE_CTL_CONTEXT_FLAG 0x00000004

dwEncodingType
Type of encoding used. If the low-order word containing the certificate encoding type is nonzero, then it is used. Otherwise, the high-order word containing the message encoding type is used. If both are specified, the encoding type in the low-order word is used.

Currently defined encoding types are shown in the following table:
Encoding type Value
CRYPT_ASN_ENCODING 0x00000001
X509_ASN_ENCODING 0x00000001
PKCS_7_ASN_ENCODING 0x00010000

pbEncoded
Pointer to the content to be copied (the existing encoded context).
cbEncoded
Size, in bytes, of the existing encoded context.
dwFlags
Flag values.

The following flags can be combined with a bitwise OR operation into CertCreateContext dwFlags.

CERT_CREATE_CONTEXT_NOCOPY_FLAG
The created context points directly to the pbEncoded instead of an allocated copy.
CERT_CREATE_CONTEXT_SORTED_FLAG
Creates a context with sorted entries. Currently this flag is only applicable to a CTL context.

For CTLs: the cCTLEntry in the returned CTL_INFO is always 0. CertFindSubjectInSortedCTL and CertEnumSubjectInSortedCTL must be called to find or enumerate the CTL entries.

pCreatePara
Pointer to a CERT_CREATE_CONTEXT_PARA structure.

If pCreatePara and pCreatePara->pfnFree are non-NULL pCreatePara->pfnFree is called to free the pbEncoded when the context is last freed.

If pCreatePara->pvFree is non-NULL, then pCreatePara->pvFree instead of pbEncoded is passed to the function of pCreatePara->pfnFree.

If pCreatePara or pCreatePara->pfnFree are NULL, no attempt is made to free pbEncoded.

Return Values

A pointer to the newly created context. If a NULL is returned, the function failed and the function pointed to by pCreatePara->pvFree must be called to free the created context.

Example

// EXAMPLE CODE FOR USING CertCreateContext().
// Assume pointers to an encoded data (pbEncoded) and the
// size of the encoded context (cbEnabled) are initialized.
// Declare and initialize.
CERT_CREATE_CONTEXT_PARA   CreatePara;
CreatePara.cbSize= sizeof(CERT_CREATE_CONTEXT_PARA);
CreatePara.pfnFree= NULL;
CreatePara.pvFree= NULL;
const BYTE *pbEncoded;          // Pointer to existing encoded data or
                                //   context- initialized elsewhere.
DWORD cbEnabled;                // Size of encoded context.
PCERT_CREATE_CONTEXT_PARA pCreatePara;
// Pointer to the created structure.
PCCRL_CONTEXT pReturn;          // Returns a pointer to address of
                                //   the created context.

// Function call to CertCreateContext().
pReturn= (PCCRL_CONTEXT) CertCreateContext(
CERT_STORE_CRL_CONTEXT_FLAG,
// in- dwContextType, this is a CRL.
          X509_ASN_ENCODING,    // in- dwEncodingType
          pbEncoded,            // in- Initialized elsewhere
          cbEnabled,            // in- cbEncoded- size of encoded
                                //   context.
          0,                    // in- dwFlags- to make a copy
                                //   CERT_CREATE_CONTEXT_NOCOPY_FLAG
                                //   is not set.
          pCreatePara);         // in, optional- pCreatePara
if(pReturn){  // Pointer to created context is returned.
printf("Context created.");
    }
else {        // NULL returned- function failed.
printf("CertCreateContext failed\n");
}

// Free the memory
CertFreeCRLContext(pReturn);
 

QuickInfo

  Windows NT: Requires version 5.0 or later.
  Windows: Unsupported.
  Windows CE: Unsupported.
  Header: Declared in wincrypt.h.
  Import Library: Use crypt32.lib.