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