6
下面是所使用散列在一個應用程序的密碼,我重寫的代碼片斷:最大長度
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編碼鹽和密碼的最大長度?