using System.Security.Cryptography;
public static void Main()
Console.WriteLine("Please enter a password");
var pw = Console.ReadLine();
var pwb = Encoding.UTF8.GetBytes(pw);
var saltb = GetRandomSalt();
var salt = BitConverter.ToInt32(saltb, 0);
var hashb = GenerateSaltedHash(pwb, saltb);
var hash = Convert.ToBase64String(hashb);
Console.WriteLine(String.Format("Password (Text): {0}", pw));
Console.WriteLine(String.Format("Salt (Int): {0}", salt));
Console.WriteLine(String.Format("SaltedHash: {0}", hash));
public static byte[] GetRandomSalt()
byte[] salt = new byte[16];
Random random = new Random();
public static byte[] GenerateSaltedHash(byte[] plainText, byte[] salt)
HashAlgorithm algorithm = new SHA256Managed();
byte[] plainTextWithSaltBytes =
new byte[plainText.Length + salt.Length];
for (int i = 0; i < plainText.Length; i++)
plainTextWithSaltBytes[i] = plainText[i];
for (int i = 0; i < salt.Length; i++)
plainTextWithSaltBytes[plainText.Length + i] = salt[i];
return algorithm.ComputeHash(plainTextWithSaltBytes);