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
);
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 |
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.
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.
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 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);
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.
CMSG_SIGNED_ENCODE_INFO, CryptMsgEncodeAndSignCTL, CryptMsgOpenToEncode