Skip to content

Latest commit

 

History

History
151 lines (113 loc) · 5.68 KB

nf-wincrypt-cryptencryptmessage.md

File metadata and controls

151 lines (113 loc) · 5.68 KB
UID title description helpviewer_keywords old-location tech.root ms.assetid ms.date ms.keywords req.header req.include-header req.target-type req.target-min-winverclnt req.target-min-winversvr req.kmdf-ver req.umdf-ver req.ddi-compliance req.unicode-ansi req.idl req.max-support req.namespace req.assembly req.type-library req.lib req.dll req.irql targetos req.typenames req.redist ms.custom f1_keywords dev_langs topic_type api_type api_location api_name
NF:wincrypt.CryptEncryptMessage
CryptEncryptMessage function (wincrypt.h)
The CryptEncryptMessage function encrypts and encodes a message.
CryptEncryptMessage
CryptEncryptMessage function [Security]
_crypto2_cryptencryptmessage
security.cryptencryptmessage
wincrypt/CryptEncryptMessage
security\cryptencryptmessage.htm
security
927f2e9a-96cf-4744-bd57-420b5034d28d
12/05/2018
CryptEncryptMessage, CryptEncryptMessage function [Security], _crypto2_cryptencryptmessage, security.cryptencryptmessage, wincrypt/CryptEncryptMessage
wincrypt.h
Windows
Windows XP [desktop apps only]
Windows Server 2003 [desktop apps only]
Crypt32.lib
Crypt32.dll
Windows
19H1
CryptEncryptMessage
wincrypt/CryptEncryptMessage
c++
APIRef
kbSyntax
DllExport
Crypt32.dll
CryptEncryptMessage

CryptEncryptMessage function

-description

The CryptEncryptMessage function encrypts and encodes a message.

-parameters

-param pEncryptPara [in]

A pointer to a CRYPT_ENCRYPT_MESSAGE_PARA structure that contains the encryption parameters.

The CryptEncryptMessage function does not support the SHA2 OIDs, szOID_DH_SINGLE_PASS_STDDH_SHA256_KDF and szOID_DH_SINGLE_PASS_STDDH_SHA384_KDF.

-param cRecipientCert [in]

Number of elements in the rgpRecipientCert array.

-param rgpRecipientCert [in]

Array of pointers to CERT_CONTEXT structures that contain the certificates of intended recipients of the message.

-param pbToBeEncrypted [in]

A pointer to a buffer that contains the message that is to be encrypted.

-param cbToBeEncrypted [in]

The size, in bytes, of the message that is to be encrypted.

-param pbEncryptedBlob [out]

A pointer to 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.

-param pcbEncryptedBlob [in, out]

A 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 copied to pbEncryptedBlob.

Note  When processing the data 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 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.
 

-returns

If the function succeeds, the function returns nonzero (TRUE).

If the function fails, it returns zero (FALSE). For extended error information, call GetLastError.

Note  Errors from calls to CryptGenKey, CryptEncrypt, CryptImportKey, and CryptExportKey can be propagated to this function.
 
The GetLastError function returns the following error codes most often.
Return code 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.

-see-also

Simplified Message Functions