CryptDecodeObject
The CryptDecodeObject function decodes a structure of type lpszStructType.
#include <wincrypt.h>
BOOL WINAPI CryptDecodeObject(
DWORD dwEncodingType, // in
LPCSTR lpszStructType, // in
const BYTE *pbEncoded, // in
DWORD cbEncoded, // in
DWORD dwFlags, // in
void *pvStructInfo, // out
DWORD *pcbStructInfo // in/out
);
Parameters
-
dwEncodingType
-
The type of encoding used. Note that either a certificate or message encoding type is required. If the low-order word containing the certificate encoding type is nonzero, then it is used. Otherwise, the high-order word containing the message encoding type is used. If both are specified, the certificate encoding type in the low-order word is used.
Currently defined encoding types are shown in the following table:
Encoding type |
Value |
CRYPT_ASN_ENCODING |
0x00000001 |
X509_ASN_ENCODING |
0x00000001 |
PKCS_7_ASN_ENCODING |
0x00010000 |
-
lpszStructType
-
A pointer to an OID defining the structure type. If the high-order word of the lpszStructType parameter is zero, the low-order word specifies the integer identifier for the type of the given structure. Otherwise, this parameter is a long pointer to a null-terminated string.
For more details, see the table in CryptEncodeObject/CryptDecodeObject Functions that relates object identifier strings and predefined constants to their corresponding data structures.
-
pbEncoded
-
A pointer to the encoded structure.
-
cbEncoded
-
The number of bytes pointed to by pbEncoded.
-
dwFlags
-
-
CRYPT_DECODE_NOCOPY_FLAG (0x01)
-
This flag can be set to indicate that "no copy" optimization is enabled. This optimization, where applicable, updates the pvStructInfo fields to point to content residing within pbEncoded instead of making a copy of the content and appending it to pvStructInfo. For applicable cases, less memory needs to be allocated by the calling application and execution is faster since a copy is not being made. Note that the tradeoff when performing a "no copy" decoding is that pbEncoded can't be freed until pvStructInfo is freed.
-
CRYPT_UNICODE_NAME_DECODE_DISABLE_IE4_UTF8_FLAG (0x01000000)
-
This flag is applicable when decoding X509_UNICODE_NAME, X509_UNICODE_NAME_VALUE, or X509_UNICODE_ANY_STRING. By default, CERT_RDN_T61_STRING encoded values are initially decoded as UTF8. If the UTF8 decoding fails, then the value is decoded as 8 bit characters. If this flag is set, it skips the initial attempt to decode the value as UTF8, and decodes the value as 8 bit characters.
-
pvStructInfo
-
Pointer to a buffer that receives the decoded structure. When the buffer that is specified is not large enough to receive the decoded structure, the function sets ERROR_MORE_DATA and stores the required buffer size, in bytes, into the variable pointed to by pcbStructInfo.
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.
-
pcbStructInfo
-
Pointer to a variable that specifies the size, in bytes, of the buffer pointed to by the pvStructInfo parameter. When the function returns, this variable contains the size of the decoded data copied to *pvStructInfo. The size contained in the variable pointed to by pcbStructInfo may indicate a size larger than the decoded structure, as the decoded structure may have pointers to auxiliary data. This size will be the sum of the size needed by the decoded structure and the auxiliary data.
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 insure 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.
Return Values
TRUE if this function succeeded. FALSE if it failed.
Call GetLastError to see the reason for any failures. This 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 CRYPT_E_OSS_ERROR from the returned error and see asn1code.h for details on the error. |
ERROR_FILE_NOT_FOUND |
A decoding function could not be found for the specified dwEncodingType 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. |
QuickInfo
Windows NT: Requires version 4.0 SP3 or later. Available also in IE 3.02 and later.
Windows: Requires Windows 98 (or Windows 95 with IE 3.02 or later).
Windows CE: Unsupported.
Header: Declared in wincrypt.h.
Import Library: Use crypt32.lib.
See Also
CryptEncodeObject