CryptoSys API Library Manual

SHA2_FileHexHash

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

VBA/VB6 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)

C/C++ Syntax

long __stdcall SHA2_FileHexHash(char *szDigest, const char *szFileName, const char *szMode);

Parameters

szDigest
[out] to receive message digest.
szFileName
[in] with full path name of file.
szMode
[in] to set mode: "t" or "b"

Returns (VBA/C)

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

szDigest must be at least 64 (API_MAX_SHA2_CHARS) characters long (65 in a C program). Setting szMode equal to "t" or "T" will hash file in "text" mode treating a CR-LF pair as a single newline character. Setting szMode 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]

[PREV: SHA2_BytesHexHash...]   [Contents]   [Index]   
   [NEXT: SHA2_HexDigest...]

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