Using system. Security. cryptography;// Introduce the namespace
Using system. text;// Introduce the namespace
Public sealed class md5hashing
{
Private Static MD5 MD5 = md5.create ();
Private md5hashing ()
{
}
/** // <Summary>
/// Encrypt the string
/// </Summary>
/// <Param name = "sourcestring"> string to be encrypted </param>
/// <Returns> MD5 encrypted string </returns>
Public static string hashstring (string sourcestring)
{
Return hashstring ("gb2312", sourcestring );
}
/** // <Summary>
/// String MD5 Encryption
/// </Summary>
/// <Param name = "codename"> encoding type </param>
/// <Param name = "sourcestring"> string to be encrypted </param>
/// <Returns> MD5 encrypted string </returns>
Public static string hashstring (string codename, string sourcestring)
{
Byte [] source = md5.computehash (encoding. getencoding (codename). getbytes (sourcestring ));
Stringbuilder sbuilder = new stringbuilder ();
For (INT I = 0; I <source. length; I ++)
{
Sbuilder. append (source [I]. tostring ("X "));
}
Return sbuilder. tostring ();
}
}
Asp.net common MD5 Encryption
Using system. Web. Security;
Public static string hashstring (string sourcestring)
{< br> return formsauthentication. hashpasswordforstoringinconfigfile (sourcestring, "MD5");
}