Creates a SHA-1 message digest in hexadecimal format from a file.
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)
long __stdcall SHA1_FileHexHash(char *szDigest, const char *szFileName, const char *szMode);
If successful, the return value is 0; otherwise it returns a non-zero error code.
Sha1.FileHexHash Method
Sha1.FileTextHexHash Method
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.
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).
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
SHA1_StringHexHash
SHA1_BytesHexHash