ASP.NET md5 function

Date: 29 Jan 2010 Comments: 1

I was pleasantly surprised to found that using System.Security.Cryptography you can create a function that calculates the MD5 hash of string.

Here’s an C# example:

using System.Security.Cryptography;
using System.Text;

public string md5(string aString)
{
byte[] byteStr = Encoding.UTF8.GetBytes(aString);
MD5 md5Provider = new MD5CryptoServiceProvider();

return Encoding.UTF8.GetString(md5Provider.ComputeHash(byteStr));
}

Here’s the same function in VB.NET:

Imports System.Security.Cryptography
Imports System.Text

Public Function md5(ByVal aString As String) As String
Dim byteStr() As Byte =  Encoding.UTF8.GetBytes(aString)
Dim md5Provider As MD5 =  New MD5CryptoServiceProvider()

Return Encoding.UTF8.GetString(md5Provider.ComputeHash(byteStr))
End Function

Does System.Security.Cryptography namespace provides all necessary cryptographic services for you?
  1. One Comments to “ASP.NET md5 function”

    1. Richard says:

      Yeah they have all kinds of amazing functions. You can even make strings into UPPERCASE! Absolutely amazing, I have no idea how they do it.

    Leave a Reply


    Spam protection by WP Captcha-Free