CryptoSys API Library Manual

SHA2_AddBytes

Adds an array of bytes to the digest.

VB6/VBA Syntax

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

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

Parameters

hContext
[in] Long handle to the SHA-1 context.
abData
[in] Byte array containing the next part of the message to be hashed.
nDataLen
[in] Long containing the number of bytes in the array

C/C++ Syntax

long _stdcall SHA2_AddBytes(long ctx_handle, const unsigned char *bytes, long len);

Returns (VB6/C)

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

.NET Equivalent

Sha256.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 SHA2_AddBytes and SHA2_AddString.

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

    ' Set context handle
    hContext = SHA2_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 = SHA2_AddBytes(hContext, abData(0), 2)
    nRet = SHA2_AddString(hContext, "c")

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

This should result in output as follows:

ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad

See Also

SHA2_Init SHA2_AddString SHA2_HexDigest SHA2_Reset

[Contents] [Index]

[HOME]   [NEXT: SHA2_AddString...]

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