public string HashPassword(string password, string salt) { var passwordBytes = Encoding.UTF8.GetBytes(password); var saltBytes = Encoding.UTF8.GetBytes(salt); var argon2 = new Argon2i(passwordBytes) { DegreeOfParallelism = 16, MemorySize = 8192, Iterations = 40, Salt = saltBytes, }; var hash = argon2.GetBytes(32); // Convert the byte array to hexadecimal string var stringBuilder = new StringBuilder(); foreach (var t in hash) { stringBuilder.Append(t.ToString("X2")); } return(stringBuilder.ToString()); }
public static byte[] ToRawArgon2(byte[] data, byte[] salt, uint iterations, uint memorySizeKiB, uint parallelism, Argon2Variant variant = Argon2Variant.Argon2id, uint derivedKeyLength = Argon2DerivedKeyLength) { switch (variant) { case Argon2Variant.Argon2d: Argon2d argon2d = new Argon2d(data); argon2d.Salt = salt; argon2d.Iterations = (int)iterations; argon2d.MemorySize = (int)memorySizeKiB; argon2d.DegreeOfParallelism = (int)parallelism; return(argon2d.GetBytes((int)derivedKeyLength)); case Argon2Variant.Argon2i: Argon2i argon2i = new Argon2i(data); argon2i.Salt = salt; argon2i.Iterations = (int)iterations; argon2i.MemorySize = (int)memorySizeKiB; argon2i.DegreeOfParallelism = (int)parallelism; return(argon2i.GetBytes((int)derivedKeyLength)); case Argon2Variant.Argon2id: Argon2id argon2id = new Argon2id(data); argon2id.Salt = salt; argon2id.Iterations = (int)iterations; argon2id.MemorySize = (int)memorySizeKiB; argon2id.DegreeOfParallelism = (int)parallelism; return(argon2id.GetBytes((int)derivedKeyLength)); default: throw new Exception("Invalid Argon2 variant"); } }
private static string SaltPassword(string password, string salt) { var argon2 = new Argon2i(Encoding.UTF8.GetBytes(password)) { Salt = Encoding.UTF8.GetBytes(salt), DegreeOfParallelism = 16, MemorySize = 1024, Iterations = 40 }; return(Convert.ToBase64String(argon2.GetBytes(128))); }
public byte[] GetPassHash(string password, byte[] salt) { var argon2 = new Argon2i(System.Text.Encoding.UTF8.GetBytes(password)) { Salt = salt, DegreeOfParallelism = 8, MemorySize = 4096, Iterations = 40 }; return(argon2.GetBytes(128)); }
private byte[] GetPasswordHash(string password) { var passwordBytes = Encoding.UTF8.GetBytes(password); var usernameBytes = Encoding.UTF8.GetBytes(GetUserName().Result); var argon2 = new Argon2i(passwordBytes); argon2.DegreeOfParallelism = 16; argon2.MemorySize = 8192; argon2.Iterations = 64; argon2.Salt = State.PasswordSalt; argon2.AssociatedData = usernameBytes; return(argon2.GetBytes(128)); }
public string Argon2Hash(string text, int iterations = 50, int degreeOfParallelism = 8, int memorySize = 8192) { using (var a = new Argon2i(Encoding.UTF8.GetBytes(text))) { a.DegreeOfParallelism = degreeOfParallelism; a.MemorySize = memorySize; a.Iterations = iterations; a.Salt = Encoding.UTF8.GetBytes(Strongify(text)); a.AssociatedData = Encoding.UTF8.GetBytes(Strongify(text)); var b = a.GetBytes(512 / 8); return(BitConverter.ToString(b).Replace("-", "").ToLower()); } }
/// <summary> /// Argon2i password encryption /// </summary> /// <param name="password">Password that should be hashed</param> /// <returns>Hash value of the password</returns> private static string EncryptPassword(string password) { var bytes = Encoding.UTF8.GetBytes(password); var argon2I = new Argon2i(bytes) { Iterations = 64, MemorySize = 4096, DegreeOfParallelism = 16 }; var hash = argon2I.GetBytes(256); return(Convert.ToBase64String(hash)); }
public bool Verify(string password) { var argon2 = new Argon2i(Encoding.UTF8.GetBytes(password)) { DegreeOfParallelism = 2, Salt = salt, MemorySize = 8192, Iterations = 2, AssociatedData = identifier.ToByteArray() }; var computedHash = argon2.GetBytes(128); return(hash.SequenceEqual(computedHash)); }
public byte[] HashPassword(string password, string salt) { byte[] newHash = null; using (var argon2 = new Argon2i(Encoding.ASCII.GetBytes(password))) { argon2.Salt = Encoding.ASCII.GetBytes(salt); argon2.DegreeOfParallelism = 16; argon2.Iterations = 40; argon2.MemorySize = 8192; newHash = argon2.GetBytes(128); } return(newHash); }
public Identity(string email, string password) { identifier = Guid.NewGuid(); rngCsp.GetBytes(salt = new byte[64]); var argon2 = new Argon2i(Encoding.UTF8.GetBytes(password)) { DegreeOfParallelism = 2, Salt = salt, MemorySize = 8192, Iterations = 2, AssociatedData = identifier.ToByteArray() }; hash = argon2.GetBytes(128); Console.WriteLine("Hashed: " + new System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary(hash).ToString()); }
public static string GenerateHashArgon2(string password, string salt) { var pwBytes = Encoding.UTF8.GetBytes(password); var saltBytes = Convert.FromBase64String(salt); var argon = new Argon2i(pwBytes) { DegreeOfParallelism = 16, MemorySize = 8192, Iterations = NUMBER_OF_ITERATIONS, Salt = saltBytes }; var hashBytes = argon.GetBytes(HASH_SIZE); var hash = Convert.ToBase64String(hashBytes); return(hash); }
public Tuple <string, string> GetStringHashAndSalt(string str) { byte[] passwordBytes = Encoding.UTF8.GetBytes(str); var argon2 = new Argon2i(passwordBytes); byte[] salt = new byte[16]; Rng.GetBytes(salt); argon2.DegreeOfParallelism = 16; argon2.MemorySize = 8192; argon2.Iterations = 40; argon2.Salt = salt; byte[] hash = argon2.GetBytes(128); return(new Tuple <string, string>(Convert.ToBase64String(hash), Convert.ToBase64String(salt))); }