SHARE
TWEET

MD5 Checksum

ba5tz Jun 25th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Private Function GetFileBytes(ByVal path As String) As Byte()
  2.     Dim lngFileNum As Long
  3.     Dim bytRtnVal() As Byte
  4.     lngFileNum = FreeFile
  5.     If LenB(Dir(path)) Then
  6.         Open path For Binary Access Read As lngFileNum
  7.         ReDim bytRtnVal(LOF(lngFileNum) - 1&) As Byte
  8.         Get lngFileNum, , bytRtnVal
  9.         Close lngFileNum
  10.     Else
  11.         Err.Raise 53
  12.     End If
  13.     GetFileBytes = bytRtnVal
  14.     Erase bytRtnVal
  15. End Function
  16.  
  17. Public Function FileToMD5Hex(sFileName As String) As String
  18.     Dim enc
  19.     Dim bytes
  20.     Dim outstr As String
  21.     Dim pos As Integer
  22.     Set enc = CreateObject("System.Security.Cryptography.MD5CryptoServiceProvider")
  23.     'Convert the string to a byte array and hash it
  24.     bytes = GetFileBytes(sFileName)
  25.     bytes = enc.ComputeHash_2((bytes))
  26.     'Convert the byte array to a hex string
  27.     For pos = 1 To LenB(bytes)
  28.         outstr = outstr & LCase(Right("0" & Hex(AscB(MidB(bytes, pos, 1))), 2))
  29.     Next
  30.     FileToMD5Hex = outstr
  31.     Set enc = Nothing
  32. End Function
  33.  
  34. 'test file
  35. Degub.print FileToMD5Hex("LokasiFIle)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top