@Test public void matchAnonymousId() throws Exception { PrivateKey k1 = TestKeys.privateKey(0); byte[] id1 = k1.createAnonymousId(); byte[] id12 = k1.createAnonymousId(); PrivateKey k2 = TestKeys.privateKey(1); byte[] id2 = k2.createAnonymousId(); assertEquals(64, id1.length); assertEquals(64, id12.length); assertEquals(64, id2.length); assertFalse(Arrays.equals(id1, id12)); assertFalse(Arrays.equals(id1, id2)); assertFalse(Arrays.equals(id12, id2)); assertTrue(k1.matchAnonymousId(id1)); assertTrue(k1.matchAnonymousId(id12)); assertTrue(k2.matchAnonymousId(id2)); assertFalse(k2.matchAnonymousId(id1)); assertFalse(k2.matchAnonymousId(id12)); assertFalse(k1.matchAnonymousId(id2)); }
public boolean matchAnonymousId(@NonNull byte[] packedId) throws IOException { assert (packedId.length == 64); HMAC hmac = new HMAC(fingerprint()); hmac.update(packedId, 0, 32); byte[] idDigest = Arrays.copyOfRange(packedId, 32, 64); return Arrays.equals(hmac.digest(), idDigest); }
AbstractKey implements Bindable, KeyMatcher { public boolean matchAnonymousId(@NonNull byte[] packedId) throws IOException { assert (packedId.length == 64); HMAC hmac = new HMAC(fingerprint()); hmac.update(packedId, 0, 32); byte[] idDigest = Arrays.copyOfRange(packedId, 32, 64); return Arrays.equals(hmac.digest(), idDigest); } }
AbstractKey implements Bindable, KeyMatcher { public boolean matchAnonymousId(@NonNull byte[] packedId) throws IOException { assert (packedId.length == 64); HMAC hmac = new HMAC(fingerprint()); hmac.update(packedId, 0, 32); byte[] idDigest = Arrays.copyOfRange(packedId, 32, 64); return Arrays.equals(hmac.digest(), idDigest); }  }
AbstractKey implements Bindable, KeyMatcher { public boolean matchAnonymousId(@NonNull byte[] packedId) throws IOException { assert (packedId.length == 64); HMAC hmac = new HMAC(fingerprint()); hmac.update(packedId, 0, 32); byte[] idDigest = Arrays.copyOfRange(packedId, 32, 64); return Arrays.equals(hmac.digest(), idDigest); }  byte[] encrypt(byte[] plain); byte[] decrypt(byte[] plain); byte[] sign(InputStream input, HashType hashType); byte[] sign(byte[] input, HashType hashType); boolean verify(InputStream input, byte[] signature, HashType hashType); boolean verify(byte[] input, byte[] signature, HashType hashType); boolean verify(String input, byte[] signature, HashType hashType); KeyInfo info(); byte[] packedInfo(); byte[] pack(); String packToBase64String(); void unpack(byte[] bytes); boolean canSign(); boolean isPublic(); boolean isPrivate(); AbstractKey getPublicKey(); @Override final Binder toBinder(); @Override final T updateFrom(Binder source); static AbstractKey fromBinder(Binder binder); boolean matchType(AbstractKey other); boolean matchTag(AbstractKey other); void setTag(String tag); void setTag(byte[] tag); @Override String toString(); Capsule.KeySource asKeySource(); byte[] fingerprint(); Digest updateDigestWithKeyComponents(Digest digest); byte[] createAnonymousId(); boolean matchAnonymousId(@NonNull byte[] packedId); KeyAddress address(boolean useSha3_384, int keyMark); final KeyAddress getShortAddress(); final KeyAddress getLongAddress(); @Override boolean isMatchingKey(AbstractKey key); @Override final boolean isMatchingKeyAddress(KeyAddress other); }
AbstractKey implements Bindable, KeyMatcher { public boolean matchAnonymousId(@NonNull byte[] packedId) throws IOException { assert (packedId.length == 64); HMAC hmac = new HMAC(fingerprint()); hmac.update(packedId, 0, 32); byte[] idDigest = Arrays.copyOfRange(packedId, 32, 64); return Arrays.equals(hmac.digest(), idDigest); }  byte[] encrypt(byte[] plain); byte[] decrypt(byte[] plain); byte[] sign(InputStream input, HashType hashType); byte[] sign(byte[] input, HashType hashType); boolean verify(InputStream input, byte[] signature, HashType hashType); boolean verify(byte[] input, byte[] signature, HashType hashType); boolean verify(String input, byte[] signature, HashType hashType); KeyInfo info(); byte[] packedInfo(); byte[] pack(); String packToBase64String(); void unpack(byte[] bytes); boolean canSign(); boolean isPublic(); boolean isPrivate(); AbstractKey getPublicKey(); @Override final Binder toBinder(); @Override final T updateFrom(Binder source); static AbstractKey fromBinder(Binder binder); boolean matchType(AbstractKey other); boolean matchTag(AbstractKey other); void setTag(String tag); void setTag(byte[] tag); @Override String toString(); Capsule.KeySource asKeySource(); byte[] fingerprint(); Digest updateDigestWithKeyComponents(Digest digest); byte[] createAnonymousId(); boolean matchAnonymousId(@NonNull byte[] packedId); KeyAddress address(boolean useSha3_384, int keyMark); final KeyAddress getShortAddress(); final KeyAddress getLongAddress(); @Override boolean isMatchingKey(AbstractKey key); @Override final boolean isMatchingKeyAddress(KeyAddress other); static final int FINGERPRINT_SHA256; static final int FINGERPRINT_SHA384; static final int TYPE_PRIVATE; static final int TYPE_PUBLIC; static final int TYPE_PRIVATE_PASSWORD; static final int TYPE_PRIVATE_PASSWORD_V2; }