CryptFormatObject

[This is preliminary documentation and subject to change.]

The CryptFormatObject function formats the encoded data and returns a Unicode string in the allocated buffer according to the certificate encoding type.

#include <wincrypt.h>
BOOL WINAPI CryptFormatObject(
  DWORD dwCertEncodingType,     // in
  DWORD dwFormatType,           // in
  DWORD dwFormatStrType,        // in
  void *pFormatStruct,          // in
  LPCSTR lpszStructType,        // in
  const BYTE *pbEncoded,        // in
  DWORD cbEncoded,              // in
  void *pbFormat,               // out
  DWORD *pcbFormat              // in/out
);
 

Parameters

dwCertEncodingType
Type of encoding used on the certificate. Currently defined certificate encoding types are shown in the following table:
Encoding type Value
X509_ASN_ENCODING 0x00000001

dwFormatType
Format type values. Not used. Set to 0.
dwFormatStrType
Structure format type values. This parameter can be zero, or you can specify one or more of the following flags by using the bitwise OR operator to combine them:

Currently defined values are shown in the following table:
Format value Description
0 Display the data in single line. Each subfield is concatenated with a ", " (see Remarks).
CRYPT_FORMAT_
STR_MULTI_LINE
Display the data in multiple lines rather than the default of a single line display (see Remarks).
CRYPT_FORMAT_
STR_NO_HEX
Disables the hex dump (see Remarks).

pFormatStruct
Pointer to the format of the structure. Not used. Set to NULL.
lpszStructType
Pointer to an OID defining the encoded data. 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.

The following table is a listing of supported OIDs with the associated OID extension:
OID Name OID
SPC_FINANCIAL_CRITERIA_OBJID 1.3.6.1.4.1.311.2.1.27
SPC_SP_AGENCY_INFO_OBJID 1.3.6.1.4.1.311.2.1.10
szOID_AUTHORITY_INFO_ACCESS 1.3.6.1.5.5.7.1.1
szOID_AUTHORITY_KEY_IDENTIFIER2 2.5.29.35
szOID_BASIC_CONSTRAINTS2 2.5.29.19
szOID_CERT_POLICIES 2.5.29.32
szOID_CRL_DIST_POINTS 2.5.29.31
szOID_CRL_REASON_CODE 2.5.29.21
szOID_ENHANCED_KEY_USAGE 2.5.29.37
szOID_ISSUER_ALT_NAME2 2.5.29.18
szOID_KEY_ATTRIBUTES 2.5.29.2
szOID_KEY_USAGE 2.5.29.15
szOID_KEY_USAGE_RESTRICTION 2.5.29.4
szOID_NEXT_UPDATE_LOCATION 1.3.6.1.4.1.311.10.2
szOID_RSA_SMIMECapabilities 1.2.840.113549.1.9.15
szOID_SUBJECT_ALT_NAME2 2.5.29.17
szOID_SUBJECT_KEY_IDENTIFIER 2.5.29.14

pbEncoded
Pointer to the encoded data to be formatted. If lpszStructType is one of the OIDs listed above, the pbEncoded is the encoded extension.
cbEncoded
Size, in bytes, of the pbEncoded structure.
pbFormat
Pointer to a buffer that receives the formatted string. 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 pcbFormat.

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.

pcbFormat
Pointer to a variable that specifies the size, in bytes, of the buffer pointed to by the pbFormat parameter. When the function returns, the variable pointed to by the pcbFormat parameter contains the number of bytes stored in the buffer. This parameter can be NULL, only if pbFormat is NULL.

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

If the function succeeds, the return value is TRUE. If it does not succeed, the return value is FALSE. To retrieve extended error information, use the GetLastError function.

Remarks

The default behavior of CryptFormatObject is to return single line display of the encoded data, that is, each subfield will be concatenated with a ", " on one line. If a user prefers to display the data in multiple line, set the flag CRYPT_FORMAT_STR_MULTI_LINE, that is, each subfield will be displayed on a separate line.

If there is no formatting routine installed or registered for the lpszStructType, the hex dump of the encoded BLOB Structure will be returned. A user can set the flag CRYPT_FORMAT_STR_NO_HEX to disable the hex dump.

Example

// EXAMPLE CODE FOR USING CryptFormatObject().
// Assume that a pointer to an encoded data structure
// (pbEncoded) is already known.

// Set up the variables.
DWORD dwCertEncodingType; // Type of encoding
DWORD dwFormatType;       // Format type
DWORD dwFormatStrType;    // Structure format flags
LPCSTR pFormatStruct;     // Pointer to structure format- set to NULL
LPCSTR  lpszStructType;   // Pointer to type of encoding
const BYTE *pbEncoded;    // Pointer to the encoded object to be read
                          //   and formatted
DWORD  cbEncoded;         // size of structure
BYTE *pbFormat;           // Pointer to the formatted string
DWORD  pcbFormat;
DWORD  cbFormat;          // size of the formated object
BOOL fResult;             // Return value- True if function successful
                          //   False if function fails       

// initalize the pointers/ structure
cout<< "Begin initalization."<< endl;

fResult= CryptFormatObject(
           X509_ASN_ENCODING,          // in- dwCertEncodingType
           0,                          // in- dwFormatType set to 0
           CRYPT_FORMAT_STR_MULTI_LINE,// in- dwFormatStrType- print
                                       //   in multiple line format
           NULL,                       // in- FormatStruct set to NULL
           szOID_CERT_POLICIES,        // in- Structure name
           pbEncoded,                  // in- Pointer to data
                                       //   structure to be formatted
                                       //   initialized elsewhere
           1024,                       // in- size in bytes
           NULL,                       // out- set to NULL to allocate
                                       //   memory
           &cbFormat);                 // in/out- pbFormat size

if (!fResult){
 cout<< "First call to CryptFormatObject failed"<< endl;
}
else {
  cout<< "First call to CryptFormatObject successful"<< endl;
  pbFormat = (BYTE*)malloc (cbFormat);
  cout<< "memory allocated" << endl;

// Function call to format the object
fResult= CryptFormatObject(
           X509_ASN_ENCODING,          // in- dwCertEncodingType
           0,                          // in- dwFormatType set to 0
           CRYPT_FORMAT_STR_MULTI_LINE,// in- dwFormatStrType- print
                                       //   in multiple line format
           NULL,                       // in- FormatStruct set to NULL
           szOID_CERT_POLICIES,        // in- Structure name
           pbEncoded,                  // in- initialized elsewhere
           1024,                       // in- size in bytes
           pbFormat,                   // out- pbFormat
           &cbFormat);                 // in/out- pbFormat size

if (!fResult){
 cout<< "Second call to CryptFormatObject failed"<< endl;
    }
else {
  cout<< "Second call to CryptFormatObject successful"<< endl
      << "The string is "<< pbFormat<< endl
      << "size of pbFormat (cbFormat)= "<< cbFormat<< endl;
    }
free(pbFormat);

}
}
 

QuickInfo

  Windows NT: Requires version 5.0 or later.
  Windows: Unsupported.
  Windows CE: Unsupported.
  Header: Declared in wincrypt.h.
  Import Library: Use crypt32.lib.