Exemplo n.º 1
0
        /// <summary>
        /// Decrypts a password object and then compares to a string to see if they match.
        /// </summary>
        /// <param name="toCompare">Text to compare to see if it matches the decrypted object.</param>
        /// <param name="toDecrypt">Encrypted password to be decrypted and compared.</param>
        /// <returns>True if there is a match, otherwise false.</returns>
        public bool DecryptCompare(string toCompare, Password toDecrypt)
        {
            if (String.IsNullOrEmpty(toCompare)) 
                return false;

            using (var deriveBytes = new Rfc2898DeriveBytes(toCompare, toDecrypt.Salt, Iterations))
            {
                byte[] newKey = deriveBytes.GetBytes(ByteLength);

                return (newKey.SequenceEqual(toDecrypt.Key));
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Sets the values of PasswordKey & PasswordSalt
 /// using the values from the Password object.
 /// </summary>
 public void SetPassword(Password password)
 {
     PasswordKey = password.Key;
     PasswordSalt = password.Salt;
 }