The CryptEncodeObject function encodes a structure of type lpszStructType.
#include <wincrypt.h>
BOOL WINAPI CryptEncodeObject(
DWORD dwEncodingType, // in
LPCSTR lpszStructType, // in
const void *pvStructInfo, // in
BYTE *pbEncoded, // out
DWORD *pcbEncoded // in/out
);
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 |
For more details, see the table in CryptEncodeObject/CryptDecodeObject Functions that relates object identifier strings and predefined constants to their corresponding data structures.
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.
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.
TRUE if this function succeeded. FALSE if this function 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 encoding. |
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 | An encoding function could not be found for the specified dwEncodingType and lpszStructType. |
ERROR_MORE_DATA | If the buffer specified by the pbEncoded 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 pcbEncoded. |
See Certificate Request Example Code.
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.