Adds a string of ascii characters to the digest.
Public Declare Function MD5_AddString Lib "diCryptoSys.dll"
(ByVal hContext As Long, ByVal strMessage As String) As Long
nRet = MD5_AddString(hContext, strMessage)
long __stdcall MD5_AddString(long hContext, const char *szMessage);
If successful, the return value is 0; otherwise it returns a non-zero error code.
Md5.AddData Method (String)
The handle to the context hContext must have been set up with a
prior call to MD5_Init
. This function may be called many times before creating
the final message digest with MD5_HexDigest
This function should only be used to hash "printable" strings.
To hash a string that contains binary characters, such as ascii zero, use MD5_AddBytes
.
Dim nRet As Long Dim strDigest As String Dim hContext As Long Dim i As Long Dim sA1000 As String ' Set context handle hContext = MD5_Init() If hContext = 0 Then MsgBox "Failed to set context" Exit Function End If ' Create a string of 1000 'a's sA1000 = String(1000, "a") ' Add 1000 times => one million repetitions of "a" For i = 1 To 1000 nRet = MD5_AddString(hContext, sA1000) Next ' Set strDigest to be 32 chars - don't forget!! strDigest = String(32, " ") nRet = MD5_HexDigest(strDigest, hContext) Debug.Print strDigest
This should result in output as follows:
7707d6ae4e027c70eea2a935c2296f21
Note that the actual value of the handle is not important, just that it should not be zero.
MD5_Init
MD5_AddBytes
MD5_HexDigest
MD5_Reset