Adds a string of ascii characters to the digest.
Public Declare Function SHA3_AddString Lib "diCryptoSys.dll" (ByVal hContext As Long, ByVal strMessage As String) As Long
nRet = SHA3_AddString(hContext, strMessage)
long _stdcall SHA3_AddString(long hContext, const char *szMessage);
If successful, the return value is 0; otherwise it returns a non-zero error code.
Sha3.AddData Method (String)
The handle to the context hContext must have been set up with a
prior call to SHA3_Init
. This function may be called many times before creating
the final message digest with SHA3_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 SHA3_AddBytes
.
This example computes the SHA-3-224 digest of one million repetitions of the character "a".
Dim nRet As Long Dim nBytes As Long Dim strDigest As String Dim hContext As Long Dim i As Long Dim sA1000 As String ' Set context handle hContext = SHA3_Init(224) 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 = SHA3_AddString(hContext, sA1000) Next ' Get required length of output string (NB 2 times number of bytes) nBytes = SHA3_LengthInBytes(hContext) strDigest = String(nBytes * 2, " ") nRet = SHA3_HexDigest(strDigest, Len(strDigest), hContext) Debug.Print strDigest
This should result in output as follows:
d69335b93325192e516a912e6d19a15cb51c6ed5c15243e7a7fd653c
SHA3_Init
SHA3_AddBytes
SHA3_HexDigest