/// <summary> /// Checks the supplied <paramref name="keyHash"/> against all of the stored passwords to /// see if the hash is valid, and retuns the matching <see cref="Key"/> if a match is found. /// </summary> /// <param name="keyHash">The hex-encoded hash to validate</param> /// <param name="salt">The hex-encoded salt value</param> /// <param name="hashAlgorithm">The <see cref="Cryptography.HashAlgorithmType"/> used to generate the hash</param> /// <param name="encryptionAlgorithm">The <see cref="Cryptography.SymmetricAlgorithmType"/> used by this key to do encryption/decryption</param> /// <param name="matchingKey">Contains the matching <see cref="Key"/> if a match is found</param> /// <returns> /// <c>true</c> if the hash matches one of the stored password/key values; /// <c>false</c> if no match is found /// If no match is found, <paramref name="matchingKey"/> will return <c>null</c>. /// </returns> public bool IsValid(string keyHash, string salt, Cryptography.HashAlgorithmType hashAlgorithm, Cryptography.SymmetricAlgorithmType encryptionAlgorithm, out Key matchingKey) { matchingKey = null; if (String.IsNullOrEmpty(keyHash)) { return(false); } keyHash = keyHash.ToUpper(); foreach (Password password in this.passwords.Values) { bool match = Key.Compare(password.ActualPassword, keyHash, salt, hashAlgorithm, encryptionAlgorithm, out matchingKey); if (match) { return(true); } } return(false); }