#if !STELLAOPS_CRYPTO_SODIUM using System; using System.Text; using Org.BouncyCastle.Crypto.Generators; using Org.BouncyCastle.Crypto.Parameters; namespace StellaOps.Cryptography; /// /// Managed Argon2id implementation powered by BouncyCastle.Cryptography. /// public sealed partial class Argon2idPasswordHasher { private static partial byte[] DeriveHashCore(string password, ReadOnlySpan salt, PasswordHashOptions options) { var passwordBytes = Encoding.UTF8.GetBytes(password); var parameters = new Argon2Parameters.Builder(Argon2Parameters.Argon2id) .WithSalt(salt.ToArray()) .WithParallelism(options.Parallelism) .WithIterations(options.Iterations) .WithMemoryAsKB(options.MemorySizeInKib) .Build(); var generator = new Argon2BytesGenerator(); generator.Init(parameters); var result = new byte[HashLengthBytes]; generator.GenerateBytes(passwordBytes, result); return result; } } #endif