Matching MD5 hashes in ASP.NET and ASP Classic

The goal of this page is to put two MD5 code samples on the same web page, one for ASP classic and one for ASP.NET. String formatting (like ASCII vs UTF-8) can trip up coding these two routines. These two code samples will produce the same MD5 hash output.

Classic ASP/VBScript MD5

The ASP code is simple once you have a copy of md5.asp from http://frez.co.uk. The only file in the ZIP that you need is md5.asp.


<!--#include file="md5.asp"-->
<% response.write md5("[email protected]") %>

ASP.NET MD5

The keys to getting the .net output to match are encoding.ascii and toString("x2").

<%@ Import Namespace="System.Security.Cryptography" %>   
<script language="VB" runat="server">

	Public Sub Page_Load( sender As Object, e As EventArgs )

		Dim strPlainText as String = "[email protected]"
  		
		dim md5Hasher as MD5 = MD5.create( )
		
		dim result as byte( ) = md5Hasher.computeHash( encoding.ascii.getBytes( strPlainText))
		
		for each singleByte as byte in result
			response.write ( singleByte.ToString("x2") )
		next
		
	End Sub

</script>

Leave a comment

Your email address will not be published. Required fields are marked *