CryptoSys API Library Manual

SHA2_AddString

Adds a string of ascii characters to the digest.

VBA/VB6 Syntax

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

nRet = SHA2_AddString(hContext, strMessage)

C/C++ Syntax

long __stdcall SHA2_AddString(long hContext, const char *szMessage);

Parameters

hContext
[in] handle to the SHA-2 context.
szMessage
[in] 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

Sha256.AddData Method (String)

Remarks

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.

Example

    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.

See Also

SHA2_Init SHA2_AddBytes SHA2_HexDigest SHA2_Reset

[Contents] [Index]

[PREV: SHA2_AddBytes...]   [Contents]   [Index]   
   [NEXT: SHA2_BytesHash...]

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