Create an MD5 Hash the Easy Way in .NET
Posted by matthew | Posted in Code Snippets | Posted on 11-12-2009
Tags: .NET, ASP.NET, Cryptography, MD5, Security, VB, VB.net
0
Creating an MD5 hash seems to take forever in .NET, however you may want to try this quick method instead.
Normally you would need to include security routines for Cryptography and it takes many lines of code to achieve, well try this instead:
<%@ Import Namespace="System.Web.Security" %> <% Dim apikey,hash,secretkey,sign secretkey = "foo" apikey = "bar" sign = secretkey + apikey + "string" hash = FormsAuthentication.HashPasswordForStoringInConfigFile (sign, "MD5") %> <%=hash.ToLower()%>
Sneakily using the web security name space instead you can quickly turn any string or strings into a perfect MD5 hash everytime. Much quicker then playing around with cryptography!



