User-defined formula (VBA) that can convert a text value into MD5

  • Thread starter Thread starter Beefminator
  • Start date Start date
Thank you for replying.

Am I using the correct user-defined VBA formula?
=GetMD5Hash(A1)

If so, then I am getting a weird output. I was expecting more of a text
output.
 
Do your results have 32 characters and do those characters consist of the 10
digits 0-9 and letters of the alphabet from a through f? If so, then it is
probably doing it right. The 32 character count is not an absolute, but
results usually contain that number of characters.
Wikipedia has a pretty good writeup about MD5.
http://en.wikipedia.org/wiki/MD5
 
No, the formula does not produce 32 characters; it is weird looking.
Here is my excel file; take a look at it.
http://www.walkhere.com/Vba_MD5.xls

I put the text word "test" as my text input, and I should get
"098f6bcd4621d373cade4e832627b4f6"

Thanks again for looking into this,
Jason
 
Well, that is rather interesting, isn't it?
I'm going to go back to ground zero and put together a workbook using the
same source that you did and see what I end up with. That will give us an
idea of whether that source code is messed up or whether you've just managed
to really hand it something it is totally unprepared to deal with.
 
Some further research shows that what you are getting is probably correct
given the method being used. See this page:
http://www.excelsig.org/VBA/wwHash.htm
So what (apparently, as I understand it) is happening is that a MD5 code is
being generated AND being encrypted. What you're seeing (and I saw on my
system also) is the encrypted results?

I'm going to nose around a bit more and see if there isn't an MD5 generator
available that doesn't encrypt the result.

Although maybe it is just enough to know that the algorigthm is working and
providing consistent results? If you just use the results internally then
you don't need to be concerned with their appearance to the user - only that
a given input will result in a consistent output?
 
I copied everything from Option Explicit to the bottom of the page. I used the "DigestStrToHexStr" as the user-defined function. Works good!.

Although the supplied code can be used as suggested by Beefminator, it is actually an exported Class Module. The part at the top is information about the module for the import to Visual Basic.

If you want to use it as the author intended, rather than just pasting the part from Option Explicit into a Standard Module, paste the whole content into a text file and change the extension to cls.

Then use the Import facility in VBA to create the clsMD5 Class Module from the text file. The Public functions in the module are then accessed as Methods of the object.
A simple example:

Dim objMD5 As clsMD5
Dim strInput As String
Dim strOutput As String

strInput = "the quick brown fox"

Set objMD5 = New clsMD5
strOutput = objMD5.DigestStrToHexStr(strInput)
Debug.Print strOutput

Set objMD5 = Nothing
 
Back
Top