Compartilhar via


CryptDecodeObjectEx (Compact 2013)

3/28/2014

This function decodes a structure of the type indicated by the lpszStructType parameter. This function offers a significant performance improvement over the CryptDecodeObject function 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. Only X509_ASN_ENCODING is used.
  • lpszStructType
    [in] 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 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 CryptEncodeObjectEx or CryptDecodeObjectEx.

  • pbEncoded
    [in] Pointer to the data to be decoded. The structure must be of the type specified by the lpszStructType parameter.
  • cbEncoded
    [in] Number of bytes pointed to by the pbEncoded parameter. 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 OR operations.

    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 pvStructInfo parameter.

    If pDecodePara or pDecodePara->pfnAlloc is NULL, then the LocalAlloc function is called for the allocation and the LocalFree function 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.

    CRYPT_DECODE_NOCOPY_FLAG

    This flag can be set to enable a no copy optimization. This optimization updates the pvStructInfo parameters to point to content residing within the pbEncoded parameter instead of making a copy of the content and appending it to the pvStructInfo parameter. 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 pbEncoded parameter cannot be freed until the pvStructInfo parameter 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 pbEncoded parameter 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_PARA structure containing decoding paragraph information. If the pDecodePara parameter is set to NULL, then the LocalAlloc and LocalFree functions are used to allocate and free memory. If the pDecodePara parameter points to a CRYPT_DECODE_PARA structure that the structure passes in callback functions to allocate and free memory. These callback functions override the default memory allocation of the LocalAlloc and LocalFree functions.
  • pvStructInfo
    [out] Address of a pointer to a buffer, if the CRYPT_ENCODE_ALLOC_FLAG flag for the dwFlags parameter is set. The value of the pvStructInfo parameter 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 pvStructInfo parameter 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 pcbStructInfo parameter.

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

  • pcbStructInfo
    [in, out] On input, pointer to a DWORD that contains the size, in bytes, of the buffer pointed to by the pvStructInfo parameter. On output, the DWORD contains the number of bytes stored in the buffer. The size contained in the variable pointed to by the pcbStructInfo parameter 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 pcbStructInfo parameter is the address of a pointer to the DWORD that 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 GetLastError function. 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 dwCertEncodingType and lpszStructType parameters.

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 the pcbStructInfo parameter.

Remarks

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

Requirements

Header

wincrypt.h

Library

crypt32.lib

See Also

Reference

Certificates Functions
CryptEncodeObjectEx
LocalAlloc
LocalFree