CryptEncryptMessage (Compact 2013)

3/28/2014

This function encrypts and encodes a message.

Syntax

BOOL WINAPI CryptEncryptMessage(
     __in PCRYPT_ENCRYPT_MESSAGE_PARA pEncryptPara,
      __in DWORD cRecipientCert,
      __in PCCERT_CONTEXT rgpRecipientCert[],
      __in const BYTE* pbToBeEncrypted,
      __in DWORD cbToBeEncrypted,
      __out BYTE* pbEncryptedBlob,
      __inout DWORD* pcbEncryptedBlob
);

Parameters

  • cRecipientCert
    [in] Number of elements in the rgpRecipientCert array.
  • rgpRecipientCert
    [in] Array of pointers to CERT_CONTEXT structures that contain the certificates of intended recipients of the message.
  • pbToBeEncrypted
    [in] Pointer to a buffer that contains the message that is to be encrypted.
  • cbToBeEncrypted
    [in] Size, in bytes, of the message that is to be encrypted.
  • pbEncryptedBlob
    [out] Pointer to a binary large object (BLOB) that contains a buffer that receives the encrypted and encoded message. To set the size of this information for memory allocation purposes, this parameter can be NULL. For more information, see Retrieving Data of Unknown Length.
  • pcbEncryptedBlob
    [in, out] Pointer to a DWORD that specifies the size, in bytes, of the buffer pointed to by the pbEncryptedBlob parameter. When the function returns, this variable contains the size, in bytes, of the encrypted and encoded message that is copied to pbEncryptedBlob.

    Note

    When processing the data that is returned in the buffer of the pbEncryptedBlob, applications need to 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 so they are 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

Returns nonzero (true) if the function succeeds; otherwise, zero (false). To retrieve extended error information, call GetLastError.

Note

Errors from calls to CryptGenKey, CryptEncrypt, CryptImportKey, and CryptExportKey can be propagated to this function.

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

Value

Description

ERROR_MORE_DATA

If the buffer specified by the pbEncryptedBlob 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, in the variable pointed to by pcbEncryptedBlob.

E_INVALIDARG

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

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