CryptoSys API Library Manual

SHA2_AddString

Adds a string of ascii characters to the digest.

VB6/VBA Syntax

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

nRet = SHA2_AddString(hContext, strMessage)

Parameters

hContext
[in] Long handle to the SHA-1 context.
strMessage
[in] String containing the next part of the message to be hashed.

C/C++ Syntax

long _stdcall SHA2_AddString(long ctx_handle, const char *strMessage);

Returns (VB6/C)

Long: 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 SHA1_Init. This function may be called many times before creating the final message digest with SHA1_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]

[HOME]   [NEXT: SHA2_BytesHash...]

Copyright © 2001-11 D.I. Management Services Pty Ltd. All rights reserved.