ASP.NET md5 function
Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in D:\Hosting\3681091\html\blog\wp-content\plugins\digg-digg\dd.class.php on line 759
Warning: file_get_contents(http://feeds.delicious.com/v2/json/urlinfo/data?url=http%3A%2F%2Fwww.devtheweb.net%2Fblog%2F2010%2F01%2F29%2Fasp-net-md5-function%2F) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in D:\Hosting\3681091\html\blog\wp-content\plugins\digg-digg\dd.class.php on line 759
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


One Comments to “ASP.NET md5 function”
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.