CryptMsgSignCTL

The CryptMsgSignCTL function creates a signed message containing the encoded CTL.

#include <wincrypt.h>
BOOL WINAPI CryptMsgSignCTL(
  DWORD dwMsgEncodingType,             // in
  BYTE *pbCtlContent,                  // in
  DWORD cbCtlContent,                  // in
  PCMSG_SIGNED_ENCODE_INFO pSignInfo,  // in
  DWORD dwFlags,                       // in
  BYTE *pbEncoded,                     // out
  DWORD *pcbEncoded                    // in/out
);
 

Parameters

dwMsgEncodingType
The type of message encoding used. Note that it is always acceptable to specify both the certificate and message encoding types, by combining them with a bitwise OR operation, as shown in the following example:
CRYPT_ASN_ENCODING | PKCS_7_ASN_ENCODING
 

However, it is required only to specify the message encoding here. Currently defined encoding types are shown in the following table.
Encoding type Value
CRYPT_ASN_ENCODING 0x00000001
PKCS_7_ASN_ENCODING 0x00010000

pbCtlContent
The encoded CTL_INFO which may be obtained via a CTL_CONTEXT's pbCtlContent member or via a CryptEncodeObject (PKCS_CTL).
cbCtlContent
The count, in bytes, of the content pointed to by pbCtlContent.
pSignInfo
Points to a CMSG_SIGNED_ENCODE_INFO structure which optionally contains an array of a CMSG_SIGNER_ENCODE_INFO structures.

The message can be encoded without any signers if the CMSG_SIGNED_ENCODE_INFO structure's cbSize member is set to the size of the structure and all of the other members are set to zero.

dwFlags
Flag values. This parameter is reserved for future use and should be set to zero in the interim.
pbEncoded
Pointer to a buffer that receives the encoded message produced.

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.

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

Return Values

If the function fails, the return value is FALSE (zero). If it succeeds, the return value is TRUE (non-zero).

To retrieve extended error information, use the GetLastError function.

The following table lists the error codes most commonly returned by the GetLastError function.

Error code Description
Propagated errors that may be encountered: An error can be propagated from
CryptMsgOpenToEncode
CryptMsgUpdate

Example

// EXAMPLE CODE FOR USING CryptMsgSignCTL().
// Creates a signed message.
// Assume that pointers to the CTL_INFO structure
// (pbCtlContent), and the PCMSG_SIGNED_ENCODE_INFO
// (pSignInfo) have already been defined.

// Set up the variables.
DWORD dwMsgEncodingType = CRYPT_ASN_ENCODING | PKCS_7_ASN_ENCODING;
                                   // Type of encoding
BYTE *pbCtlContent;                // Pointer to the encoded CTL_INFO
DWORD cbCtlContent = 128;          // # of bytes of CTL_INFO
PCMSG_SIGNED_ENCODE_INFO pSignInfo;// Pointer to
                                   //   CMSG_SIGNED_ENCODE_INFO
                                   //   structure
DWORD dwFlags = 0;                 // Flag values- reserved- set to 0
BYTE *pbEncoded;                   // out
DWORD cbEncoded;                   // in/out
BOOL fResult;                      // Return TRUE if function succeeds
                                   //   FALSE if function fails

// Function called the first time to get a pointer to
// the size of the encoded message (cbEncoded)
fResult= CryptMsgSignCTL(
           dwMsgEncodingType,
           pbCtlContent,
           cbCtlContent,
           pSignInfo,
           0,                      // dwFlags set to 0
           NULL,                   // NULL on first call
           &cbEncoded);

if (!fResult){
  cout << "first call to CryptMsgSignCTL failed"<< endl;
}
else {
  cout<< "first call to CryptMsgSignCTL successful"<< endl;
  pbEncoded = (BYTE*) malloc (cbEncoded);
  cout<< "memory allocated"<< endl;
}
// Function call to a pointer to the encoded message
fResult= CryptMsgSignCTL(
           dwMsgEncodingType,      // in
           pbCtlContent,           // in
           cbCtlContent,           // in
           pSignInfo,              // in
           dwFlags,                // in
           pbEncoded,              // out
           &cbEncoded);            // in/out

if (!fResult) {                    // FALSE
 cout<< "Function failed"<< endl
     << "error code = "<< GetLastError()<< endl;
}
else {                             // TRUE
 cout<< "Function succeeded"<< endl
     << "size = "<< &cbEncoded<< endl
     << "encoded message at location = "<< pbEncoded<< endl;
}
free (pbEncoded);
 

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

CMSG_SIGNED_ENCODE_INFO, CryptMsgEncodeAndSignCTL, CryptMsgOpenToEncode