[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
);
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 |
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 |
The following flags can be combined with a bitwise OR operation into CertCreateContext dwFlags.
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.
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.
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 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);
Windows NT: Requires version 5.0 or later.
Windows: Unsupported.
Windows CE: Unsupported.
Header: Declared in wincrypt.h.
Import Library: Use crypt32.lib.