public void Validate_WhenGivenIncorrectTextAndHashCombination_ReturnsFalse(int saltByteSize, int hashByteSize, int iterations, char[] delimiter, string text, string correctHash) { var p = new PBKDF2CryptoProvider(saltByteSize, hashByteSize, iterations, delimiter); var valid = p.ValidateHash(text, correctHash); Assert.IsFalse(valid); }
public void Create_WhenGivenValidString_ReturnsHash(int saltByteSize, int hashByteSize, int iterations, char[] delimiter, string text) { var p = new PBKDF2CryptoProvider(saltByteSize, hashByteSize, iterations, delimiter); var hash = p.CreateHash(text); Console.WriteLine("Hash: {0}", hash); Assert.IsNotNullOrEmpty(hash); Assert.AreEqual(3, hash.Split(delimiter).Length); Assert.AreEqual(iterations.ToString(), hash.Split(delimiter)[0]); }
public void Validate_WhenGivenAutoGeneratedString_ReturnsValid(int saltByteSize, int hashByteSize, int iterations, char[] delimiter) { var p = new PBKDF2CryptoProvider(saltByteSize, hashByteSize, iterations, delimiter); var csprng = new RNGCryptoServiceProvider(); var arr = new byte[128]; csprng.GetBytes(arr); var text = Encoding.UTF8.GetString(arr); Console.WriteLine("Text: {0}", text); var hash = p.CreateHash(text); Console.WriteLine("Hash: {0}", hash); var valid = p.ValidateHash(text, hash); Assert.IsTrue(valid); }