[This is preliminary documentation and subject to change.]
The CryptDecodeObjectEx function decodes a structure of type lpszStructType. CryptDecodeObjectEx offers a significant performance improvement over CryptDecodeObject by supporting the memory allocation with the CRYPT_DECODE_ALLOC_FLAG.
#include <wincrypt.h>
BOOL WINAPI CryptDecodeObjectEx(
DWORD dwCertEncodingType, // in
LPCSTR lpszStructType, // in
const BYTE *pbEncoded, // in
DWORD cbEncoded, // in
DWORD dwFlags, // in
PCRYPT_DECODE_PARA pDecodePara, // in, optional
void *pvStructInfo, // out, optional
DWORD *pcbStructInfo // in, out
);
Currently defined encoding types are shown in the following table:
Certificate Encoding type | Value |
---|---|
CRYPT_ASN_ENCODING | 0x00000001 |
X509_ASN_ENCODING | 0x00000001 |
PKCS_7_ASN_ENCODING | 0x00010000 |
For more details, see the table in CryptEncodeObject/CryptDecodeObject Functions that relates object identifier strings and predefined constants to their corresponding data structures.
The following flags can be combined with a bitwise OR operation into CryptDecodeObjectEx dwFlags.
If pDecodePara or pDecodePara->pfnAlloc is NULL, then, LocalAlloc is called for the allocation and LocalFree must be called to free the memory.
If pDecodePara and pDecodePara->pfnAlloc are non NULL, then pDecodePara->pfnAlloc is called for the allocation and the function pointed to by pDecodePara->pfnFree must be called to free the memory.
This parameter can be NULL to set the size of this information for memory allocation purposes. For more information, see Common In/Out Parameter Conventions.
When the CRYPT_DECODE_ALLOC_FLAG is set, pvStructInfo is the address of a pointer to the buffer that will be updated. Because memory is allocated and its pointer is stored at *pvStructInfo, pvStructInfo must always be non-NULL.
When the CRYPT_DECODE_ALLOC_FLAG is set, pcbStructInfo is the address of a pointer to the DWORD that will be updated.
Note When processing the data returned in the buffer, applications need to use the actual size of the data returned. The actual size may be slightly smaller than the size of the buffer specified on input. (On input, buffer sizes are usually specified large enough to ensure that the largest possible output data will fit in the buffer.) On output, the variable pointed to by this parameter is updated to reflect the actual size of the data copied to the buffer.
TRUE if the function succeeded, FALSE if the function failed.
Call GetLastError to see the reason for any failures. The function has the following error codes:
Error code | Description |
---|---|
CRYPT_E_BAD_ENCODE | An error was encountered while decoding. |
CRYPT_E_OSS_ERROR | ASN.1 encoding error. Note, to get the OSS error subtract the value in CRYPT_E_OSS_ERROR from the returned error value and see asn1code.h for details on the error. |
ERROR_FILE_NOT_FOUND | A decoding function could not be found for the specified dwCertEncodingType and lpszStructType. |
ERROR_MORE_DATA | If the buffer specified by the pvStructInfo parameter is not large enough to hold the returned data, the function sets the ERROR_MORE_DATA code, and stores the required buffer size, in bytes, in the variable pointed to by pcbStructInfo. |
// EXAMPLE CODE FOR USING CryptDecodeObjectEx().
// Assume that pointers to the data to be decoded
// (pbEncoded) and the # of bytes to be decoded (cbEncoded)
// are initialized elsewhere.
#define MY_ENCODING_TYPE (PKCS_7_ASN_ENCODING | X509_ASN_ENCODING)
// Declare and initialize.
const BYTE *pbEncoded; // Initialized elsewhere
DWORD cbEncoded; // Initialized elsewhere
PCRYPT_DECODE_PARA DecodePara;
void *pvStructInfo;
DWORD cbStructInfo;
BOOL fResult;
DecodePara->cbSize= sizeof(PCRYPT_DECODE_PARA);
// CryptDecodeObjectEx function call.
fResult= CryptDecodeObjectEx(
MY_ENCODING_TYPE, // in- Encoding/decoding type.
X509_NAME, // in- Struct type
pbEncoded, // in- Data to be decoded.
cbEncoded, // in- # of bytes of pbEncoded.
CRYPT_DECODE_ALLOC_FLAG,
// in- dwFlags
NULL, // in, optional- DecodePara set to NULL
// to use default memory allocation
// of+ LocalAlloc and LocalFree.
(void*) &pvStructInfo,
// out, optional- pvStructInfo
&cbStructInfo); // in, out- pvStructInfo size
if(!fResult) { // FALSE returned- function failed.
printf("The call to CryptDecodeObjectEx failed.\n");
}
else { // TRUE returned- function successful.
printf("The call to CryptDecodeObjectEx successful.\n");
}
// Free the memory.
LocalFree(pvStructInfo);
Windows NT: Requires version 5.0 or later.
Windows: Unsupported.
Windows CE: Unsupported.
Header: Declared in wincrypt.h.
Import Library: Use crypt32.lib.
CryptEncodeObject, CryptEncodeObjectEx, CryptDecodeObject