CryptoSys API Library Manual

SHA2_FileHexHash

Creates a SHA-256 message digest in hexadecimal format from a file.

VB6/VBA Syntax

Public Declare Function SHA2_FileHexHash Lib "diCryptoSys.dll" (ByVal strDigest As String, ByVal strFileName As String, ByVal strMode As String) As Long

nRet = SHA2_FileHexHash(strDigest, strFileName, strMode)

Parameters

strDigest
[out] String to receive message digest.
strFileName
[in] String with full path name of file.
strMode
[in] String to set mode: "t" or "b"

C/C++ Syntax

long _stdcall SHA2_FileHexHash(char *strDigest, const char *strFileName, const char *strMode);

Returns (VB6/C)

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

.NET Equivalent

Sha256.FileHexHash Method
Sha256.FileTextHexHash Method

COM/ASP Equivalent

sha256.FileHexHash
Public Function FileHexHash(ByVal strFileName As String) As String
sha256.FileTextHexHash
Public Function FileHexHash(ByVal strFileName As String) As String

See sha256.FileHexHash, sha256.FileTextHexHash.

Remarks

strDigest must be at least 64 (API_MAX_SHA2_CHARS) characters long (65 in a C program). Setting strMode equal to "t" or "T" will hash file in "text" mode treating a CR-LF pair as a single newline character. Setting strMode equal to "b" or "B" will hash file in "binary" mode treating CR-LF as two binary characters (default).

Example

    Dim nRet As Long
    Dim strDigest As String
    Dim strFileName As String

    strFileName = "hello.txt"
    ' Set strDigest to be 64 chars
    strDigest = String(64, " ")
    ' Make sha1sum in text mode (treating CR-LF as single NL)
    nRet = SHA2_FileHexHash(strDigest, strFileName, "t")
    Debug.Print "t "; nRet; strDigest
    ' Do in binary mode (treating CR-LF as two binary bytes)
    nRet = SHA2_FileHexHash(strDigest, strFileName, "b")
    Debug.Print "b "; nRet; strDigest

For a 13-byte text file "hello.txt" in the default directory containing the 11 characters "hello world" followed by CR-LF this should result in output as follows:

t  0 a948904f2f0f479b8f8197694b30184b0d2ed1c1cd2a1ec0fb85d299a192a447
b  0 572a95fee9c0f320030789e4883707affe12482fbb1ea04b3ea8267c87a890fb

See Also

SHA2_StringHexHash SHA2_BytesHexHash

[Contents] [Index]

[HOME]   [NEXT: SHA2_HexDigest...]

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