Share via


CryptSignAndEncryptMessage (Compact 2013)

3/28/2014

This 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 WINAPI CryptSignAndEncryptMessage(
    __in PCRYPT_SIGN_MESSAGE_PARA pSignPara,
    __in PCRYPT_ENCRYPT_MESSAGE_PARA pEncryptPara,
    __in DWORD cRecipientCert,
    __in PCCERT_CONTEXT rgpRecipientCert[],
    __in const BYTE* pbToBeSignedAndEncrypted,
    __in DWORD cbToBeSignedAndEncrypted,
    __out BYTE* pbSignedAndEncryptedBlob,
    __inout DWORD* pcbSignedAndEncryptedBlob
);

Parameters

  • cRecipientCert
    [in] Number of array elements in rgpRecipientCert.
  • rgpRecipientCert
    [in] Array of pointers to CERT_CONTEXT structures. Each structure is the certificate of an intended recipient of the message.
  • pbToBeSignedAndEncrypted
    [in] A pointer to a buffer that contains the content to be signed and encrypted.
  • cbToBeSignedAndEncrypted
    [in] The size, in bytes, of the pbToBeSignedAndEncrypted buffer.
  • pbSignedAndEncryptedBlob
    [out] 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
    [in, out] A pointer to a DWORD that specifies the size, in bytes, of the buffer that pbSignedAndEncryptedBlob points to. 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.

Property Value/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 codes most commonly returned by the GetLastError function.

Error code

Description

CRYPT_E_UNEXPECTED_MSG_TYPE

Not a hashed cryptographic message.

E_INVALIDARG

The message encoding type is not valid. Currently only PKCS_7_ASN_ENCODING is supported. The cbSize in *pHashPara is not valid.

ERROR_MORE_DATA

If the buffer specified by the pbComputedHash 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 pcbComputedHash.

Note

Errors from the called functions CryptCreateHash, CryptHashData, and CryptGetHashParam might be propagated to this function.

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.

Requirements

Header

wincrypt.h

Library

crypt32.lib

See Also

Reference

Certificates Functions