Example #1
0
        public static bool VerifyPasswordPbkdf2(string plain, HashAndSalt hashed)
        {
            byte[] newHash = KeyDerivation.Pbkdf2(
                password: plain,
                salt: hashed.Salt,
                prf: KeyDerivationPrf.HMACSHA256,
                iterationCount: IterCount,
                numBytesRequested: HashLenght
                );

            return(SlowEquals(hashed.PasswordHash, newHash));
        }
Example #2
0
        public static HashAndSalt FromBytes(byte[] bytes)
        {
            var res = new HashAndSalt()
            {
                Salt         = new byte[PasswordHelper.SaltLength],
                PasswordHash = new byte[PasswordHelper.HashLenght]
            };

            Array.Copy(bytes, res.PasswordHash, PasswordHelper.HashLenght);
            Array.Copy(bytes, PasswordHelper.HashLenght, res.Salt, 0, PasswordHelper.SaltLength);
            return(res);
        }
Example #3
0
        public static HashAndSalt HashPasswordPbkdf2(string password)
        {
            var res = new HashAndSalt();
            var rng = RandomNumberGenerator.Create();

            res.Salt = new byte[SaltLength];
            rng.GetBytes(res.Salt);

            res.PasswordHash = KeyDerivation.Pbkdf2(
                password: password,
                salt: res.Salt,
                prf: KeyDerivationPrf.HMACSHA256,
                iterationCount: IterCount,
                numBytesRequested: HashLenght
                );

            return(res);
        }
Example #4
0
 public static bool VerifyPasswordPbkdf2(string plain, byte[] hashed)
 {
     return(VerifyPasswordPbkdf2(plain, HashAndSalt.FromBytes(hashed)));
 }
Example #5
0
 public static bool VerifyPasswordPbkdf2(string plain, string hashed)
 {
     return(VerifyPasswordPbkdf2(plain, HashAndSalt.FromString(hashed)));
 }