public void TestKeyDerivation() { byte[] key = new byte[32]; Arrays.fill(key, 0x02); byte[] result = UnidentifiedAccess.DeriveAccessKeyFrom(key); CollectionAssert.AreEqual(EXPECTED_RESULT, result); }
public bool VerifyUnidentifiedAccess(byte[] theirUnidentifiedAccessVerifier) { if (theirUnidentifiedAccessVerifier == null || theirUnidentifiedAccessVerifier.Length == 0) { return(false); } byte[] unidentifiedAccessKey = UnidentifiedAccess.DeriveAccessKeyFrom(Key); throw new NotImplementedException(); //TODO /* * Mac mac = Mac.getInstance("HmacSHA256"); * mac.init(new SecretKeySpec(unidentifiedAccessKey, "HmacSHA256")); * * byte[] ourUnidentifiedAccessVerifier = mac.doFinal(new byte[32]); * * return MessageDigest.isEqual(theirUnidentifiedAccessVerifier, ourUnidentifiedAccessVerifier); */ }
public bool VerifyUnidentifiedAccess(byte[] theirUnidentifiedAccessVerifier) { try { if (theirUnidentifiedAccessVerifier == null || theirUnidentifiedAccessVerifier.Length == 0) { return(false); } byte[] unidentifiedAccessKey = UnidentifiedAccess.DeriveAccessKeyFrom(key); HMAC mac = new HMACSHA256(unidentifiedAccessKey); byte[] ourUnidentifiedAccessVerifier = mac.ComputeHash(new byte[32]); return(Enumerable.SequenceEqual(theirUnidentifiedAccessVerifier, ourUnidentifiedAccessVerifier)); } catch (InvalidKeyException ex) { throw new ArgumentException(null, ex); } }