相当于openssl中的PasswordDeriveBytes
我的C#代码如下:
private static string password = "Password";
private static string salt = "SALT";
private static string hashAlgorithm = "SHA1";
private static int iterations = 2;
var saltValueBytes = Encoding.UTF8.GetBytes(salt);
var passwordKey = new PasswordDeriveBytes(password, saltValueBytes, hashAlgorithm, iterations)
...
我需要在Mac中实现相同的功能,我知道Opnessl实现了相关方法(即libcrypto)。
Opnessl 中与上述代码等效的方法是什么?
I have C# code as below:
private static string password = "Password";
private static string salt = "SALT";
private static string hashAlgorithm = "SHA1";
private static int iterations = 2;
var saltValueBytes = Encoding.UTF8.GetBytes(salt);
var passwordKey = new PasswordDeriveBytes(password, saltValueBytes, hashAlgorithm, iterations)
...
I need to implement the same in Mac, I came to know that Opnessl implements related methods(i.e. libcrypto).
What is the equivalent method in Opnessl to above code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这展示了如何使用 OpenSSL 实现 PBKDF1,根据文档,这是
PasswordDeriveBytes
使用的算法。This shows how to implement PBKDF1 with OpenSSL, which according to the documentation is the algorithm used by
PasswordDeriveBytes
.OpenSSL 实现了 PBKDF2,.NET 将其公开为
Rfc2898DeriveBytes
。PasswordDeriveBytes
使用(根据 .NET 4 文档)“PBKDF1 算法的扩展”。 OpenSSL 不会公开 PBKDF1(谁知道有问题的“扩展名”可能是什么)。如果可能的话,使用 PBKDF2(又名
Rfc2898DeriveBytes
)将为您避免很多问题。OpenSSL implements PBKDF2, which .NET exposes as
Rfc2898DeriveBytes
.PasswordDeriveBytes
uses (according to the .NET 4 docs) "an extension of the PBKDF1 algorithm". PBKDF1 is not exposed by OpenSSL (and who knows what the 'extension' in question may be).Using PBKDF2 (aka
Rfc2898DeriveBytes
) if possible will save you a lot of problems here.这是 mono 源代码 用于执行 GetBytes(X),其中 X 可以大于散列的大小。正如你所看到的,我只实现了 SHA1 版本......
This is a c++ quick and dirty translation of the mono source code to perform GetBytes(X) where X can be greater than the size of the hash. As you can see I'v implemented only the SHA1 version...