public NerdyRfc2898DeriveBytes( ReadOnlySpan <byte> password, ReadOnlySpan <byte> salt, int iterations, HashAlgorithmName hashAlgorithm) { if (salt.Length < MinimumSaltSize) { throw new ArgumentException($"salt minimum length is {MinimumSaltSize}", nameof(salt)); } if (iterations <= 0) { throw new ArgumentOutOfRangeException(nameof(iterations), "iterations must be a positive number"); } this.salt = new byte[salt.Length + sizeof(uint)]; salt.CopyTo(this.salt); this.iterations = (uint)iterations; this.password = new byte[password.Length]; password.CopyTo(this.password); this.HashAlgorithm = hashAlgorithm; this.hmac = this.OpenHmac(); // this.blockSize is in bytes, HashSize is in bits. this.blockSize = this.hmac.HashSize >> 3; this.Initialize(); }
public NerdyRfc2898DeriveBytes(string password, int saltSize, int iterations, HashAlgorithmName hashAlgorithm) { switch (saltSize) { case < 0: throw new ArgumentOutOfRangeException(nameof(saltSize), $"saleSize must a positive number"); case < MinimumSaltSize: throw new ArgumentException($"salt minimum length is {MinimumSaltSize}", nameof(saltSize)); } if (iterations <= 0) { throw new ArgumentOutOfRangeException(nameof(iterations), "iterations must be a positive number"); } this.salt = new byte[saltSize + sizeof(uint)]; using (var rng = new NerdyRandomNumberGenerator()) { rng.NextBytes(this.salt); } this.iterations = (uint)iterations; this.password = Encoding.UTF8.GetBytes(password); this.HashAlgorithm = hashAlgorithm; this.hmac = this.OpenHmac(); // this.blockSize is in bytes, HashSize is in bits. this.blockSize = this.hmac.HashSize >> 3; this.Initialize(); }
public NerdyRfc2898DeriveBytes(string password, byte[] salt, int iterations, HashAlgorithmName hashAlgorithm) : this(Encoding.UTF8.GetBytes(password), salt, iterations, hashAlgorithm) { }