Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

This function decodes a structure of the type indicated by the lpszStructTypeparameter. This function offers a significant performance improvement over the CryptDecodeObjectfunction by supporting memory allocation with the CRYPT_DECODE_ALLOC_FLAG value.

Syntax

BOOL WINAPI CryptDecodeObjectEx(
  DWORD 
dwCertEncodingType, 
  LPCSTR 
lpszStructType, 
  const BYTE* 
pbEncoded, 
  DWORD 
cbEncoded, 
  DWORD 
dwFlags, 
  PCRYPT_DECODE_PARA 
pDecodePara, 
  void* 
pvStructInfo, 
  DWORD* 
pcbStructInfo
);

Parameters

dwCertEncodingType

[in] Specifies the type of encoding used. Currently, only X509_ASN_ENCODING is used; however, additional encoding types may be added in the future.

lpszStructType

[in] Pointer to an OID defining the structure type. If the high-order word of the lpszStructTypeparameter is zero, the low-order word specifies the integer identifier for the type of the specified structure. Otherwise, this parameter is a long pointer to a NULL-terminated string.

For more information about object identifier strings, their predefined constants, and their corresponding structures, see CryptEncodeObjectExor CryptDecodeObjectEx.

pbEncoded

[in] Pointer to the data to be decoded. The structure must be of the type specified by the lpszStructTypeparameter.

cbEncoded

[in] Number of bytes pointed to by the pbEncodedparameter. This value represents the number of bytes to be decoded.

dwFlags

[in] Bitmask of flags. The following table shows values for these flags that can be combined with bitwise ORoperations.

Value Description

CRYPT_DECODE_ALLOC_FLAG

The called decoding function allocates memory for the decoded structure. A pointer to the allocated structure is returned in the pvStructInfoparameter.

If pDecodeParaor pDecodePara-> pfnAllocis NULL, then the LocalAllocfunction is called for the allocation and the LocalFreefunction must be called to free the memory.

If pDecodeParaand pDecodePara->pfnAllocare non-NULL, then pDecodePara-> pfnAllocis called for the allocation and the function pointed to by pDecodePara-> pfnFreemust be called to free the memory.

CRYPT_DECODE_NOCOPY_FLAG

This flag can be set to enable a no copy optimization. This optimization updates the pvStructInfoparameters to point to content residing within the pbEncodedparameter instead of making a copy of the content and appending it to the pvStructInfoparameter. The calling application needs to allocate less memory and execution is faster because a copy is not made. Note that when performing no copy decoding, the pbEncodedparameter cannot be freed until the pvStructInfoparameter is freed.

CRYPT_UNICODE_NAME_DECODE_DISABLE_IE4_UTF8_FLAG

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 eight-bit characters. If this flag is set, it skips the initial attempt to decode the value as UTF8 and decodes the value as eight-bit characters.

CRYPT_DECODE_TO_BE_SIGNED_FLAG

By default, the contents of the buffer pointed to by the pbEncodedparameter included the signed content and the signature. If this flag is set, the buffer includes only the to be signed content. This flag is applicable to X509_CERT_TO_BE_SIGNED, X509_CERT_CRL_TO_BE_SIGNED, X509_CRT_REQUEST_TO_BE_SIGNED, and X509_KEYGEN_REQUEST_TO_BE_SIGNED objects.

CRYPT_DECODE_SHARE_OID_STRING_FLAG

When this flag is set, the OID strings are allocated in Crypt32.dll and shared instead of being copied into the returned data structure. This flag can be set if Crypt32.dll is not unloaded before the caller is unloaded.

CRYPT_DECODE_NO_SIGNATURE_BYTE_REVERSAL_FLAG

By default, the signature bytes are reversed. If this flag is set, this byte reversal is inhibited.

pDecodePara

[in] Pointer to a CRYPT_DECODE_PARAstructure containing decoding paragraph information. If the pDecodeParaparameter is set to NULL, then the LocalAllocand LocalFreefunctions are used to allocate and free memory. If the pDecodeParaparameter points to a CRYPT_DECODE_PARAstructure that the structure passes in callback functions to allocate and free memory. These callback functions override the default memory allocation of the LocalAllocand LocalFreefunctions.

pvStructInfo

[out] Address of a pointer to a buffer, if the CRYPT_ENCODE_ALLOC_FLAG flag for the dwFlagsparameter is set. The value of the pvStructInfoparameter must not be NULL because memory is allocated inside the function and the pointer is stored at * pvStructInfo.

If CRYPT_ENCODE_ALLOC_FLAG is not set, the pvStructInfoparameter is a 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 the ERROR_MORE_DATA code and stores the required buffer size, in bytes, in the variable pointed to by the pcbStructInfoparameter.

This parameter can be NULL to retrieve the size of this information for memory allocation purposes.

pcbStructInfo

[in, out] On input, pointer to a DWORDthat contains the size, in bytes, of the buffer pointed to by the pvStructInfoparameter. On output, the DWORDcontains the number of bytes stored in the buffer. The size contained in the variable pointed to by the pcbStructInfoparameter can indicate a size larger than the decoded structure, as the decoded structure can include pointers to auxiliary data. This size is the sum of the size needed by the decoded structure and the auxiliary data.

When CRYPT_DECODE_ALLOC_FLAG is set, the pcbStructInfoparameter is the address of a pointer to the DWORDthat is updated.

When processing the data returned in the buffer, applications must use the actual size of the data returned. The actual size can 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 fits 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 Value

If the function succeeds, the return value is nonzero, or TRUE.

If the function fails, the return value is zero, or FALSE.

For extended error information, call the GetLastErrorfunction. The following table shows possible error codes.

Value Description

CRYPT_E_BAD_ENCODE

An error was encountered while decoding.

ERROR_FILE_NOT_FOUND

A decoding function could not be found for the specified dwCertEncodingTypeand lpszStructTypeparameters.

ERROR_MORE_DATA

If the buffer specified by the pvStructInfoparameter 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 the pcbStructInfoparameter.

Remarks

The desktop operating system supports the flag PKCS_7_ASN_ENCODING, but Windows Embedded CE does not and ignores the flag when it is specified.

Requirements

Header wincrypt.h
Library crypt32.lib
Windows Embedded CE Windows CE 3.0 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also

Reference

CryptEncodeObjectEx

Other Resources

LocalAlloc
LocalFree