CryptoSys API Library Manual

SHA1_FileHexHash

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

VBA/VB6 Syntax

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

nRet = SHA1_FileHexHash(strDigest, strFileName, strMode)

C/C++ Syntax

long __stdcall SHA1_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

Sha1.FileHexHash Method
Sha1.FileTextHexHash Method

COM/ASP Equivalent

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

See sha1.FileHexHash, sha1.FileTextHexHash.

Remarks

szDigest must be at least 40 (API_MAX_SHA1_CHARS) characters long (41 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 40 chars
    strDigest = String(40, " ")
    ' Make sha1sum in text mode (treating CR-LF as single NL)
    nRet = SHA1_FileHexHash(strDigest, strFileName, "t")
    Debug.Print "t " & nRet; strDigest
    ' Do in binary mode (treating CR-LF as two binary bytes)
    nRet = SHA1_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 22596363b3de40b06f981fb85d82312e8c0ed511
b  0 88a5b867c3d110207786e66523cd1e4a484da697

See Also

SHA1_StringHexHash SHA1_BytesHexHash

[Contents] [Index]

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

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