我有这个简单的类有两种方法:
private static byte[] PBKDF2(string field, byte[] salt, int iterations, int outputBytes)
{
Rfc2898DeriveBytes pbkdf2 = new Rfc2898DeriveBytes(field, salt);
pbkdf2.IterationCount = iterations;
return pbkdf2.GetBytes(outputBytes);
}
public static string CreateHash(string field, String salt)
{
//if (Array.TrueForAll(salt, x => x == 0))
//{
// RNGCryptoServiceProvider csprng = new RNGCryptoServiceProvider();
// csprng.GetBytes(salt);
// string s = Convert.ToBase64String(salt);
//}
byte[] salts = Encoding.ASCII.GetBytes(salt);
byte[] hash = PBKDF2(field, salts, PBKDF2_ITERATIONS, HASH_BYTE_SIZE);
return Convert.ToBase64String(hash);
}
我需要提供一个前端,用户输入一个简单的字符串,如“abc”,我需要根据它生成一个盐。这就是我将要存储在数据库中并使用它传递给上面的方法(CreateHash)来解除识别 数据。这个salt / key需要能够被解密,我必须在前端显示。
我也可以使用其他类/库。它不一定是Rfc2898DeriveBytes。
请提供一些关于如何实现此盐/密钥生成功能的输入。这种盐不能是随机值。
谢谢!
答案 0 :(得分:0)