The CryptDecrypt function is used to decrypt data that was previously encrypted via the CryptEncrypt function.
Declare Function CryptDecrypt Lib "advapi32.dll" (ByVal hKey As Long, ByVal hHash As Long, ByVal Final As Long, ByVal dwFlags As Long, ByVal pbData As String, pdwDataLen 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 key to use for the decryption. An application obtains this handle by using either the CryptGenKey or CryptImportKey function.
This key specifies the decryption algorithm that is used.
[in] A handle to a hash object. This parameter is only used if a hash of the data is to be computed. See the “Remarks” section for more information.
If no hash is to be done, this parameter must be zero.
[in] The Boolean value that specifies whether this is the last section in a series being decrypted. This will be TRUE if this is the last or only block. If it is not, then it will be FALSE. See the “Remarks” section for more information.
[in] The flag values. This parameter is reserved for future use and should always be zero.
[in/out] The buffer holding the data to be decrypted. Once that decryption has been performed, the plaintext is placed back in this same buffer.
The number of encrypted bytes in this buffer is specified by pdwDataLen.
[in/out] The address of the data length. Before calling this function, the caller should set this parameter to the number of bytes to be decrypted. Upon return, this address will contain the number of bytes of plaintext generated.
When a block cipher is used, this data length must be a multiple of the block size, unless this is the final section of data to be decrypted and the Final flag is TRUE.
|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 hKey session key specifies an algorithm that this CSP does not support.
The data to be decrypted is invalid. For example, when a block cipher is used and the Final flag FALSE, the value specified by pdwDataLen must be a multiple of the block size. This error can also be returned when the padding is found to be invalid.
The dwFlags parameter is nonzero.
The hHash parameter contains an invalid handle.
The hKey parameter does not contain a valid handle to a key.
The size of the output buffer is too small to hold the generated plaintext.
The CSP context that was specified when the key was created cannot be found.
The application attempted to decrypt the same data twice.
The function failed in some unexpected way.