31 lines
1.2 KiB
C#
31 lines
1.2 KiB
C#
namespace HRD.LDAPService.JWT
|
|
{
|
|
public static class JWTCrypt
|
|
{
|
|
public static string GenerateHashPassword(string inputKey)
|
|
{
|
|
return BCrypt.Net.BCrypt.EnhancedHashPassword(inputKey, 11, BCrypt.Net.HashType.SHA512);
|
|
}
|
|
|
|
public static bool VerifyHashPassword(string hashedPassword, string providedPassword)
|
|
{
|
|
return BCrypt.Net.BCrypt.Verify(providedPassword, hashedPassword, true, BCrypt.Net.HashType.SHA512);
|
|
}
|
|
|
|
public static string SHA512(string input)
|
|
{
|
|
var bytes = System.Text.Encoding.UTF8.GetBytes(input);
|
|
using (var hash = System.Security.Cryptography.SHA512.Create())
|
|
{
|
|
var hashedInputBytes = hash.ComputeHash(bytes);
|
|
|
|
// Convert to text
|
|
// StringBuilder Capacity is 128, because 512 bits / 8 bits in byte * 2 symbols for byte
|
|
var hashedInputStringBuilder = new System.Text.StringBuilder(128);
|
|
foreach (var b in hashedInputBytes)
|
|
hashedInputStringBuilder.Append(b.ToString("X2"));
|
|
return hashedInputStringBuilder.ToString();
|
|
}
|
|
}
|
|
}
|
|
} |