Creates a cryptographic hash digest in hex format from a file.
VB6/VBA
Debug.Print "Testing HASH_HexFromFile ..." Dim nRet As Long Dim sDigest As String Dim sFileName As String ' File to be hashed contains a total of 13 bytes: "hello world" plus CR-LF ' 68 65 6c 6c 6f 20 77 6f 72 6c 64 0d 0a hello world.. sFileName = "hello.txt" ' Pre-dimension digest string sDigest = String(PKI_MAX_HASH_CHARS, " ") ' Create default hash (SHA1) in binary mode nRet = HASH_HexFromFile(sDigest, Len(sDigest), sFileName, 0) Debug.Print nRet, Left(sDigest, nRet) ' Use SHA1 in "text" mode nRet = HASH_HexFromFile(sDigest, Len(sDigest), sFileName, PKI_HASH_MODE_TEXT) Debug.Print nRet, Left(sDigest, nRet) ' Use MD5 nRet = HASH_HexFromFile(sDigest, Len(sDigest), sFileName, PKI_HASH_MD5) Debug.Print nRet, Left(sDigest, nRet) ' Use MD5 in "text" mode nRet = HASH_HexFromFile(sDigest, Len(sDigest), sFileName, PKI_HASH_MD5 Or PKI_HASH_MODE_TEXT) Debug.Print nRet, Left(sDigest, nRet)
Output
Testing HASH_HexFromFile ... 40 88a5b867c3d110207786e66523cd1e4a484da697 40 22596363b3de40b06f981fb85d82312e8c0ed511 32 a0f2a3c1dcd5b1cac71bf0c03f2ff1bd 32 6f5902ac237024bdd0c176cb93063dc4
VB.NET
Console.WriteLine("Testing HASH_HexFromFile ...")
Dim sDigest As String
Dim sFileName As String
' File to be hashed contains a total of 13 bytes: "hello world" plus CR-LF
' 68 65 6c 6c 6f 20 77 6f 72 6c 64 0d 0a hello world..
sFileName = "hello.txt"
' Create default hash (SHA1) in binary mode
sDigest = Hash.HexFromFile(sFileName, HashAlgorithm.Sha1)
Console.WriteLine(sDigest.Length & " " & sDigest)
' Use SHA1 in "text" mode
sDigest = Hash.HexFromTextFile(sFileName, HashAlgorithm.Sha1)
Console.WriteLine(sDigest.Length & " " & sDigest)
' Use MD5
sDigest = Hash.HexFromFile(sFileName, HashAlgorithm.Md5)
Console.WriteLine(sDigest.Length & " " & sDigest)
' Use MD5 in "text" mode
sDigest = Hash.HexFromTextFile(sFileName, HashAlgorithm.Md5)
Console.WriteLine(sDigest.Length & " " & sDigest)
[Contents]