public bool VerifyHashedPassword(byte[] decodedHashedPassword, string providedPassword) { // Read header information var prf = (KeyDerivationPrf)BufferUtil.ReadNetworkByteOrder(decodedHashedPassword, 1); var iterCount = (int)BufferUtil.ReadNetworkByteOrder(decodedHashedPassword, 5); var saltLength = (int)BufferUtil.ReadNetworkByteOrder(decodedHashedPassword, 9); // Read the salt: must be >= 128 bits if (saltLength < 128 / 8) { return(false); } var salt = new byte[saltLength]; Buffer.BlockCopy(decodedHashedPassword, 13, salt, 0, salt.Length); // Read the subkey (the rest of the payload): must be >= 128 bits var subkeyLength = decodedHashedPassword.Length - 13 - salt.Length; if (subkeyLength < 128 / 8) { return(false); } var expectedSubkey = new byte[subkeyLength]; Buffer.BlockCopy(decodedHashedPassword, 13 + salt.Length, expectedSubkey, 0, expectedSubkey.Length); // Hash the incoming password and verify it var actualSubKey = KeyDerivation.Pbkdf2(providedPassword, salt, prf, iterCount, subkeyLength); return(iterCount > 0 && BufferUtil.ByteArraysEqual(actualSubKey, expectedSubkey)); }
public void Base64() { var converter = new Base64BinaryConverter(); var str = converter.GetString(TestInput); var bytes = converter.GetBytes(str); var flag = BufferUtil.ByteArraysEqual(TestInput, bytes); Assert.True(flag); }
public bool Equals(byte[] other) { return(BufferUtil.ByteArraysEqual(_source, other)); }