The CertAddSerializedElementToStore function adds the serialized certificate, CRL, or CTL element to the store. The serialized element contains the encoded certificate, CRL, or CTL and its properties, such as, CERT_KEY_PROV_INFO_PROP_ID.
#include <wincrypt.h>
BOOL WINAPI CertAddSerializedElementToStore(
HCERTSTORE hCertStore, // in
const BYTE *pbElement, // in
DWORD cbElement, // in
DWORD dwAddDisposition, // in
DWORD dwFlags, // in
DWORD dwContextTypeFlags, // in
DWORD *pdwContextType, // out, optional
const void **ppvContext // out, optional
);
Disposition | Value |
---|---|
CERT_STORE_ADD_NEW | 0x00000001 |
CERT_STORE_ADD_USE_EXISTING | 0x00000002 |
CERT_STORE_ADD_REPLACE_EXISTING | 0x00000003 |
CERT_STORE_ADD_ALWAYS | 0x00000004 |
For dwAddDisposition == CERT_STORE_ADD_NEW the operation fails if the certificate, CRL, or CTL already exists in the store. LastError is set to CRYPT_E_EXISTS.
For dwAddDisposition == CERT_STORE_ADD_USE_EXISTING, if the certificate, CRL, or CTL already exists, then it is used and if ppvContext is not NULL, the existing context is duplicated. It only copies the properties that don't already exist. The SHA1 and MD5 hash propoerties aren't copied.
For dwAddDisposition == CERT_STORE_ADD_REPLACE_EXISTING, if the certificate, CRL, or CTL already exists, then the existing certificate, CRL, or CTL context is deleted before creating and adding the new context.
For dwAddDisposition == CERT_STORE_ADD_ALWAYS, no check is made to see if the certificate, CRL, or CTL already exists. A new certificate, CRL, or CTL context is always created. This may lead to duplicates in the store.
CertGetCRLFromStore, or CertGetSubjectCertificateFromStore is called to determine if the element already exists in the store, if that check is necessary.
Currently defined context type flags are shown in the following table:
Context type flag | 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 context types are shown in the following table:
Context type | Value |
---|---|
CERT_STORE_CERTIFICATE_CONTEXT | 0x00000001 |
CERT_STORE_CRL_CONTEXT | 0x00000002 |
CERT_STORE_CTL_CONTEXT | 0x00000003 |
TRUE if the function succeeded. FALSE if the function failed.
Call GetLastError to see the reason for any failures. This function has the following error codes:
Error code | Description |
---|---|
CRYPT_E_EXISTS | For a dwAddDisposition of CERT_STORE_ADD_NEW, the certificate, CRL, or CTL already exists in the store. |
CRYPT_E_OSS_ERROR | ASN.1 decoding error. Note, to get the OSS error subtract CRYPT_E_OSS_ERROR from the returned error and see asn1code.h for details on the error. |
E_INVALIDARG | Invalid add disposition specified by the dwAddDisposition argument. |
See CertSerializeCertificateStoreElement.
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.
CertSerializeCertificateStoreElement, CertSerializeCRLStoreElement