Adds a string of ascii characters to the digest.
Public Declare Function SHA1_AddString Lib "diCryptoSys.dll"
(ByVal hContext As Long, ByVal strMessage As String) As Long
nRet = SHA1_AddString(hContext, strMessage)
long __stdcall SHA1_AddString(long hContext, const char *szMessage);
If successful, the return value is 0; otherwise it returns a non-zero error code.
Sha1.AddData Method (String)
The handle to the context hContext must have been set up with a
prior call to SHA1_Init. This function may be called many times before creating
the final message digest with SHA1_HexDigest
This function should only be used to hash strings of "printable" ANSI characters.
To hash a string that contains binary characters, such as ascii zero, use SHA1_AddBytes.
Dim nRet As Long
Dim strDigest As String
Dim hContext As Long
' Set context handle
hContext = SHA1_Init()
Debug.Print "SHA1_Init() returns handle = " & Hex(hContext)
' Remember to check for an invalid handle
If hContext = 0 Then
MsgBox "Failed to set context"
Exit Function
End If
' Add strings one by one
nRet = SHA1_AddString(hContext, "a")
nRet = SHA1_AddString(hContext, "bc")
' Set strDigest to be 40 chars
strDigest = String(40, " ")
nRet = SHA1_HexDigest(strDigest, hContext)
Debug.Print strDigest
This should result in output as follows:
SHA1_Init() returns handle = 10029CB0 a9993e364706816aba3e25717850c26c9cd0d89d
Note that the actual value of the handle is not important, just that it should not be zero.
SHA1_Init
SHA1_AddBytes
SHA1_HexDigest
SHA1_Reset