@Override public DeterministicKey decrypt(KeyParameter aesKey) throws KeyCrypterException { return (DeterministicKey) super.decrypt(aesKey); }
@Override public DeterministicKey decrypt(KeyParameter aesKey) throws KeyCrypterException { return (DeterministicKey) super.decrypt(aesKey); }
@Override public DeterministicKey decrypt(KeyParameter aesKey) throws KeyCrypterException { return (DeterministicKey) super.decrypt(aesKey); }
@Override public DeterministicKey decrypt(KeyParameter aesKey) throws KeyCrypterException { return (DeterministicKey) super.decrypt(aesKey); }
/** * 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; }
/** * 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; }
@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; } }
/** * Create a decrypted private key with AES key. Note that if the AES key is wrong, this * has some chance of throwing KeyCrypterException due to the corrupted padding that will result, but it can also * just yield a garbage key. * * @param aesKey The KeyParameter with the AES encryption key (usually constructed with keyCrypter#deriveKey and cached). */ public ECKey decrypt(KeyParameter aesKey) throws KeyCrypterException { final KeyCrypter crypter = getKeyCrypter(); if (crypter == null) throw new KeyCrypterException("No key crypter available"); return decrypt(crypter, aesKey); }
/** * Create a decrypted private key with AES key. Note that if the AES key is wrong, this * has some chance of throwing KeyCrypterException due to the corrupted padding that will result, but it can also * just yield a garbage key. * * @param aesKey The KeyParameter with the AES encryption key (usually constructed with keyCrypter#deriveKey and cached). */ public ECKey decrypt(KeyParameter aesKey) throws KeyCrypterException { final KeyCrypter crypter = getKeyCrypter(); if (crypter == null) throw new KeyCrypterException("No key crypter available"); return decrypt(crypter, aesKey); }
/** * Create a decrypted private key with AES key. Note that if the AES key is wrong, this * has some chance of throwing KeyCrypterException due to the corrupted padding that will result, but it can also * just yield a garbage key. * * @param aesKey The KeyParameter with the AES encryption key (usually constructed with keyCrypter#deriveKey and cached). */ public ECKey decrypt(KeyParameter aesKey) throws KeyCrypterException { final KeyCrypter crypter = getKeyCrypter(); if (crypter == null) throw new KeyCrypterException("No key crypter available"); return decrypt(crypter, aesKey); }
/** * Create a decrypted private key with AES key. Note that if the AES key is wrong, this * has some chance of throwing KeyCrypterException due to the corrupted padding that will result, but it can also * just yield a garbage key. * * @param aesKey The KeyParameter with the AES encryption key (usually constructed with keyCrypter#deriveKey and cached). */ public ECKey decrypt(KeyParameter aesKey) throws KeyCrypterException { final KeyCrypter crypter = getKeyCrypter(); if (crypter == null) throw new KeyCrypterException("No key crypter available"); return decrypt(crypter, aesKey); }
@Override public BasicKeyChain toDecrypted(KeyParameter aesKey) { lock.lock(); try { checkState(keyCrypter != null, "Wallet is already decrypted"); // Do an up-front check. if (numKeys() > 0 && !checkAESKey(aesKey)) throw new KeyCrypterException("Password/key was incorrect."); BasicKeyChain decrypted = new BasicKeyChain(); for (ECKey key : hashToKeys.values()) { decrypted.importKeyLocked(key.decrypt(aesKey)); } return decrypted; } finally { lock.unlock(); } }
@Override public BasicKeyChain toDecrypted(KeyParameter aesKey) { lock.lock(); try { checkState(keyCrypter != null, "Wallet is already decrypted"); // Do an up-front check. if (numKeys() > 0 && !checkAESKey(aesKey)) throw new KeyCrypterException("Password/key was incorrect."); BasicKeyChain decrypted = new BasicKeyChain(); for (ECKey key : hashToKeys.values()) { decrypted.importKeyLocked(key.decrypt(aesKey)); } return decrypted; } finally { lock.unlock(); } }
@Test public void testEncryptedCreate() throws Exception { ECKey unencryptedKey = new ECKey(); byte[] originalPrivateKeyBytes = checkNotNull(unencryptedKey.getPrivKeyBytes()); log.info("Original private key = " + Utils.HEX.encode(originalPrivateKeyBytes)); EncryptedData encryptedPrivateKey = keyCrypter.encrypt(unencryptedKey.getPrivKeyBytes(), keyCrypter.deriveKey(PASSWORD1)); ECKey encryptedKey = ECKey.fromEncrypted(encryptedPrivateKey, keyCrypter, unencryptedKey.getPubKey()); assertTrue(encryptedKey.isEncrypted()); assertNull(encryptedKey.getSecretBytes()); ECKey rebornUnencryptedKey = encryptedKey.decrypt(keyCrypter.deriveKey(PASSWORD1)); assertTrue(!rebornUnencryptedKey.isEncrypted()); assertArrayEquals(originalPrivateKeyBytes, rebornUnencryptedKey.getPrivKeyBytes()); }
@Test public void testUnencryptedCreate() throws Exception { Utils.setMockClock(); ECKey key = new ECKey(); long time = key.getCreationTimeSeconds(); assertNotEquals(0, time); assertTrue(!key.isEncrypted()); byte[] originalPrivateKeyBytes = key.getPrivKeyBytes(); ECKey encryptedKey = key.encrypt(keyCrypter, keyCrypter.deriveKey(PASSWORD1)); assertEquals(time, encryptedKey.getCreationTimeSeconds()); assertTrue(encryptedKey.isEncrypted()); assertNull(encryptedKey.getSecretBytes()); key = encryptedKey.decrypt(keyCrypter.deriveKey(PASSWORD1)); assertTrue(!key.isEncrypted()); assertArrayEquals(originalPrivateKeyBytes, key.getPrivKeyBytes()); }