日期:2014-05-18 浏览次数:20972 次
public string md5(string str, int code) //code 16 或 32 { if (code == 16) //16位MD5加密(取32位加密的9~25字符) { return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower().Substring(8, 16); } if (code == 32) //32位加密 { return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str.Trim(), "MD5").ToString(); } return "00000000000000000000000000000000"; } }
using System.Web.Security; namespace Usb_Server { public class ToMd5 { /// <summary> /// 给密码加密 /// </summary> /// <param name="str"></param> /// <param name="code"></param> /// <returns></returns> public string md5(string str, int code) { if (code == 16) //16位MD5加密(取32位加密的9~25字符) { return FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower().Substring(8, 16); } if (code == 32) //32位MD5加密 { return FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower(); } return ""; } } }