CryptoSys API Library Manual

MD5_FileHexHash

Creates an MD5 message digest in hexadecimal format from a file.

VB6/VBA Syntax

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

nRet = MD5_FileHexHash(strDigest, strFileName, strMode)

Parameters

strDigest
[out] String to receive message digest.
strFileName
[in] String with full path name of file.
strMode
[in] String to set mode: "t" or "b"

C/C++ Syntax

long _stdcall MD5_FileHexHash(char *strDigest, const char *strFileName, const char *strMode);

Returns (VB6/C)

Long: If successful, the return value is 0; otherwise it returns a non-zero error code.

.NET Equivalent

Md5.FileHexHash Method
Md5.FileTextHexHash Method

COM/ASP Equivalent

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

See md5.FileHexHash, md5.FileTextHexHash.

Remarks

strDigest must be at least 32 (API_MAX_MD5_CHARS) characters long (33 in a C program). Setting strMode equal to "t" or "T" will hash file in "text" mode treating a CR-LF pair as a single newline character. Setting strMode 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 32 chars
    strDigest = String(32, " ")
    ' Make md5sum in text mode (treating CR-LF as single NL)
    nRet = MD5_FileHexHash(strDigest, strFileName, "t")
    Debug.Print "t "; nRet; strDigest
    ' Do in binary mode (treating CR-LF as two binary bytes)
    nRet = MD5_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 6f5902ac237024bdd0c176cb93063dc4
b  0 a0f2a3c1dcd5b1cac71bf0c03f2ff1bd

See Also

MD5_StringHexHash MD5_BytesHexHash

[Contents] [Index]

[HOME]   [NEXT: MD5_HexDigest...]

Copyright © 2001-11 D.I. Management Services Pty Ltd. All rights reserved.