MS CryptoAPI

Posted on 2000-03-27
Last Modified: 2011-04-14
can someone please deminstrate how to use the function "CryptSignMessage" in visual basic. An example in C can be found at

Question by:majestic
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 2662663
Here is a sample I got from a friend.  Only clue as to the author is "black dog"  *shrug*

Enjoy!  :)


Expert Comment

ID: 2662664
oops!  I suppose the filename would help:

Author Comment

ID: 2662759
it seems to be a clearly written program but it does not use the CryptSignMessage function that i'm looking for.  Thanks any way.
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

LVL 28

Accepted Solution

AzraSound earned 100 total points
ID: 2662969
i cannot find documentation on it in VB either.  You may consider using several functions to achieve the effect of the CryptSignMessage function however from the functions listed here:

Expert Comment

ID: 2663023
See Also
  Windows NT/2000: Requires Windows NT 4.0 SP3 or later (or Windows NT 4.0 with Internet Explorer 3.02 or later).
  Windows 95/98: Requires Windows 98 (or Windows 95 with Internet Explorer 3.02 or later).
  Header: Declared in wincrypt.h.
  Import Library: Use crypt32.lib.
  Platform SDK: Cryptography
The CryptSignMessage function creates a hash of the specified content, signs the hash, and then encodes both the original message content and the signed hash.

BOOL WINAPI CryptSignMessage(
  BOOL fDetachedSignature,            // in
  DWORD cToBeSigned,                  // in
  const BYTE *rgpbToBeSigned[ ],      // in
  DWORD rgcbToBeSigned[ ],            // in
  BYTE *pbSignedBlob,                 // out
  DWORD *pcbSignedBlob                // in/out
Pointer to CRYPT_SIGN_MESSAGE_PARA structure containing the signature parameters.
TRUE if this is to be a detached signature. Otherwise it is set to FALSE. If this parameter is set to TRUE, only the signed hash is encoded in pbSignedBlob. Otherwise, both rgpbToBeSigned and the signed hash are encoded.
Count of the number of array elements in rgpbToBeSigned and rgcbToBeSigned. This parameter must be set to one unless fDetachedSignature is set to TRUE.
Array of pointers to buffers that contain the contents to be signed.
Array of sizes, in bytes, of the content buffers pointed to in rgpbToBeSigned.
Pointer to a buffer to receive the encoded signed hash, if fDetachedSignature is TRUE, or to both the encoded content and signed hash if fDetachedSignature is FALSE.
This parameter can be NULL to set the size of this information for memory allocation purposes. See Retrieving Data of Unknown Length.

Pointer to a DWORD specifying the size, in bytes, of the pbSignedBlob buffer. When the function returns, this variable contains the size, in bytes, of the signed and encoded message.
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.

Return Values
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.

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

This function has the following error codes.

Error code Description
ERROR_MORE_DATA  If the buffer specified by the pbSignedBlob 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 pcbSignedBlob.
E_INVALIDARG  Invalid message encoding type. Currently only PKCS_7_ASN_ENCODING is supported. Invalid cbSize in *pSignPara.
KEY_PROPERTY  The pSigningCert in *pSignPara does not have a CERT_KEY_PROV_INFO_PROP_ID or CERT_KEY_CONTEXT_PROP_ID property.
OSS_ERROR  Message ASN.1 encoding error. Note, to get the OSS error subtract CRYPT_E_OSS_ERROR from the returned error and see Asn1code.h for details on the error.

See Example C Program: Using CryptSignMessage.

  Windows NT/2000: Requires Windows NT 4.0 SP3 or later (or Windows NT 4.0 with Internet Explorer 3.02 or later).
  Windows 95/98: Requires Windows 98 (or Windows 95 with Internet Explorer 3.02 or later).
  Header: Declared in wincrypt.h.
  Import Library: Use crypt32.lib.

See Also

Built on Wednesday, May 12, 1999

Author Comment

ID: 2671733
I found the answer to my question on another link on this site.



Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question