Created
October 14, 2023 12:27
-
-
Save hancheester/8101a9ad3a2331753ce2e688579bd597 to your computer and use it in GitHub Desktop.
To hash password
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Security.Cryptography; | |
using System.Text; | |
namespace PasswordHasher | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
const int keySize = 64; | |
const int iterations = 350000; | |
HashAlgorithmName hashAlgorithm = HashAlgorithmName.SHA512; | |
var saltBytes = RandomNumberGenerator.GetBytes(keySize); | |
Console.Write("Enter password: "); | |
var password = Console.ReadLine(); | |
var hashBytes = Rfc2898DeriveBytes.Pbkdf2( | |
Encoding.UTF8.GetBytes(password!), | |
saltBytes, | |
iterations, | |
hashAlgorithm, | |
keySize); | |
Console.WriteLine(); | |
var salt = Convert.ToHexString(saltBytes); | |
var hash = Convert.ToHexString(hashBytes); | |
Console.WriteLine($"Salt: \n{salt}"); | |
Console.WriteLine(); | |
Console.WriteLine($"Hash: \n{hash}"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment