/** * A deterministic key is considered to be encrypted if it has access to encrypted private key bytes, OR if its * parent does. The reason is because the parent would be encrypted under the same key and this key knows how to * rederive its own private key bytes from the parent, if needed. */ @Override public boolean isEncrypted() { return priv == null && (super.isEncrypted() || (parent != null && parent.isEncrypted())); }
/** * Creates decrypted private key if needed. */ public ECKey maybeDecrypt(@Nullable KeyParameter aesKey) throws KeyCrypterException { return isEncrypted() && aesKey != null ? decrypt(aesKey) : this; }
/** * Creates decrypted private key if needed. */ public ECKey maybeDecrypt(@Nullable KeyParameter aesKey) throws KeyCrypterException { return isEncrypted() && aesKey != null ? decrypt(aesKey) : this; }
/** * A deterministic key is considered to be encrypted if it has access to encrypted private key bytes, OR if its * parent does. The reason is because the parent would be encrypted under the same key and this key knows how to * rederive its own private key bytes from the parent, if needed. */ @Override public boolean isEncrypted() { return priv == null && (super.isEncrypted() || (parent != null && parent.isEncrypted())); }
/** * Creates decrypted private key if needed. */ public ECKey maybeDecrypt(@Nullable KeyParameter aesKey) throws KeyCrypterException { return isEncrypted() && aesKey != null ? decrypt(aesKey) : this; }
/** Returns true if this key is watch only, meaning it has a public key but no private key. */ public boolean isWatching() { return isPubKeyOnly() && !isEncrypted(); }
/** * Creates decrypted private key if needed. */ public ECKey maybeDecrypt(@Nullable KeyParameter aesKey) throws KeyCrypterException { return isEncrypted() && aesKey != null ? decrypt(aesKey) : this; }
/** * A deterministic key is considered to be encrypted if it has access to encrypted private key bytes, OR if its * parent does. The reason is because the parent would be encrypted under the same key and this key knows how to * rederive its own private key bytes from the parent, if needed. */ @Override public boolean isEncrypted() { return priv == null && (super.isEncrypted() || (parent != null && parent.isEncrypted())); }
/** Imports the given unencrypted keys into the basic chain, encrypting them along the way with the given key. */ public int importKeysAndEncrypt(final List<ECKey> keys, KeyParameter aesKey) { // TODO: Firstly check if the aes key can decrypt any of the existing keys successfully. checkState(keyCrypter != null, "Not encrypted"); LinkedList<ECKey> encryptedKeys = Lists.newLinkedList(); for (ECKey key : keys) { if (key.isEncrypted()) throw new IllegalArgumentException("Cannot provide already encrypted keys"); encryptedKeys.add(key.encrypt(keyCrypter, aesKey)); } return importKeys(encryptedKeys); }
/** Imports the given unencrypted keys into the basic chain, encrypting them along the way with the given key. */ public int importKeysAndEncrypt(final List<ECKey> keys, KeyParameter aesKey) { // TODO: Firstly check if the aes key can decrypt any of the existing keys successfully. checkState(keyCrypter != null, "Not encrypted"); LinkedList<ECKey> encryptedKeys = Lists.newLinkedList(); for (ECKey key : keys) { if (key.isEncrypted()) throw new IllegalArgumentException("Cannot provide already encrypted keys"); encryptedKeys.add(key.encrypt(keyCrypter, aesKey)); } return importKeys(encryptedKeys); }
/** Imports the given unencrypted keys into the basic chain, encrypting them along the way with the given key. */ public int importKeysAndEncrypt(final List<ECKey> keys, KeyParameter aesKey) { // TODO: Firstly check if the aes key can decrypt any of the existing keys successfully. checkState(keyCrypter != null, "Not encrypted"); LinkedList<ECKey> encryptedKeys = Lists.newLinkedList(); for (ECKey key : keys) { if (key.isEncrypted()) throw new IllegalArgumentException("Cannot provide already encrypted keys"); encryptedKeys.add(key.encrypt(keyCrypter, aesKey)); } return importKeys(encryptedKeys); }
@Nullable private ECKey maybeDecrypt(ECKey key) { if (key == null) return null; else if (key.isEncrypted()) { if (aesKey == null) throw new ECKey.KeyIsEncryptedException(); return key.decrypt(aesKey); } else { return key; } }
@Nullable private ECKey maybeDecrypt(ECKey key) { if (key == null) return null; else if (key.isEncrypted()) { if (aesKey == null) throw new ECKey.KeyIsEncryptedException(); return key.decrypt(aesKey); } else { return key; } }
@Nullable private ECKey maybeDecrypt(ECKey key) { if (key == null) return null; else if (key.isEncrypted()) { if (aesKey == null) throw new ECKey.KeyIsEncryptedException(); return key.decrypt(aesKey); } else { return key; } }
@Nullable private ECKey maybeDecrypt(ECKey key) { if (key == null) return null; else if (key.isEncrypted()) { if (aesKey == null) throw new ECKey.KeyIsEncryptedException(); return key.decrypt(aesKey); } else { return key; } }
private void checkKeyEncryptionStateMatches(ECKey key) { if (keyCrypter == null && key.isEncrypted()) throw new KeyCrypterException("Key is encrypted but chain is not"); else if (keyCrypter != null && !key.isEncrypted()) throw new KeyCrypterException("Key is not encrypted but chain is"); else if (keyCrypter != null && key.getKeyCrypter() != null && !key.getKeyCrypter().equals(keyCrypter)) throw new KeyCrypterException("Key encrypted under different parameters to chain"); }
private void checkKeyEncryptionStateMatches(ECKey key) { if (keyCrypter == null && key.isEncrypted()) throw new KeyCrypterException("Key is encrypted but chain is not"); else if (keyCrypter != null && !key.isEncrypted()) throw new KeyCrypterException("Key is not encrypted but chain is"); else if (keyCrypter != null && key.getKeyCrypter() != null && !key.getKeyCrypter().equals(keyCrypter)) throw new KeyCrypterException("Key encrypted under different parameters to chain"); }
private void checkKeyEncryptionStateMatches(ECKey key) { if (keyCrypter == null && key.isEncrypted()) throw new KeyCrypterException("Key is encrypted but chain is not"); else if (keyCrypter != null && !key.isEncrypted()) throw new KeyCrypterException("Key is not encrypted but chain is"); else if (keyCrypter != null && key.getKeyCrypter() != null && !key.getKeyCrypter().equals(keyCrypter)) throw new KeyCrypterException("Key encrypted under different parameters to chain"); }
@Test(expected = KeyCrypterException.class) public void cannotImportEncryptedKey() { final ECKey key1 = new ECKey(); chain.importKeys(ImmutableList.of(key1)); chain = chain.toEncrypted("foobar"); ECKey encryptedKey = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertTrue(encryptedKey.isEncrypted()); BasicKeyChain chain2 = new BasicKeyChain(); chain2.importKeys(ImmutableList.of(encryptedKey)); }
@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()); }