CryptoSys API Library Manual

SHA3_AddBytes

Adds an array of bytes to the digest.

VBA/VB6 Syntax

Public Declare Function SHA3_AddBytes Lib "diCryptoSys.dll" (ByVal hContext As Long, ByRef lpData As Byte, ByVal nDataLen As Long) As Long

nRet = SHA3_AddBytes(hContext, abData(0), nDataLen)

C/C++ Syntax

long _stdcall SHA3_AddBytes(long hContext, const unsigned char *lpData, long nDataLen);

Parameters

hContext
[in] handle to the SHA-3 context.
lpData
[in] byte array containing the next part of the message to be hashed.
nDataLen
[in] number of bytes in the array

Returns (VBA/C)

If successful, the return value is 0; otherwise it returns a non-zero error code.

.NET Equivalent

Sha3.AddData Method (Byte[])

Remarks

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. SHA3_AddString may also be called.

Example

This example creates the SHA-3-256 hash of the three-character string "abc" using a mixture of calls to SHA3_AddBytes and SHA3_AddString.

Dim nRet As Long
Dim nBytes As Long
Dim strDigest As String
Dim hContext As Long
Dim abData(1) As Byte

' Set context handle
hContext = SHA3_Init(256)
' Check for an invalid handle
If hContext = 0 Then
  MsgBox "Failed to set context"
  Exit Function
End If

' Set up a test array of bytes
abData(0) = Asc("a")
abData(1) = &H62    ' same as Asc("b")
' Add mixture of bytes and strings to pass "abc"
nRet = SHA3_AddBytes(hContext, abData(0), 2)
nRet = SHA3_AddString(hContext, "c")

' 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:

3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532

See Also

SHA3_Init SHA3_AddString SHA3_HexDigest

[Contents] [Index]

[PREV: SHA2_StringHexHash...]   [Contents]   [Index]   
   [NEXT: SHA3_AddString...]

Copyright © 2001-24 D.I. Management Services Pty Ltd. All rights reserved. Generated 2024-01-07T07:42:00Z.