Reputation: 35
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)
Upvotes: 1
Views: 22828
Reputation: 382
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");
}
Upvotes: 3
Reputation: 35
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
Upvotes: 1