CryptMsgCountersignEncoded function

The CryptMsgCountersignEncoded function countersigns an existing PKCS #7 message signature. The pbCountersignature BYTE buffer it creates is a PKCS #7 encoded SignerInfo that can be used as an unauthenticated Countersignature attribute of a PKCS #9 signed-data or signed-and-enveloped-data message.


BOOL WINAPI CryptMsgCountersignEncoded(
  _In_    DWORD                    dwEncodingType,
  _In_    PBYTE                    pbSignerInfo,
  _In_    DWORD                    cbSignerInfo,
  _In_    DWORD                    cCountersigners,
  _In_    PCMSG_SIGNER_ENCODE_INFO rgCountersigners,
  _Out_   PBYTE                    pbCountersignature,
  _Inout_ PDWORD                   pcbCountersignature


dwEncodingType [in]

Specifies the encoding type used. Currently, only X509_ASN_ENCODING and PKCS_7_ASN_ENCODING are being used; however, additional encoding types may be added in the future. For either current encoding type, use: X509_ASN_ENCODING | PKCS_7_ASN_ENCODING.

pbSignerInfo [in]

A pointer to the encoded SignerInfo that is to be countersigned.

cbSignerInfo [in]

Count, in bytes, of the encoded SignerInfo data.

cCountersigners [in]

Number of countersigners in the rgCountersigners array.

rgCountersigners [in]

Array of countersigners' CMSG_SIGNER_ENCODE_INFO structures.

pbCountersignature [out]

A pointer to a buffer to receive an encoded PKCS #9 countersignature attribute.

On input, this parameter can be NULL to set the size of this information for memory allocation purposes. For more information, see Retrieving Data of Unknown Length.

pcbCountersignature [in, out]

A pointer to a variable that specifies the size, in bytes, of the buffer pointed to by the pbCountersignature parameter. When the function returns, the variable pointed to by the pcbCountersignature parameter contains the number of bytes stored in the buffer.

Return value

If the function succeeds, the return value is nonzero (TRUE).

If the function fails, the return value is zero (FALSE). For extended error information, call GetLastError.

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

Return codeDescription

The object identifier is badly formatted.


One or more arguments are not valid.


Ran out of memory.


Propagated errors might be returned from one of the following functions:

If the function fails, GetLastError may return an Abstract Syntax Notation One (ASN.1) encoding/decoding error. For information about these errors, see ASN.1 Encoding/Decoding Return Values.


Minimum supported client

Windows XP [desktop apps | UWP apps]

Minimum supported server

Windows Server 2003 [desktop apps | UWP apps]







See also

Low-level Message Functions
Simplified Message Functions