public Rfc2898DeriveBytes(string password, int saltSize, int iterations, HashAlgorithmName hashAlgorithm)
        {
            if (saltSize < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(saltSize), SR.ArgumentOutOfRange_NeedNonNegNum);
            }
            if (saltSize < MinimumSaltSize)
            {
                throw new ArgumentException(SR.Cryptography_PasswordDerivedBytes_FewBytesSalt, nameof(saltSize));
            }
            if (iterations <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(iterations), SR.ArgumentOutOfRange_NeedPosNum);
            }

            _salt         = Helpers.GenerateRandom(saltSize);
            _iterations   = (uint)iterations;
            _password     = Encoding.UTF8.GetBytes(password);
            HashAlgorithm = hashAlgorithm;
            _hmac         = OpenHmac();
            // _blockSize is in bytes, HashSize is in bits.
            _blockSize = _hmac.HashSize >> 3;

            Initialize();
        }
        public Rfc2898DeriveBytes(string password, int saltSize, int iterations)
        {
            if (saltSize < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(saltSize), SR.ArgumentOutOfRange_NeedNonNegNum);
            }
            if (saltSize < MinimumSaltSize)
            {
                throw new ArgumentException(SR.Cryptography_PasswordDerivedBytes_FewBytesSalt, nameof(saltSize));
            }
            if (iterations <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(iterations), SR.ArgumentOutOfRange_NeedPosNum);
            }

            _salt       = Helpers.GenerateRandom(saltSize);
            _iterations = (uint)iterations;
            _password   = Encoding.UTF8.GetBytes(password);
            _hmacSha1   = new HMACSHA1(_password);

            Initialize();
        }
Beispiel #3
0
 public HMACSHA1()
     : this(Helpers.GenerateRandom(BlockSize))
 {
 }
Beispiel #4
0
 public HMACGost3411()
     : this(Helpers.GenerateRandom(BlockSize))
 {
 }
Beispiel #5
0
 public HMACSHA512()
     : this(Helpers.GenerateRandom(128))
 {
 }
Beispiel #6
0
 public HMACSHA1()
     : this(Helpers.GenerateRandom(64))
 {
 }
Beispiel #7
0
 public void GenerateKey()
 {
     byte[] key = Helpers.GenerateRandom(AsymmetricAlgorithmHelpers.BitsToBytes(_outer.BaseKeySize));
     SetKey(key);
 }
Beispiel #8
0
 public void GenerateIV()
 {
     byte[] iv = Helpers.GenerateRandom(AsymmetricAlgorithmHelpers.BitsToBytes(_outer.BlockSize));
     _outer.IV = iv;
 }
Beispiel #9
0
 public HMACMD5()
     : this(Helpers.GenerateRandom(64))
 {
 }