C#教程:账号加密算法
作者:转载自:xin3721视频教程网更新时间:2010-12-9

.net 的membership给我们提供了账户乃至权限等配置。

  我们有时要手动的去配置账户,比如账户的增删查改。

  众所周知,.net的密码存进数据库是经过特殊加密的,

  这时候我们就要用到账户密码的加密算法

  代码

  ///

  /// 获取密码加密密钥

  ///

  ///

  private string GetPassWordSalt()

  {

  byte[] data = new byte[0x10];

  new System.Security.Cryptography.RNGCryptoServiceProvider().GetBytes(data);

  return Convert.ToBase64String(data);

  }

  ///

  /// 哈希密码加密算法

  ///

  /// 原始字符串

  /// salt加密字符串

  /// 加密格式

  ///

  public string EncryptToHashString(string s, string saltkey, string hashname)

  {

  byte[] src = System.Text.Encoding.Unicode.GetBytes(s);

  byte[] saltbuf = Convert.FromBase64String(saltkey);

  byte[] dst = new byte[saltbuf.Length + src.Length];

  byte[] inArray = null;

  System.Buffer.BlockCopy(saltbuf, 0, dst, 0, saltbuf.Length);

  System.Buffer.BlockCopy(src, 0, dst, saltbuf.Length, src.Length);

  System.Security.Cryptography.HashAlgorithm algorithm = System.Security.Cryptography.HashAlgorithm.Create(hashname);

  inArray = algorithm.ComputeHash(dst);

  return Convert.ToBase64String(inArray);

  }

原文地址https://www.xin3721.com/Article/xin3721_Article_13791.html

关于我们--广告服务--免责声明--本站帮助-友情链接--版权声明--联系我们     黑ICP备07002182号