最近使用Microsoft CryptoAPI的过程中,发现了其中两个函数的一些问题,做此笔记。
BOOL WINAPI CryptEncrypt(
HCRYPTKEY hKey,
HCRYPTHASH hHash,
BOOL Final,
DWORD dwFlags,
BYTE* pbData,
DWORD* pdwDataLen,
DWORD dwBufLen
);需要注意其中的三个参数:一、BOOL FinalFinal [in] Boolean value that specifies whether this is the last section in a series being encrypted. Final is set to TRUE for the last or only block and to FALSE if there are more blocks to be encrypted. For more information, see Remarks.说的比较清楚,若只有一个分组的数据需要加密或者为最后一个分组,则Final为TRUE。
二、DWORD* pdwDataLen
pdwDataLen
[in, out] Pointer to a DWORD value that contains the length of the data buffer. Upon input, the DWORD value is set to the number of bytes to be encrypted. Upon return, the DWORD value contains the number of bytes needed to hold the encrypted data.
在输入时,pdwDataLen为需要加密的分组长度,如使用DES对64位数据进行加密,那么输入时
pdwDataLen为8;在输