MD5_BytesHash creates an MD5 message digest in Byte array format
from a message in Byte array format.
Public Declare Function MD5_BytesHash Lib "diCryptoSys.dll"
(ByRef abDigest As Byte, ByRef abData As Byte, ByVal nDataLen As Long) As Long
nRet = MD5_BytesHash(abDigest(0), abData(0), nDataLen)
long _stdcall MD5_BytesHash(unsigned char *digest, const unsigned char *bytes, long len);
Long: If successful, the return value is 0;
otherwise it returns a non-zero error code.
Byte array to receive message digest.Byte array containing the message to be hashed.Long containing number of bytes in the array.
This function differs from other MD5 functions in that it creates a digest in Byte array
format. This is particularly useful when you need to carry out repeated hash operations.
abDigest must be at least 16 (API_MAX_MD5_BYTES) bytes long.
Note the (0) in abDigest(0) and abData(0).
Dim nRet As Long
Dim abData(2) As Byte ' Create 3-byte array (NB zero-based)
Dim abDigest(15) As Byte ' Create 16-byte array to receive digest
' Setup byte array with "abc"
abData(0) = Asc("a")
abData(1) = Asc("b")
abData(2) = Asc("c")
' Compute MD5 hash digest
nRet = MD5_BytesHash(abDigest(0), abData(0), 3)
' Print resulting bytes in hex format
Debug.Print nRet; cnvHexStrFromBytes(abDigest)
This should result in output as follows:
0 900150983CD24FB0D6963F7D28E17F72
This second example shows how to carry out repeated hashes of the digest.
Dim nRet As Long
Dim abData(2) As Byte ' Create 3-byte array (NB zero-based)
Dim abDigest(15) As Byte ' Create 16-byte array to receive digest
Dim i As Integer
' Setup byte array with "abc"
abData(0) = Asc("a")
abData(1) = Asc("b")
abData(2) = Asc("c")
' Compute MD5 hash digest of input
nRet = MD5_BytesHash(abDigest(0), abData(0), 3)
' Now carry out repeated hashes of the 16-byte-long digest
For i = 2 To 1000
nRet = MD5_BytesHash(abDigest(0), abDigest(0), 16)
Next
' Print H(1000) in hex format
Debug.Print cnvHexStrFromBytes(abDigest)
This should result in output as follows:
1375514E02C36AAE265B2FE20CCADAFB