CryptSignAndEncryptMessage function

The CryptSignAndEncryptMessage function creates a hash of the specified content, signs the hash, encrypts the content, hashes the encrypted contents and the signed hash, and then encodes both the encrypted content and the signed hash. The result is the same as if the hash were first signed and then encrypted.

Syntax

BOOL CryptSignAndEncryptMessage(
  PCRYPT_SIGN_MESSAGE_PARA    pSignPara,
  PCRYPT_ENCRYPT_MESSAGE_PARA pEncryptPara,
  DWORD                       cRecipientCert,
  PCCERT_CONTEXT []           rgpRecipientCert,
  const BYTE                  *pbToBeSignedAndEncrypted,
  DWORD                       cbToBeSignedAndEncrypted,
  BYTE                        *pbSignedAndEncryptedBlob,
  DWORD                       *pcbSignedAndEncryptedBlob
);

Parameters

pSignPara

A pointer to a CRYPT_SIGN_MESSAGE_PARA structure that contains the signature parameters.

pEncryptPara

A pointer to a CRYPT_ENCRYPT_MESSAGE_PARA structure containing encryption parameters.

cRecipientCert

Number of array elements in rgpRecipientCert.

rgpRecipientCert

Array of pointers to CERT_CONTEXT structures. Each structure is the certificate of an intended recipients of the message.

pbToBeSignedAndEncrypted

A pointer to a buffer containing the content to be signed and encrypted.

cbToBeSignedAndEncrypted

The size, in bytes, of the pbToBeSignedAndEncrypted buffer.

pbSignedAndEncryptedBlob

A pointer to a buffer to receive the encrypted and encoded message.

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.

pcbSignedAndEncryptedBlob

A pointer to DWORD specifying the size, in bytes, of the buffer pointed to by pbSignedAndEncryptedBlob. When the function returns, this variable contains the size, in bytes, of the signed and encrypted message copied to *pbSignedAndEncryptedBlob.

Note  When processing the data returned, applications must use the actual size of the data returned. The actual size can be slightly smaller than the size of the buffer specified on input. (On input, buffer sizes are usually specified large enough to ensure 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 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 lists the error code most commonly returned by the GetLastError function.

Return code Description
ERROR_MORE_DATA
If the buffer specified by the pbSignedAndEncryptedBlob 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, into the variable pointed to by pcbSignedAndEncryptedBlob.
 
Note  Errors from the called functions CryptSignMessage and CryptEncryptMessage might be propagated to this function.
 

Requirements

   
Minimum supported client Windows XP [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps only]
Target Platform Windows
Header wincrypt.h
Library Crypt32.lib
DLL Crypt32.dll

See Also

CryptDecryptAndVerifyMessageSignature

CryptSignMessage

Simplified Message Functions