Adds a string of ascii characters to the digest.
Public Declare Function SHA2_AddString Lib "diCryptoSys.dll"
(ByVal hContext As Long, ByVal strMessage As String) As Long
nRet = SHA2_AddString(hContext, strMessage)
long __stdcall SHA2_AddString(long hContext, const char *szMessage);
If successful, the return value is 0; otherwise it returns a non-zero error code.
Sha256.AddData Method (String)
The handle to the context hContext must have been set up with a
prior call to SHA2_Init. This function may be called many times before creating
the final message digest with SHA2_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
Dim i As Long
Dim sA1000 As String
' Set context handle
hContext = SHA2_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 = SHA2_AddString(hContext, sA1000)
Next
' Set strDigest to be 64 chars - don't forget!!
strDigest = String(64, " ")
nRet = SHA2_HexDigest(strDigest, hContext)
Debug.Print strDigest
This should result in output as follows:
cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0
Note that the actual value of the handle is not important, just that it should not be zero.
SHA2_Init
SHA2_AddBytes
SHA2_HexDigest
SHA2_Reset