using System.Security.Cryptography;
using Isopoh.Cryptography.Argon2;
using Isopoh.Cryptography.SecureArray;
using Isopoh.Cryptography.Argon2;
public static void Main()
var password = "password1";
byte[] passwordBytes = Encoding.UTF8.GetBytes(password);
byte[] salt = RandomNumberGenerator.GetBytes(16);
var config = new Argon2Config
Type = Argon2Type.DataIndependentAddressing,
Version = Argon2Version.Nineteen,
MemoryCost = 32768 / 2 / 2,
Threads = Environment.ProcessorCount,
Password = passwordBytes,
AssociatedData = [1,2,3,4],
var argon2A = new Argon2(config);
using(SecureArray<byte> hashA = argon2A.Hash())
hashString = config.EncodeString(hashA.Buffer);
var configOfPasswordToVerify = new Argon2Config { Password = passwordBytes, Threads = 1 };
SecureArray<byte> hashB = null;
if (configOfPasswordToVerify.DecodeString(hashString, out hashB) && hashB != null)
var argon2ToVerify = new Argon2(configOfPasswordToVerify);
using(var hashToVerify = argon2ToVerify.Hash())
if (Argon2.FixedTimeEquals(hashB, hashToVerify))
if (Argon2.Verify(hashString, passwordBytes, 5))
Console.WriteLine("fail");