0
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();

I have codes like this above, they are working fine but I'm gonna use them for moodle project, so I need to hash my passwords with "2y$" identifier.

What can I use? I can't use nuGetPackages like cryptsharpofficial, cause it gives error when I want to use it in Windows 10 November Update (10586)

2
  • 3
    $2y$ is the crypt scheme ID for a variant of bcrypt/blowfish - look for a C# library that supports this, .e.g github.com/BcryptNet/bcrypt.net
    – iainn
    Apr 17, 2018 at 13:11
  • Moodle is a php project, and it stores passwords with password_hash command. If I want to add data in mysql, I need to use "2y$" identifier. Otherwise passwords doesn't work. and does "bcrypt.net" supports 10586 update?
    – Cruwiel
    Apr 17, 2018 at 13:20

2 Answers 2

1

I just installed "BCrypt.Net-Next" and codes shown in below works well:

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

Thanks to @iainn, his comment link: Hashing Password with "$2y$" identifier

1
1

The BCrypt.Net-Next by default uses the $2a$ algorithm.

You can have it explicitly use $2y$ by specifying the bcryptMinorRevision of the GenerateSalt() function like this:

string salt = BCrypt.Net.BCrypt.GenerateSalt(8, 'y');
string hashedPassword = BCrypt.Net.BCrypt.HashPassword(passToHash, salt);

Here are the first few lines of the decompiled GenerateSalt() function from that library:

        public static string GenerateSalt(int workFactor, char bcryptMinorRevision = 'a')
        {
            if (workFactor < 4 || workFactor > 31)
            {
                throw new ArgumentOutOfRangeException("workFactor", workFactor, $"The work factor must be between {(short)4} and {(short)31} (inclusive)");
            }

            if (bcryptMinorRevision != 'a' && bcryptMinorRevision != 'b' && bcryptMinorRevision != 'x' && bcryptMinorRevision != 'y')
            {
                throw new ArgumentException("BCrypt Revision should be a, b, x or y", "bcryptMinorRevision");
            }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.