使用" $ 2y $"哈希密码识别码

时间:2018-04-17 13:04:50

标签: c# uwp moodle

String strAlgName = HashAlgorithmNames.Sha1;

HashAlgorithmProvider objAlgProv = HashAlgorithmProvider.OpenAlgorithm(strAlgName);
CryptographicHash objHash = objAlgProv.CreateHash();

String strMsg1 = "test";
IBuffer buffMsg1 = CryptographicBuffer.ConvertStringToBinary(strMsg1, BinaryStringEncoding.Utf16BE);

objHash.Append(buffMsg1);

IBuffer buffHash1 = objHash.GetValueAndReset();

我上面有这样的代码,它们工作正常,但我会将它们用于moodle项目,所以我需要用" 2y $"标识符。

我可以使用什么?我不能使用像cryptsharpofficial这样的nuGetPackages,因为当我想在Windows 10 11月更新(10586)中使用它时会出现错误

1 个答案:

答案 0 :(得分:1)

我刚刚安装了“BCrypt.Net-Next”,下面显示的代码效果很好:

string hashedPassword = BCrypt.Net.BCrypt.HashPassword(passToHash);

感谢@iainn,他的评论链接: Hashing Password with "$2y$" identifier