Adds an array of bytes to be digested in the HASH context.
Public Declare Function HASH_AddBytes Lib "diCryptoSys.dll" (ByVal hContext As Long, ByRef lpData As Byte, ByVal nDataLen As Long) As Long
nRet = HASH_AddBytes(hContext, abData(0), nDataLen)
long __stdcall HASH_AddBytes(long hContext, const void *lpData, long nDataLen);
If successful, the return value is 0; otherwise it returns a non-zero error code.
Public Function hashAddBytes
(hContext As Long, lpData() As Byte) As Long
Public Function hashAddString(hContext As Long, szData As String) As Long
Hash.AddData Method (Byte[])
Hash.AddData Method (String)
int crsysapi::Hash::AddData (bvec_t data)
int crsysapi::Hash::AddData (std::string s)
The handle hContext to the context must have been set up with a
prior call to HASH_Init
.
The HASH_AddBytes
function may be called many times before creating
the final message digest with HASH_Final
.
VBA users can use the more convenient wrapper functions hashAddBytes
and hashAddString
.
Dim hContext As Long Dim r As Long Dim nBytes As Long Dim lpMessage1() As Byte Dim lpMessage2() As Byte Dim lpDigest() As Byte hContext = HASH_Init(API_HASH_SHA1) Debug.Print "HASH_Init returns 0x" & Hex(hContext) ' Check for an invalid handle If hContext = 0 Then MsgBox "Failed to set context" Exit Sub End If ' Create two arrays of bytes to digest (long way!) ReDim lpMessage1(0) ' 1 bytes long lpMessage1(0) = &H61 ' ASCII 'a' ReDim lpMessage2(1) ' 2 bytes long lpMessage2(0) = &H62 ' ASCII 'b' lpMessage2(1) = &H63 ' ASCII 'c' ' Add data in parts (the string "abc") r = HASH_AddBytes(hContext, lpMessage1(0), 1) r = HASH_AddBytes(hContext, lpMessage2(0), 2) nBytes = HASH_DigestLength(hContext) Debug.Print "HASH_DigestLength=" & nBytes ReDim lpDigest(nBytes - 1) nBytes = HASH_Final(lpDigest(0), nBytes, hContext) Debug.Print "DIG=" & cnvHexStrFromBytes(lpDigest) Debug.Print "OK= " & "A9993E364706816ABA3E25717850C26C9CD0D89D"
Dim hContext As Long Dim lpDigest() As Byte ' Initialize context to use SHA-3-256 (NB HASH_ func) hContext = hashInit(API_HASH_SHA3_256) Debug.Print "hashInit returns 0x" & Hex(hContext) ' Check for an invalid handle If hContext = 0 Then MsgBox "Failed to set context" Exit Sub End If ' Add "abc" in parts Call hashAddBytes(hContext, cnvBytesFromHexStr("61")) ' ASCII "a" Call hashAddString(hContext, "") ' Empty string => No effect Call hashAddBytes(hContext, cnvBytesFromHexStr("")) ' Empty byte array => No effect Call hashAddString(hContext, "bc") ' Add a string directly ' Get final digest value lpDigest = hashFinal(hContext) Debug.Print "DIG=" & cnvHexStrFromBytes(lpDigest) Debug.Print "OK= " & "3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532"