[This is preliminary documentation and subject to change.]
The CryptQueryObject function takes a CERT_BLOB or a file name and returns the information about the content of the blob or the file.
#include <wincrypt.h>
BOOL WINAPI CryptQueryObject(
DWORD dwObjectType, // in
const void *pvObject, // in
DWORD dwExpectedContentTypeFlags, // in
DWORD dwExpectedFormatTypeFlags, // in
DWORD dwFlags, // in
DWORD *pdwMsgAndCertEncodingType, // out
DWORD *pdwContentType, // out
DWORD *pdwFormatType, // out
HCERTSTORE *phCertStore, // out
HCRYPTMSG *phMsg, // out
const void **ppvContext // out
);
ObjectType | Description |
---|---|
CERT_QUERY_OBJECT_FILE | Get the information about a file |
CERT_QUERY_OBJECT_BLOB | Get the information about a blob |
If the dwObjectType is not correct for the object, program behavior is unspecified.
If dwObjectType is CERT_QUERY_OBJECT_FILE, pvObject is a LPWSTR. If dwObjectType is CERT_QUERY_OBJECT_BLOB, pvObject is a PCERT_BLOB.
If the pvObject does not point to the correct type specified by dwObjectType, program behavior is unspecified.
Expected Content Type Flag Name | Content type |
---|---|
CERT_QUERY_CONTENT_FLAG_ALL | any type |
CERT_QUERY_CONTENT_FLAG_CERT | single certificate |
CERT_QUERY_CONTENT_FLAG_CTL | single CTL |
CERT_QUERY_CONTENT_FLAG_CRL | single CRL |
CERT_QUERY_CONTENT_FLAG_ SERIALIZED_STORE |
serialized store |
CERT_QUERY_CONTENT_FLAG_ SERIALIZED_CERT |
serialized single certificate |
CERT_QUERY_CONTENT_FLAG_ SERIALIZED_CTL |
serialized single CTL |
CERT_QUERY_CONTENT_FLAG_ SERIALIZED_CRL |
serialized single CRL |
CERT_QUERY_CONTENT_FLAG_ PKCS7_SIGNED |
PKCS#7 signed message |
CERT_QUERY_CONTENT_FLAG_ PKCS7_UNSIGNED |
PKCS#7 unsigned message |
CERT_QUERY_CONTENT_FLAG_ PKCS7_SIGNED_EMBED |
embedded PKCS7 signed message |
CERT_QUERY_CONTENT_FLAG_PKCS10 | PKCS#10 |
CERT_QUERY_CONTENT_FLAG_PFX | PFX BLOB |
If the dwExpectedContentTypeFlags is not correct for the type specified by pdwContentType, the function will return a FALSE.
Expected Format Type Flags Name | Format type |
---|---|
CERT_QUERY_FORMAT_FLAG_ALL | any format |
CERT_QUERY_FORMAT_FLAG_BINARY | binary format |
CERT_QUERY_FORMAT_FLAG_BASE64_ ENCODED |
base64 encoded |
If the dwExpectedFormatTypeFlags is not correct for the type specified by pdwFormatType, the function will return a FALSE.
Encoding Type | value |
---|---|
X509_ASN_ENCODING | 0x00000001 |
PKCS_7_ASN_ENCODING | 0x00010000 |
Content Type | value |
---|---|
CERT_QUERY_CONTENT_CERT | 1 |
CERT_QUERY_CONTENT_CTL | 2 |
CERT_QUERY_CONTENT_CRL | 3 |
CERT_QUERY_CONTENT_SERIALIZED_STORE | 4 |
CERT_QUERY_CONTENT_SERIALIZED_CERT | 5 |
CERT_QUERY_CONTENT_SERIALIZED_CTL | 6 |
CERT_QUERY_CONTENT_SERIALIZED_CRL | 7 |
CERT_QUERY_CONTENT_PKCS7_SIGNED | 8 |
CERT_QUERY_CONTENT_PKCS7_UNSIGNED | 9 |
CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED | 10 |
CERT_QUERY_CONTENT_PKCS10 | 11 |
CERT_QUERY_CONTENT_PFX | 12 |
Format Type | value |
---|---|
CERT_QUERY_FORMAT_BINARY | 1 |
CERT_QUERY_FORMAT_BASE64_ENCODED | 2 |
The caller should free *phCertStore via CertCloseStore.
If no output is wanted, set phCertStore to NULL.
Content Type | value |
---|---|
CERT_QUERY_CONTENT_CERT | 1 |
CERT_QUERY_CONTENT_CTL | 2 |
CERT_QUERY_CONTENT_CRL | 3 |
CERT_QUERY_CONTENT_SERIALIZED_STORE | 4 |
CERT_QUERY_CONTENT_SERIALIZED_CERT | 5 |
CERT_QUERY_CONTENT_SERIALIZED_CTL | 6 |
CERT_QUERY_CONTENT_SERIALIZED_CRL | 7 |
CERT_QUERY_CONTENT_PKCS7_SIGNED | 8 |
CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED | 10 |
The caller should free *phMsg via CryptMsgClose.
If no output is wanted, set phMsg to NULL.
dwContentType | value |
---|---|
CERT_QUERY_CONTENT_PKCS7_SIGNED | 8 |
CERT_QUERY_CONTENT_PKCS7_UNSIGNED | 9 |
CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED | 10 |
pvContext | dwContentType | free pvContext via |
---|---|---|
PCCERT_ CONTEXT |
CERT_QUERY_ CONTENT_CERT |
CertFreeCertificate Context |
PCCERT_ CONTEXT |
CERT_QUERY_ CONTENT_ SERIALIZED_CERT |
CertFreeCertificate Context |
PCCTL_ CONTEXT |
CERT_QUERY_ CONTENT_CTL |
CertFreeCTLContext |
PCCTL_ CONTEXT |
CERT_QUERY_ CONTENT_ SERIALIZED_CTL |
CertFreeCTLContext |
PCCRL_ CONTEXT |
CERT_QUERY_ CONTENT_CRL |
CertFreeCRLContext |
PCCRL_ CONTEXT |
CERT_QUERY_ CONTENT_ SERIALIZED_CRL |
CertFreeCRLContext |
If the function succeeds, the return value is TRUE. If it fails, the return value is FALSE. To retrieve extended error information, use the GetLastError function.
// EXAMPLE CODE FOR USING CryptQueryObject().
// Assume that a pointer to the CERT_BLOB
// (pvObject) is already known.
// Set up the variables.
DWORD dwObjectType; // Type of the object
const CERT_BLOB *pvObject; // Pointer to a CERT_BLOB-
// initialized elsewhere
DWORD dwExpectedContentTypeFlags; // Content type
DWORD dwExpectedFormatTypeFlags; // Format flags
DWORD dwFlags; // Flag value- set to 0
DWORD dwMsgAndCertEncodingType;
DWORD dwContentType;
DWORD dwFormatType;
HCERTSTORE hCertStore;
HCRYPTMSG hMsg;
const void *pvContext; // Using PCCERT_CONTEXT because
// this is expecting a content
// type of CERT_QUERY_CONTENT_CERT
BOOL fResult; // Return value- True if function
// successful False if function
// fails
// Function call to CryptQueryObject
fResult= CryptQueryObject(
CERT_QUERY_OBJECT_BLOB,// in- object type- open a blob
pvObject, // in- object- because dwObjectType
// is a blob, this is a pointer to
// a blob- initialized elsewhere
CERT_QUERY_CONTENT_FLAG_CERT,
// in- content flag- single
// certificate
CERT_QUERY_FORMAT_BINARY, // in- format flag- binary format
0, // in- dwFlags set to 0
&dwMsgAndCertEncodingType,// out, optional
&dwContentType, // out, optional- this example
// should be
// CERT_QUERY_CONTENT_CERT
&dwFormatType, // out, optional
&hCertStore, // out, optional
&hMsg, // out, optional- in this example
// output will be a NULL
&pvContext); // out, optional
cout<< "CryptQueryObject;"<< endl
<< "fResult = "<< fResult<< endl<< endl;
if (fResult) { // returned value is TRUE
// CryptQueryObject is successful
cout<< "the encoding type (dwMsgAndCertEncodingType) is "
<< dwMsgAndCertEncodingType<< endl
<< "the content type (dwContentType) is "<< dwContentType
<< endl
<< "the format type (dwFormatType) is "<< dwFormatType<< endl
<< "the certificate store (hCertStore) is at "<< hCertStore
<< endl
<< "the message (hMsg) is "<< hMsg<< endl
<< "the context (pvContext) is "<< pvContext<< " bytes "
<< endl;
}
else { // returned value is FALSE
cout<< "CryptQueryObject failed" << endl
<< "error code = "<< GetLastError()<< endl;
}
CryptMsgClose( // free memory
hMsg);
CertCloseStore( // free memory
hCertStore,
CERT_CLOSE_STORE_FORCE_FLAG);
CertFreeCertificateContext( // free memory
(PCCERT_CONTEXT)pvContext);
// PCCERT_CONTEXT because this is a
// CERT_QUERY_CONTENT_CERT
Windows NT: Requires version 4.0 SP3 or later (or version 4.0 with IE 3.02 or later).
Windows: Unsupported.
Windows CE: Unsupported.
Header: Declared in wincrypt.h.
Import Library: Use crypt32.lib.