/** * Locates a keypair from the basicKeyChain given the raw public key bytes. * @return ECKey or null if no such key was found. */ @Override @Nullable public ECKey findKeyFromPubKey(byte[] pubkey) { keyChainGroupLock.lock(); try { return keyChainGroup.findKeyFromPubKey(pubkey); } finally { keyChainGroupLock.unlock(); } }
/** * Locates a keypair from the basicKeyChain given the raw public key bytes. * @return ECKey or null if no such key was found. */ @Override @Nullable public ECKey findKeyFromPubKey(byte[] pubkey) { keyChainGroupLock.lock(); try { return keyChainGroup.findKeyFromPubKey(pubkey); } finally { keyChainGroupLock.unlock(); } }
/** * Locates a keypair from the basicKeyChain given the raw public key bytes. * @return ECKey or null if no such key was found. */ @Override @Nullable public ECKey findKeyFromPubKey(byte[] pubkey) { keyChainGroupLock.lock(); try { return keyChainGroup.findKeyFromPubKey(pubkey); } finally { keyChainGroupLock.unlock(); } }
/** * Locates a keypair from the basicKeyChain given the raw public key bytes. * @return ECKey or null if no such key was found. */ @Override @Nullable public ECKey findKeyFromPubKey(byte[] pubkey) { keyChainGroupLock.lock(); try { return keyChainGroup.findKeyFromPubKey(pubkey); } finally { keyChainGroupLock.unlock(); } }
@Test public void encryptionWhilstEmpty() throws Exception { group = new KeyChainGroup(PARAMS); group.setLookaheadSize(5); KeyCrypterScrypt scrypt = new KeyCrypterScrypt(2); final KeyParameter aesKey = scrypt.deriveKey("password"); group.encrypt(scrypt, aesKey); assertTrue(group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS).isEncrypted()); final ECKey key = group.currentKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); group.decrypt(aesKey); assertFalse(checkNotNull(group.findKeyFromPubKey(key.getPubKey())).isEncrypted()); }
@Test public void findKey() throws Exception { ECKey a = group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); ECKey b = group.freshKey(KeyChain.KeyPurpose.CHANGE); ECKey c = new ECKey(); ECKey d = new ECKey(); // Not imported. group.importKeys(c); assertTrue(group.hasKey(a)); assertTrue(group.hasKey(b)); assertTrue(group.hasKey(c)); assertFalse(group.hasKey(d)); ECKey result = group.findKeyFromPubKey(a.getPubKey()); assertEquals(a, result); result = group.findKeyFromPubKey(b.getPubKey()); assertEquals(b, result); result = group.findKeyFromPubHash(a.getPubKeyHash()); assertEquals(a, result); result = group.findKeyFromPubHash(b.getPubKeyHash()); assertEquals(b, result); result = group.findKeyFromPubKey(c.getPubKey()); assertEquals(c, result); result = group.findKeyFromPubHash(c.getPubKeyHash()); assertEquals(c, result); assertNull(group.findKeyFromPubKey(d.getPubKey())); assertNull(group.findKeyFromPubHash(d.getPubKeyHash())); }
assertTrue(group.checkPassword("password")); assertFalse(group.checkPassword("wrong password")); final ECKey ea = group.findKeyFromPubKey(a.getPubKey()); assertTrue(checkNotNull(ea).isEncrypted()); if (withImported) { assertTrue(checkNotNull(group.findKeyFromPubKey(b.getPubKey())).isEncrypted()); assertEquals(yesterday, group.getEarliestKeyCreationTime()); } else { ECKey ec = group.findKeyFromPubKey(c.getPubKey()); try { group.importKeysAndEncrypt(ImmutableList.of(ec), aesKey); assertFalse(checkNotNull(group.findKeyFromPubKey(a.getPubKey())).isEncrypted()); if (withImported) { assertFalse(checkNotNull(group.findKeyFromPubKey(b.getPubKey())).isEncrypted()); assertEquals(yesterday, group.getEarliestKeyCreationTime()); } else {