CertSaveStore function (wincrypt.h)

The CertSaveStore function saves the certificate store to a file or to a memory BLOB.

Syntax

BOOL CertSaveStore(
  [in]      HCERTSTORE hCertStore,
  [in]      DWORD      dwEncodingType,
  [in]      DWORD      dwSaveAs,
  [in]      DWORD      dwSaveTo,
  [in, out] void       *pvSaveToPara,
  [in]      DWORD      dwFlags
);

Parameters

[in] hCertStore

The handle of the certificate store to be saved.

[in] dwEncodingType

Specifies the certificate encoding type and message encoding type. Encoding is used only when dwSaveAs contains CERT_STORE_SAVE_AS_PKCS7. Otherwise, the dwMsgAndCertEncodingType parameter is not used.

This parameter can be a combination of one or more of the following values.

Value Meaning
PKCS_7_ASN_ENCODING
65536 (0x10000)
Specifies PKCS 7 message encoding.
X509_ASN_ENCODING
1 (0x1)
Specifies X.509 certificate encoding.

[in] dwSaveAs

Specifies how to save the certificate store.

This parameter can be one of the following values.

Value Meaning
CERT_STORE_SAVE_AS_PKCS7
2
The certificate store can be saved as a PKCS #7 signed message that does not include additional properties. The dwEncodingType parameter specifies the message encoding type.
CERT_STORE_SAVE_AS_STORE
1
The certificate store can be saved as a serialized store containing properties in addition to encoded certificates, certificate revocation lists (CRLs), and certificate trust lists (CTLs). The dwEncodingType parameter is ignored.
Note  The CERT_KEY_CONTEXT_PROP_ID property and the related CERT_KEY_PROV_HANDLE_PROP_ID and CERT_KEY_SPEC_PROP_ID values are not saved to a serialized store.
 

[in] dwSaveTo

Specifies where and how to save the certificate store. The contents of this parameter determines the format of the pvSaveToPara parameter.

This parameter can be one of the following values.

Value Meaning
CERT_STORE_SAVE_TO_FILE
1
The function saves the certificate store to a file. The pvSaveToPara parameter contains a handle to a file previously obtained by using the CreateFile function. The file must be opened with write permission. After a successful save operation, the file pointer is positioned after the last write operation.
CERT_STORE_SAVE_TO_FILENAME
4
The function saves the certificate store to a file. The pvSaveToPara parameter contains a pointer to a null-terminated Unicode string that contains the path and file name of the file to save to. The function opens the file, saves to it, and closes it.
CERT_STORE_SAVE_TO_FILENAME_A
3
The function saves the certificate store to a file. The pvSaveToPara parameter contains a pointer to a null-terminated ANSI string that contains the path and file name of the file to save to. The function opens the file, saves to it, and closes it.
CERT_STORE_SAVE_TO_FILENAME_W
4
The function saves the certificate store to a file. The pvSaveToPara parameter contains a pointer to a null-terminated Unicode string that contains the path and file name of the file to save to. The function opens the file, saves to it, and closes it.
CERT_STORE_SAVE_TO_MEMORY
2
The function saves the certificate store to a memory BLOB. The pvSaveToPara parameter contains a pointer to a CERT_BLOB structure. Before use, the CERT_BLOB's pbData and cbData members must be initialized. Upon return, cbData is updated with the actual length. For a length-only calculation, pbData must be set to NULL. If pbData is non-NULL and cbData is not large enough, the function returns zero with a last error code of ERROR_MORE_DATA.

[in, out] pvSaveToPara

A pointer that represents where the store should be saved to. The contents of this parameter depends on the value of the dwSaveTo parameter.

[in] dwFlags

This parameter is reserved for future use and must be set to zero.

Return value

If the function succeeds, the function returns nonzero.

If the function fails, it returns zero. For extended error information, call GetLastError.

Note that CreateFile or WriteFile errors can be propagated to this function. One possible error code is CRYPT_E_FILE_ERROR which indicates that an error occurred while writing to the file.

Requirements

Requirement Value
Minimum supported client Windows XP [desktop apps | UWP apps]
Minimum supported server Windows Server 2003 [desktop apps | UWP apps]
Target Platform Windows
Header wincrypt.h
Library Crypt32.lib
DLL Crypt32.dll

See also

CertCloseStore

CertOpenStore

Certificate Store Functions

CreateFile

WriteFile