The CryptSignHash function is used to sign a piece of data. Because all signature algorithms are asymmetric and thus incredibly slow, CryptoAPI will not let data be signed directly. Instead, you must first hash the data and then use CryptSignHash to sign the hash value.
Declare Function CryptSignHash Lib "advapi32.dll" Alias "CryptSignHashA" (ByVal hHash As Long, ByVal dwKeySpec As Long, ByVal sDescription As String, ByVal dwFlags As Long, ByVal pbSignature As String, pdwSigLen As Long) As Long
|Operating Systems Supported|
|Windows NT 4.0 or later; Windows 95 OSR2 or later (or Windows 95 with Internet Explorer 3.02 or later)|
[in] A handle to the hash object to be signed.
[in] The key pair to use to sign the hash. The following keys can be specified:
· AT_KEYEXCHANGE ¾ Exchange private key
· AT_SIGNATURE ¾ Signature private key
The signature algorithm used is specified when the key pair was originally created.
The only signature algorithm that the Microsoft RSA Base Provider supports is the RSA Public-Key algorithm.
[in] The string describing the data to sign. This description text is added to the hash object before the signature is generated. Whenever the signature is authenticated (with CryptVerifySignature), the exact same description string must be supplied. This ensures that both the signer and the authenticator agree on what is being signed or authenticated.
Some CSPs (not the Microsoft RSA Base Provider) will display this description string to the user. This lets the user confirm what he or she is signing. This protects the user from unscrupulous applications and also reduces misunderstandings.
This parameter can be NULL if no description string is to included in the signature. Usually, this is only the case when the signature is performed using a signature key that is not legally bound to the user. For example, when a signature operation is performed with the key exchange private key as part of a key exchange protocol, no description string is typically specified.
[in] The flag values. This parameter is reserved for future use and should always be zero.
[out] The buffer in which the function places the signature data.
This parameter can be NULL if all you are doing is determining the number of bytes required for the returned signature data.
[in/out] The address of the signature data length. Before calling this function, the caller should set this parameter to the length, in bytes, of the pbSignature buffer. Upon return, this address will contain the number of bytes in the signature data.
If the buffer specified by pbSignature is not large enough to hold the data, the function returns the ERROR_MORE_DATA error code (through GetLastError) and stores the required buffer size, in bytes, into the variable pointed to by pdwSigLen.
If pbSignature is NULL, then no error is returned and the function stores the size of the data, in bytes, in the variable pointed to by pdwSigLen.
|If the function succeeds, the return value is nonzero. |
If the function fails, the return value is zero. To retrieve extended error information, use the GetLastError function.
The following table lists the error codes most commonly returned by the GetLastError function. The error codes prefaced by “NTE” are generated by the particular CSP you are using.
One of the parameters specifies an invalid handle.
One of the parameters contains an invalid value. This is most often an illegal pointer.
The hHash handle specifies an algorithm that this CSP does not support.
The dwFlags parameter is nonzero.
The hash object specified by the hHash parameter is invalid.
The CSP context that was specified when the hash object was created cannot be found.
The private key specified by dwKeySpec does not exist.
The CSP ran out of memory during the operation.