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

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.
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA error replacing data 6 39
Updates not working for MS Windows 7 12 164
Visual Studio 2005 text editor 10 38
Problem to With line 4 56
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

816 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now