Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the spinupwp domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /sites/coreysalzano.com/files/wp-includes/functions.php on line 6121
Matching MD5 hashes in ASP.NET and ASP Classic – Corey Salzano

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@example.com") %>

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@example.com"
  		
		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>