Skip to content

Instantly share code, notes, and snippets.

@yovchev
Last active December 2, 2019 22:51
Show Gist options
  • Save yovchev/892675f96f04bc82c005160b92e4f899 to your computer and use it in GitHub Desktop.
Save yovchev/892675f96f04bc82c005160b92e4f899 to your computer and use it in GitHub Desktop.
Excel, Access VBA Function to create MD5 from text
Public Function MD5Hex(textString As String) As String
Dim enc
Dim textBytes() As Byte
Dim bytes
Dim oUTF8
Dim outstr As String
Set oUTF8 = CreateObject("System.Text.UTF8Encoding")
Set enc = CreateObject("System.Security.Cryptography.MD5CryptoServiceProvider")
textBytes = oUTF8.GetBytes_4(textString)
bytes = enc.ComputeHash_2((textBytes))
For pos = 1 To LenB(bytes)
outstr = outstr & LCase(Right("0" & Hex(AscB(MidB(bytes, pos, 1))), 2))
Next
MD5Hex = outstr
Set enc = Nothing
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment