Creates a message digest hash as a byte array from byte data. The hash algorithm to use is passed in the options parameter.
nRet = HASH_Bytes(abDigest(0), nDigLen, abMessage(0), nMsgLen, nOptions)
Byte array to receive the hash digest.Long specifying the length in bytes of the output array.Byte array containing the message dataLong specifying length of the message data in bytes.Long Option flags. Select one of:
long _stdcall HASH_Bytes(unsigned char *digest, long digLen, const void *aMessage, long messageLen, long flags);
Long: If successful, the return value is the number of bytes in the hash digest array;
otherwise it returns a negative error code.
Specify a zero nDigLen parameter to find out the required length of the output array.
The maximum possible length is PKI_MAX_HASH_BYTES.
Hint: SHA-1 requires 20 bytes; MD5 and MD2 require 16 bytes; SHA-512 requires 64.
The final digest will be truncated to the specified length if less than the expected size.
VB6/VBA users: Note the '(0)' after the byte array parameters.
Dim nRet As Long
Dim abDigest() As Byte
Dim abMessage() As Byte
Dim nMsgLen As Long
' Set up message to be hashed
abMessage = StrConv("abc", vbFromUnicode)
nMsgLen = UBound(abMessage) + 1
' Pre-dimension digest array (NB zero-based so subtract one)
ReDim abDigest(PKI_MAX_HASH_BYTES - 1)
' Create default hash (SHA1)
nRet = HASH_Bytes(abDigest(0), PKI_MAX_HASH_BYTES, abMessage(0), nMsgLen, 0)
If nRet > 0 Then ReDim Preserve abDigest(nRet - 1)
Debug.Print nRet, cnvHexStrFromBytes(abDigest)
' Repeat for MD5
ReDim abDigest(PKI_MAX_HASH_BYTES - 1)
nRet = HASH_Bytes(abDigest(0), PKI_MAX_HASH_BYTES, abMessage(0), nMsgLen, PKI_HASH_MD5)
If nRet > 0 Then ReDim Preserve abDigest(nRet - 1)
Debug.Print nRet, cnvHexStrFromBytes(abDigest)
The above example should produce the following output:
20 A9993E364706816ABA3E25717850C26C9CD0D89D 16 900150983CD24FB0D6963F7D28E17F72