CryptoSys API Library Manual

SHA1_AddBytes

Adds an array of bytes to the digest.

VBA/VB6 Syntax

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

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

C/C++ Syntax

long __stdcall SHA1_AddBytes(long hContext, const unsigned char *lpData, long nDataLen);

Parameters

hContext
[in] handle to the SHA-1 context.
lpData
[in] array containing the next part of the message to be hashed.
nDataLen
[in] containing the 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

Sha1.AddData Method (Byte[])

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

Example

This example creates the hash of the three-character string "abc" using a mixture of calls to SHA1_AddBytes and SHA1_AddString.

    Dim nRet As Long
    Dim strDigest As String
    Dim hContext As Long
    Dim abData(2) As Byte

    ' Set context handle
    hContext = SHA1_Init()
    ' Remember to 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
    nRet = SHA1_AddBytes(hContext, abData(0), 2)
    nRet = SHA1_AddString(hContext, "c")

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

This should result in output as follows:

a9993e364706816aba3e25717850c26c9cd0d89d

See Also

SHA1_Init SHA1_AddString SHA1_HexDigest SHA1_Reset

[Contents] [Index]

[PREV: RNG_UpdateSeedFile...]   [Contents]   [Index]   
   [NEXT: SHA1_AddString...]

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