C# PasswordDeriveBytes Confusion(C# PasswordDeriveBytes 混淆)
问题描述
我在 C# 中有以下代码
I have following code in C#
PasswordDeriveBytes DerivedPassword = new PasswordDeriveBytes(Password, SaltValueBytes, HashAlgorithm, PasswordIterations);
byte[] KeyBytes = DerivedPassword.GetBytes(32);
我正在使用SHA1"哈希算法.
I am using "SHA1" hashing algorithm.
根据 SHA1 定义,它生成 160 位(20 字节)的密钥.我的问题是 GetBytes 方法如何从 DerivedPassword 中获取 32 个字节,GetBytes 方法背后使用了什么算法?
According to SHA1 definition, its generate 160 bits (20 bytes) key. My question is how GetBytes method get 32 bytes from DerivedPassword, what algorithm used behind GetBytes method?
推荐答案
Microsoft 对原始 PKCS#5(又名 PBKDF1)的实现包括 insecure 扩展,以提供比散列函数所能提供的更多的字节(参见错误报告此处和这里).
Microsoft's implementation of original PKCS#5 (aka PBKDF1) include insecure extensions to provide more bytes than the hash function can provide (see bug reports here and here).
即使它没有错误,您也应该避免对标准进行未记录的专有扩展(否则您将来可能永远无法解密您的数据 - 至少不能在 Windows 之外.)
Even if it was not buggy you should avoid undocumented, proprietary extensions to standards (or you might never be able to decrypt your data in the future - at least not outside Windows.)
我强烈建议您使用更新的 Rfc2898DeriveBytes
,它实现了自 .NET 2.0 起可用的 PBKDF2 (PKCS#5 v2).
I strongly suggest you to use the newer Rfc2898DeriveBytes
which implements PBKDF2 (PKCS#5 v2) which is available since .NET 2.0.
这篇关于C# PasswordDeriveBytes 混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C# PasswordDeriveBytes 混淆


- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 输入按键事件处理程序 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01