CryptoSys API Library Manual

HASH_Bytes

Creates a message digest hash as a byte array from byte data. The hash algorithm to use is passed in the options parameter.

VB6/VBA Syntax

Public Declare Function HASH_Bytes Lib "diCryptoSys.dll" (ByRef abDigest As Byte, ByVal nDigLen As Long, ByRef abMessage As Byte, ByVal nMsgLen As Long, ByVal nOptions As Long) As Long

nRet = HASH_Bytes(abDigest(0), nDigLen, abMessage(0), nMsgLen, nOptions)

Parameters

abDigest
[out] Byte array to receive the hash digest.
nDigLen
[in] Long specifying the length in bytes of the output array.
abMessage
[in] Byte array containing the message data
nMsgLen
[in] Long specifying length of the message data in bytes.
nOptions
[in] Long Option flags. Select one of:
API_HASH_SHA1 (0) to use the SHA-1 algorithm (default)
API_HASH_MD5 to use the MD5 algorithm
API_HASH_MD2 to use the MD2 algorithm
API_HASH_RMD160 to use the RIPEMD-160 algorithm
API_HASH_SHA224 to use the SHA-224 algorithm
API_HASH_SHA256 to use the SHA-256 algorithm
API_HASH_SHA384 to use the SHA-384 algorithm
API_HASH_SHA512 to use the SHA-512 algorithm

C/C++ Syntax

long _stdcall HASH_Bytes(unsigned char *digest, long digLen, const void *aMessage, long messageLen, long flags);

Returns (VB6/C)

Long: If successful, the return value is the number of bytes in the hash digest array; otherwise it returns a negative error code.

.NET Equivalent

Hash.BytesFromBytes Method

Remarks

Specify a zero nDigLen parameter to find out the required length of the output array. The maximum possible length is API_MAX_HASH_BYTES. Hint: SHA-1 requires 20 bytes; MD5 and MD2 require 16 bytes; SHA-512 requires 64. The final digest will be truncated to the specified length if less than the expected size. VB6 users should note the "(0)" after the byte array parameters.

Example

    Dim nRet As Long
    Dim abDigest() As Byte
    Dim abMessage() As Byte
    Dim nMsgLen As Long
    ' Set up message to be hashed
    abMessage = StrConv("abc", vbFromUnicode)
    nMsgLen = UBound(abMessage) + 1
    ' Pre-dimension digest array (NB zero-based so subtract one)
    ReDim abDigest(API_MAX_HASH_BYTES - 1)
    ' Create default hash (SHA1)
    nRet = HASH_Bytes(abDigest(0), API_MAX_HASH_BYTES, abMessage(0), nMsgLen, 0)
    If nRet > 0 Then ReDim Preserve abDigest(nRet - 1)
    Debug.Print nRet, cnvHexStrFromBytes(abDigest)
    
    ' Repeat for MD5
    ReDim abDigest(API_MAX_HASH_BYTES - 1)
    nRet = HASH_Bytes(abDigest(0), API_MAX_HASH_BYTES, abMessage(0), nMsgLen, API_HASH_MD5)
    If nRet > 0 Then ReDim Preserve abDigest(nRet - 1)
    Debug.Print nRet, cnvHexStrFromBytes(abDigest)

The above example should produce the following output:

 20           A9993E364706816ABA3E25717850C26C9CD0D89D
 16           900150983CD24FB0D6963F7D28E17F72

See Also

HASH_HexFromBytes HASH_HexFromHex

[Contents] [Index]

[HOME]   [NEXT: HASH_File...]

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