bcrypt 的 .net 实现

发布于 2024-07-20 17:43:10 字数 150 浏览 3 评论 0原文

有谁知道 bcrypt 的良好实现吗?我知道这个问题之前已经被问过,但得到的回应很少。 我有点不确定是否要选择谷歌中出现的实现,并且我认为在 System.Security.Cryptography 命名空间中使用 sha256 可能会更好,至少我知道它是受支持的! 你有什么想法?

Does anyone know of a good implementation of bcrypt, I know this question has been asked before but it got very little response. I'm a bit unsure of just picking an implementation that turns up in google and am thinking that I may be better off using sha256 in the System.Security.Cryptography namespace, at least then I know it's supported! What are you thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

孤独难免 2024-07-27 17:43:10

听起来您正在寻找 BCrypt.net

BCrypt.net 是一个实现
OpenBSD 基于 Blowfish 的密码
散列码,在“A
未来适应性密码方案”作者:
尼尔斯·普罗沃斯和大卫·马齐埃。 这是
Damien 直接移植 jBCrypt
米勒,并因此被释放
相同的 BSD 风格许可证。 代码是
完全托管并应与任何
小端 CLI 实现——它
已通过 Microsoft .NET 测试
和单声道。

It sounds like you are looking for BCrypt.net:

BCrypt.net is an implementation of
OpenBSD's Blowfish-based password
hashing code, described in "A
Future-Adaptable Password Scheme" by
Niels Provos and David Mazières. It is
a direct port of jBCrypt by Damien
Miller, and is thus released under the
same BSD-style license. The code is
fully managed and should work with any
little-endian CLI implementation -- it
has been tested with Microsoft .NET
and Mono.

↘人皮目录ツ 2024-07-27 17:43:10

BCrypt.Net 似乎是目前最受欢迎的库

http://bcrypt.codeplex.com/

这里是如何使用它来哈希密码的示例:

[TestMethod]
    public void BCryptTest()
    {
        const string password = "PASSWORD";
        const int workFactor = 13;

        var start = DateTime.UtcNow;
        var hashed = BCrypt.Net.BCrypt.HashPassword(password, workFactor);
        var end = DateTime.UtcNow;

        Console.WriteLine("hash length is {0} chars", hashed.Length);
        Console.WriteLine("Processing time is {0} with workFactor {1}", end - start, workFactor);
        Console.WriteLine("Hashed password: {0} ", hashed);
        Console.WriteLine("correct password {0}", BCrypt.Net.BCrypt.Verify("PASSWORD", hashed));
        Console.WriteLine("incorrect password {0}", BCrypt.Net.BCrypt.Verify("PASSWORd", hashed));
    }

示例输出:

hash length is 60 chars
Processing time is 00:00:01.0020000 with workFactor 13
Hashed password: $2a$13$iBqdG7ENBABEargiyzGlTexPsmviF/qrFxUZB2zce7HKF6MoBNhEq 
correct password True
incorrect password False

BCrypt.Net seems to be a most popular library at this moment

http://bcrypt.codeplex.com/

Here is an example how to use it for hashing password:

[TestMethod]
    public void BCryptTest()
    {
        const string password = "PASSWORD";
        const int workFactor = 13;

        var start = DateTime.UtcNow;
        var hashed = BCrypt.Net.BCrypt.HashPassword(password, workFactor);
        var end = DateTime.UtcNow;

        Console.WriteLine("hash length is {0} chars", hashed.Length);
        Console.WriteLine("Processing time is {0} with workFactor {1}", end - start, workFactor);
        Console.WriteLine("Hashed password: {0} ", hashed);
        Console.WriteLine("correct password {0}", BCrypt.Net.BCrypt.Verify("PASSWORD", hashed));
        Console.WriteLine("incorrect password {0}", BCrypt.Net.BCrypt.Verify("PASSWORd", hashed));
    }

Sample output:

hash length is 60 chars
Processing time is 00:00:01.0020000 with workFactor 13
Hashed password: $2a$13$iBqdG7ENBABEargiyzGlTexPsmviF/qrFxUZB2zce7HKF6MoBNhEq 
correct password True
incorrect password False
静水深流 2024-07-27 17:43:10

您可以在此处找到 .Net 的 BCrypt 的更新实现:
http://bcrypt.codeplex.com/

You can find an updated implementation of BCrypt for .Net here:
http://bcrypt.codeplex.com/

舂唻埖巳落 2024-07-27 17:43:10

当我将某些内容从 PostgreSQL(有 pg_crypto)移动到 SQLite(没有)时,我需要一个 BCrypt 实现,所以我编写了自己的实现。 从这条消息中看出,我不是唯一需要这个的人,我决定为其添加许可证并发布它。 网址为:

http://zer7.com/software.php?page=cryptsharp

其背后的 Blowfish 实现是 Bruce Schneier 的公共域 C 实现的移植,并在所有官方测试向量上取得了成功。

我根据规范自己编写的 BCrypt 代码。 我还创建了一个 PHP 脚本,它生成长度为 0 到 100 的随机密码和盐,对它们进行加密,然后将它们输出到测试文件。 到目前为止,C# 代码 100% 匹配这些内容。 欢迎您使用该脚本并自行测试。

该库还包括适用于任何 HMAC 的 PBKDF2 代码,而不是 .Net 的仅 SHA-1 实现(今天添加 - 我打算很快用 C# 进行 SCrypt,这需要带有 HMAC-SHA256 的 PBKDF2)。 如果您愿意,您也可以基于此为自己制定一个计划。

I needed a BCrypt implementation when moving something from PostgreSQL (which has pg_crypto) to SQLite (which doesn't), so I wrote my own. Seeing from this message I'm not the only one needing this, I've decided to slap a license on it and release it. The URL is:

http://zer7.com/software.php?page=cryptsharp

The Blowfish implementation behind it is a port of Bruce Schneier's public domain C implementation, and succeeds on all the official test vectors.

The BCrypt code I wrote myself based on the spec. I also created a PHP script which generates random passwords of length 0 to 100 and salts, crypts them, and outputs them to a test file. The C# code matches these 100% of the time so far. You are welcome to use the script and test this yourself.

The library also includes PBKDF2 code which works for any HMAC as opposed to .Net's SHA-1-only implementation (added today -- I'm intending to do SCrypt in C# soon and that requires PBKDF2 with HMAC-SHA256). You could make yourself a scheme based on this too, if you wanted.

旧伤还要旧人安 2024-07-27 17:43:10

错误答案,请参见下文

.Net Framework 中的所有“Cng”(下一代加密)后缀算法现在都使用 bcrypt。 例如 SHA256Cng。


实际上,MS BCrypt (BestCrypt) 并不是指基于 Blowfish 密码的密码 - 谢谢 RobbyD 的评论。
不会删除答案,以防其他人犯同样的困惑。

Wrong answer, please see below

All "Cng" (Cryptography Next Generation) postfixed algorithms in the .Net Framework now use bcrypt. E.g. SHA256Cng.


Actually the MS BCrypt (BestCrypt) does not refer to the one based on the Blowfish cipher - thank you, RobbyD, for the comment.
Will not delete the answer, just in case anyone else makes the same confusion.

紫轩蝶泪 2024-07-27 17:43:10

Have you tried this MS BCryptCreateHash C++ function perhaps?? Seems to be present from Windows Server 2008 and Windows Vista.

Also, you can probably check the following MS C# BCryptNative.cs class too perhaps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文