【发布时间】:2011-07-29 15:43:20
【问题描述】:
下面是我正在重写的应用程序中用于哈希密码的代码的 sn-p:
internal string GenerateSalt()
{
byte[] buf = new byte[16];
(new RNGCryptoServiceProvider()).GetBytes(buf);
return Convert.ToBase64String(buf);
}
internal string EncodePassword(string pass, string salt)
{
byte[] bIn = Encoding.Unicode.GetBytes(pass);
byte[] bSalt = Convert.FromBase64String(salt);
byte[] bAll = new byte[bSalt.Length + bIn.Length];
Buffer.BlockCopy(bSalt, 0, bAll, 0, bSalt.Length);
Buffer.BlockCopy(bIn, 0, bAll, bSalt.Length, bIn.Length);
HashAlgorithm s = HashAlgorithm.Create("SHA512");
byte[] bRet = s.ComputeHash(bAll);
return Convert.ToBase64String(bRet);
}
哈希密码和盐稍后将存储在数据库中。 base64 编码的盐和密码的最大长度是多少?
【问题讨论】:
标签: c# sql-server encoding character-encoding base64