CryptoSys API Library Manual

SHA1_BytesHash

Creates a SHA-1 message digest in Byte array format from a message in Byte array format.

VBA/VB6 Syntax

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

nRet = SHA1_BytesHash(abDigest(0), abData(0), nDataLen) ' Note the "(0)" after the byte array parameters

C/C++ Syntax

long __stdcall SHA1_BytesHash(unsigned char *digest, const unsigned char *lpData, long nDataLen);

Parameters

digest
[out] array to receive message digest.
lpData
[in] array containing the message to be hashed.
nDataLen
[in] containing 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.BytesHash Method

Remarks

This function differs from other SHA1 functions in that it creates a digest in Byte array format. This is particularly useful when you need to carry out repeated hash operations. lpDigest must be at least 20 (API_MAX_SHA1_BYTES)bytes long.

Examples

    Dim nRet As Long
    Dim abData(2) As Byte   ' Create 3-byte array (NB zero-based)
    Dim abDigest(19) As Byte ' Create 20-byte array to receive digest
    
    ' Setup byte array with "abc"
    abData(0) = Asc("a")
    abData(1) = Asc("b")
    abData(2) = Asc("c")
    
    ' Compute SHA-1 hash digest
    nRet = SHA1_BytesHash(abDigest(0), abData(0), 3)
    
    ' Print resulting bytes in hex format
    Debug.Print nRet; cnvHexStrFromBytes(abDigest)

This should result in output as follows:

 0 A9993E364706816ABA3E25717850C26C9CD0D89D

This second example shows how to carry out repeated hashes of the digest.

    Dim nRet As Long
    Dim abData(2) As Byte   ' Create 3-byte array (NB zero-based)
    Dim abDigest(19) As Byte ' Create 20-byte array to receive digest
    Dim i As Integer
    
    ' Setup byte array with "abc"
    abData(0) = Asc("a")
    abData(1) = Asc("b")
    abData(2) = Asc("c")
    
    ' Compute SHA-1 hash digest of input
    nRet = SHA1_BytesHash(abDigest(0), abData(0), 3)
    
    ' Now carry out repeated hashes of the digest
    For i = 2 To 1000
        nRet = SHA1_BytesHash(abDigest(0), abDigest(0), 20)
    Next
   
    ' Print H(1000) in hex format
    Debug.Print cnvHexStrFromBytes(abDigest)

This should result in output as follows:

 58EEDCE24AD638F2ABF39E4B13D5726802DEF2C1

See Also

SHA1_BytesHexHash PBE_Kdf2

[Contents] [Index]

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

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