The CryptMsgUpdate function updates the contents of a cryptographic message, thereby allowing messages to be constructed piecemeal, by repetitively calling CryptMsgUpdate. Depending on how the message was opened, the content is either encoded or decoded.
#include <wincrypt.h>
BOOL WINAPI CryptMsgUpdate(
HCRYPTMSG hCryptMsg, // in
const BYTE *pbData, // in
DWORD cbData, // in
BOOL fFinal // in
);
When there is no detached data (the CMSG_DETACHED_FLAG flag was not used) and a message has been opened (either CryptMsgOpenToDecode or CryptMsgOpenToEncode was performed for the message), fFinal should be set to true, and CryptMsgUpdate is only called once.
When there is detached data (the CMSG_DETACHED_FLAG flag was used) and a message has been opened for encode (CryptMsgOpenToEncode was performed for the message), fFinal should be set to true only on the last call to CryptMsgUpdate.
For detached data in the decode case, the header and the content of a message are contained in different blobs. Each blob requires that fFinal be set to true as described below.
When there is detached data (the CMSG_DETACHED_FLAG flag was used) and a message has been opened for decode (CryptMsgOpenToDecode was performed for the message), fFinal should be set to true when the header is processed by a single call to CryptMsgUpdate. Then fFinal is set false while processing the detached data in subsequent calls to CryptMsgUpdate, until the last detached data block is to be processed, where it should be set true again.
If the function fails, the return value is false (zero). If it succeeds, the return value is true (non-zero).
To retrieve extended error information, use the GetLastError function.
Errors encountered in the application defined callback function specified by pStreamInfo in CryptMsgOpenToDecode and CryptMsgOpenToEncode may be propagated to CryptMsgUpdate if streaming is used. If this happens, SetLastError is not called by CryptMsgUpdate after the callback returns, which preserves any errors encountered under the control of the application. It is the responsibility of the callback function (or one of the APIs that it calls) to call SetLastError if an error occurs while the application is processing the streamed data.
The following table lists the error codes most commonly returned by the GetLastError function.
Error code | Description |
---|---|
CRYPT_E_INVALID_MSG_TYPE | The message type is invalid. |
CRYPT_E_MSG_ERROR | An error was encountered doing a cryptographic operation. |
CRYPT_E_OID_FORMAT | The object identifier is badly formatted. |
CRYPT_E_OSS_ERROR | OSS Certificate encode/decode error code base. Note, to get the OSS error subtract CRYPT_E_OSS_ERROR from the returned error and see asn1code.h for details on the error. |
CRYPT_E_UNEXPECTED_ENCODING | The message is not encoded as expected. |
CRYPT_E_UNKNOWN_ALGO | The cryptographic algorithm is unknown. |
E_INVALIDARG | One or more arguments are invalid. |
E_OUTOFMEMORY | Ran out of memory. |
Propagated errors that may be encountered when a message has been opened for encode: | When the message type is CMSG_SIGNED CryptHashData CryptGetHashParam CryptSignHash
When the message type is CMSG_ENVELOPED CryptGetKeyParam
When the message type is CMSG_HASHED CryptHashData |
Propagated errors that may be encountered when a message has been opened for decode: | When the message type is CMSG_SIGNED CryptCreateHash CryptHashData
When the message type is CMSG_HASHED CryptCreateHash |
See Signed Message Example Code.
See Enveloped Message Example 1.
See Hashed Message Example Code.
Windows NT: Requires version 4.0 SP3 or later. Available also in IE 3.02 and later.
Windows: Requires Windows 98 (or Windows 95 with IE 3.02 or later).
Windows CE: Unsupported.
Header: Declared in wincrypt.h.
Import Library: Use crypt32.lib.
CryptMsgGetParam, CryptMsgOpenToEncode, CryptMsgOpenToDecode