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

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

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

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

代码
/// <summary>
/// 获取密码加密密钥
/// </summary>
/// <returns></returns>
private string GetPassWordSalt()
{
byte[] data = new byte[0x10];
new System.Security.Cryptography.RNGCryptoServiceProvider().GetBytes(data);
return Convert.ToBase64String(data);
}

/// <summary>
/// 哈希密码加密算法
/// </summary>
/// <param name="s">原始字符串</param>
/// <param name="saltKey">salt加密字符串</param>
/// <param name="hashName">加密格式</param>
/// <returns></returns>
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);
}

 

 

 

相关文章:

  • 2021-07-12
  • 2021-10-23
  • 2022-12-23
  • 2022-01-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-31
  • 2022-12-23
  • 2021-09-07
  • 2022-12-23
  • 2021-11-01
  • 2021-10-29
相关资源
相似解决方案