The CertSaveStore function saves the certificate store.
#include <wincrypt.h>
BOOL WINAPI CertSaveStore(
HCERTSTORE hCertStore, // in
DWORD dwMsgAndCertEncodingType, // in
DWORD dwSaveAs, // in
DWORD dwSaveTo, // in
void *pvSaveToPara, // in/out
DWORD dwFlags // in
);
Note Both a certificate and message encoding type are required and are specified 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 shown in the following table.
Encoding type | Value |
---|---|
X509_ASN_ENCODING | 0x00000001 |
PKCS_7_ASN_ENCODING | 0x00010000 |
Note, the CERT_KEY_CONTEXT_PROP_ID property (and its CERT_KEY_PROV_HANDLE_PROP_ID and CERT_KEY_SPEC_PROP_ID) is not saved into a serialized store.
The dwMsgAndCertEncodingType specifies the message encoding type when dwSaveAs is CERT_STORE_SAVE_AS_PKCS7.
Upon entry, SaveBlob's pbData and cbData need to be initialized.
Upon return, cbData is updated with the actual length.
For a length only calculation, pbData should be set to NULL. If pbData is non-NULL and cbData is not large enough, FALSE is returned with a last error of ERROR_MORE_DATA.
For dwSaveTo equal to CERT_STORE_SAVE_TO_FILENAME_A and
for dwSaveTo equal to CERT_STORE_SAVE_TO_FILENAME_W and
for dwSaveTo equal to CERT_STORE_SAVE_TO_FILENAME:
Opens the file, saves to it, and closes it.
The filename is passed in pvSaveToPara.
The filename is UNICODE for the "_W" option and ASCII for the "_A"option. For "_W": given, LPCWSTR pwszFilename; pvSaveToPara = (void *) pwszFilename;
For "_A": given, LPCSTR pszFilename; pvSaveToPara = (void *) pszFilename;
Note, the default (without "_A" or "_W") is UNICODE.
TRUE if the function succeeded. FALSE if the function failed.
Call GetLastError to see the reason for any failures. Note that CreateFile or WriteFile errors may be propagated to this function. This function has the following error codes:
Error code | Description |
---|---|
CRYPT_E_FILE_ERROR | An error occurred while writing to the file. |
See Example Code for Fundamental Certificate Store Operations.
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.