I’ve been looking for a Classic ASP script that allows me to hash a string using the MD5 algorithm. I need to match this hashed string against the same string in an ASP.NET Page, hashed using .NET’s MD5 hashing algorithms.
Even though I have found several scripts for Classic ASP that generate the hash, I haven’t found one that generates the correct hash using non-English characters (like ñ, for example).
Do you know some Classic ASP script that works in this particular case?
Note:
I have tried these scripts:
http://userpages.umbc.edu/~mabzug1/cs/md5/md5.asp
http://forums.aspfree.com/code-bank-54/asp-classic-md5-hash-82164.html
Examples:
String:
muñeca
Correct MD5 Hash:
ea07bec1f37f4b56ebe368355d1c058f
Generated Hash:
298e60cb1179df15d5772726a3975132
The first part of hashing any string is getting a byte array of the string’s characters. The byte array created depends on the encoding type used for the string. .Net strings are encoded in UTF-16. I don’t recall vbscript’s encoding type off the type of my head, but it’s probably just ascii or at best UTF-8.
Therefore, to fix your problem, the first thing you need to do is get vbscript to give you a byte array that represents the UTF-16 characters in your string. Then go look for an md5 hash function that expects a byte array directly, instead of a string type.
Unfortunately, even this may not be enough. It’s possible that vbscript’s lack of native UTF-16 could result in what is normally a minor loss of fidelity in the string input from the user, such that the string in your Classic ASP code is no longer exactly the same characters as the string in your ASP.Net code. If this is the case, the only solution is to change your ASP.Net code to match the Classic ASP encoding, rather than vice versa. This may be the much easier solution anyway. For this to work, you will need to know exactly what character encoding your vbscript code is using. Again, I don’t have that information in my head anymore, so you can google it as well as I.