我一直在尝试对必须保存在设备上的密码进行哈希和加盐处理。这是我一直在使用的代码,但我在 Windows 应用商店框架中找不到 System.Security.Cryptography 和 RNGCryptoServiceProvider。
public static string CreateSalt(int size)
{
var rng = new RNGCryptoServiceProvider();
var buff = new byte[size];
rng.GetBytes(buff);
return Convert.ToBase64String(buff);
}
public static string GenerateSHA256Hash(string input, string salt)
{
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(input + salt);
SHA1Managed sha = new SHA1Managed();
byte[] hash = sha.ComputeHash(bytes);
return Convert.ToBase64String(hash);
}
有没有人建议如何在 Windows 应用商店应用程序上执行此操作? 谢谢
最佳答案
有一种替代方法可以使用 RNGCryptoServiceProvider
var buffer = CryptographicBuffer.GenerateRandom(saltlength);
var string = CryptographicBuffer.EncodeToBase64String(buffer)
Windows.Security.Cryptography 是 System.Security.Cryptography 的替代品,适用于 Windows 应用商店应用。
关于c# - Windows 应用商店应用程序中的哈希和盐字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29835621/