CryptoSys API Library Manual

SHA1_AddString

Adds a string of ascii characters to the digest.

VBA/VB6 Syntax

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

nRet = SHA1_AddString(hContext, strMessage)

C/C++ Syntax

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

Parameters

hContext
[in] handle to the SHA-1 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

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

    ' Set context handle
    hContext = SHA1_Init()

    Debug.Print "SHA1_Init() returns handle = " & Hex(hContext)
    ' Remember to check for an invalid handle
    If hContext = 0 Then
        MsgBox "Failed to set context"
        Exit Function
    End If

    ' Add strings one by one
    nRet = SHA1_AddString(hContext, "a")
    nRet = SHA1_AddString(hContext, "bc")

    ' Set strDigest to be 40 chars
    strDigest = String(40, " ")
    nRet = SHA1_HexDigest(strDigest, hContext)
    Debug.Print strDigest

This should result in output as follows:

SHA1_Init() returns handle = 10029CB0
a9993e364706816aba3e25717850c26c9cd0d89d

Note that the actual value of the handle is not important, just that it should not be zero.

See Also

SHA1_Init SHA1_AddBytes SHA1_HexDigest SHA1_Reset

[Contents] [Index]

[PREV: SHA1_AddBytes...]   [Contents]   [Index]   
   [NEXT: SHA1_BytesHash...]

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