日期:2014-05-18  浏览次数:20894 次

加密
我想修改用户密码,然后在用此方法加密,但不知道怎么调用,请帮帮忙
public static string md5(string str, int code)
  {
  string strEncrypt = string.Empty;
  if (code == 16)
  {
  strEncrypt = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").Substring(8, 16);
  }

  if (code == 32)
  {
  strEncrypt = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5");
  }

  return strEncrypt;
  }

------解决方案--------------------
C# code

类名.md5("xxx",32); //类名是指这个方法所在的类;xxx是传入的加密字符串,32或16一个是原生的md5加密,一个在此基础上又进行了字符串截取

------解决方案--------------------
SQL code

select RIGHT(sys.fn_varbintohexstr(hashbytes('md5','123456')),32) --32位
select substring(sys.fn_varbintohexstr(hashbytes('md5','123456')),8,16)--16位