Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

CryptMsgCalculateEncodedLength (Windows CE 5.0)

Windows CE 5.0
Send Feedback

This function calculates the maximum number of bytes need for an encoded cryptographic message when it is given the message type, encoding parameters, and total length of the data to be encoded. Note that the result will always be greater than or equal to the actual number of bytes needed.

DWORD WINAPI CryptMsgCalculateEncodedLength(
  DWORD dwMsgEncodingType,
  DWORD dwFlags,
  DWORD dwMsgType,
  const void* pvMsgEncodeInfo,
  LPSTR pszInnerContentObjID,
  DWORD cbData



[in] Specifies the encoding type used. It is always acceptable to specify both the certificate and message encoding types by combining them with a bitwise-OR operation as shown in the following example:


The message encoding type defines how the message is encoded. The message encoding type is stored in the high-order word of the encoding type structure.

The following list shows the currently defined encoding:

[in] The following table shows the currently defined flags.
CMSG_BARE_CONTENT_FLAG Indicates that streamed output will not have an outer ContentInfo wrapper, as defined by PKCS #7. This makes it suitable to be streamed into an enclosing message.
CMSG_DETACHED_FLAG Indicates that there is detached data being supplied for the subsequent calls to CryptMsgUpdate.
CMSG_CONTENTS_OCTETS_FLAG Indicates that the size of the Distinguished Encoding Rules (DER) encoding of a message to be nested inside an enveloped message must be calculated. This is particularly useful when streaming is being performed.

DER is a set of rules for encoding ASN.1 defined data as a stream of bits for external storage or transmission. Every ASN.1 object has exactly one corresponding DER encoding. DER is defined in CCITT Recommendation X.509, Section 8.7. This is one of two encoding methods currently used by CryptoAPI.

CMSG_CMS_ENCAPSULATED_CONTENT_FLAG Indicates that non-Data type inner content is encapsulated within an OCTET STRING. This flag is applicable for both Signed and Enveloped messages.

Inner data is any encoded data used as the message for another encoded message. For example, an enveloped message and its hash value may be the inner data for a second message.

[in] The following table shows the currently defined message types.
CMSG_DATA An octet (BYTE) string.
CMSG_ENCRYPTED Not implemented.
[in] Pointer to the data to be encoded. The type of data pointed to depends on the value of dwMsgType. For details, see the dwMsgType table.
[in, optional] When calling CryptMsgCalculateEncodedLength with data provided to CryptMsgUpdate already encoded, the appropriate object identifier is passed in pszInnerContentObjID. If pszInnerContentObjID is NULL, the inner content type is assumed not to have been previously encoded, and is encoded as an octet string and given the type CMSG_DATA.

When streaming is being used, pszInnerContentObjID must be either NULL or szOID_RSA_data.

The following table shows the algorithm object identifiers that are commonly used:

  • szOID_RSA_data
  • szOID_RSA_signedData
  • szOID_RSA_envelopedData
  • szOID_RSA_signEnvData
  • szOID_RSA_digestedData
  • szOID_RSA_encryptedData

A user can define new inner content usage. The user must ensure that the sender and receiver of the message agree upon the semantics associated with the object identifier.

[in] Size, in bytes, of the content.

Return Values

Returns the required length for an encoded cryptographic message. This length might not be the exact length but it will not be less than the required length. If the function fails, zero is returned.

To retrieve extended error information, use the GetLastError function. The following table shows the error codes that are most commonly returned.

CRYPT_E_INVALID_MSG_TYPE The message type is invalid.
CRYPT_E_UNKNOWN_ALGO The cryptographic algorithm is unknown.
E_INVALIDARG One or more arguments are invalid.


OS Versions: Windows CE 5.0 and later.
Header: Wincrypt.h.
Link Library: Coredll.lib.

See Also

Cryptography Functions | CryptMsgOpenToEncode

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.

© 2015 Microsoft