using System;
using System.Collections.Generic;
using System.Web;
namespace Web.Code
{
public class MD5Pwd
{
#region 加密
/// <summary>
/// MD5加密
/// </summary>
/// <param name="InputString">要加密的字串</param>
/// <returns>密文</returns>
public static string Md5hash_String(string InputString)
{
InputString = Md5hash_String(InputString, "MD5");
return InputString;
}
/// <summary>
/// SHA1,MD5加密
/// </summary>
/// <param name="InputString">要加密的字符串</param>
/// <param name="format">加密格式 MD5 或 SHA1</param>
/// <returns>返回加密后的字串</returns>
public static string Md5hash_String(string InputString, string format)
{
if (format == "SHA1")
{
InputString = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(InputString, "SHA1");
//InputString=.Security.Authentication
}
else if (format == "MD5")
{
InputString = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(InputString, "MD5");
}
return InputString;
}
//sql2005的MDT函数
//select sys.fn_VarBinToHexStr(hashbytes(’MD5′, ‘12345′))
#endregion
}
}