CryptoSys API Library Manual

SHA3_AddString

Adds a string of ascii characters to the digest.

VBA/VB6 Syntax

Public Declare Function SHA3_AddString Lib "diCryptoSys.dll" (ByVal hContext As Long, ByVal strMessage As String) As Long

nRet = SHA3_AddString(hContext, strMessage)

C/C++ Syntax

long _stdcall SHA3_AddString(long hContext, const char *szMessage);

Parameters

hContext
[in] handle to the SHA-3 context.
szMessage
[in] string containing the next part of the message to be hashed.

Returns (VBA/C)

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

.NET Equivalent

Sha3.AddData Method (String)

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 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.

Example

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

See Also

SHA3_Init SHA3_AddBytes SHA3_HexDigest

[Contents] [Index]

[PREV: SHA3_AddBytes...]   [Contents]   [Index]   
   [NEXT: SHA3_HexDigest...]

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