/** * Encrypt the wallet using the KeyCrypter and the AES key. A good default KeyCrypter to use is * {@link org.bitcoinj.crypto.KeyCrypterScrypt}. * * @param keyCrypter The KeyCrypter that specifies how to encrypt/ decrypt a key * @param aesKey AES key to use (normally created using KeyCrypter#deriveKey and cached as it is time consuming to create from a password) * @throws KeyCrypterException Thrown if the wallet encryption fails. If so, the wallet state is unchanged. */ public void encrypt(KeyCrypter keyCrypter, KeyParameter aesKey) { keyChainGroupLock.lock(); try { keyChainGroup.encrypt(keyCrypter, aesKey); } finally { keyChainGroupLock.unlock(); } saveNow(); }
/** * Encrypt the wallet using the KeyCrypter and the AES key. A good default KeyCrypter to use is * {@link org.bitcoinj.crypto.KeyCrypterScrypt}. * * @param keyCrypter The KeyCrypter that specifies how to encrypt/ decrypt a key * @param aesKey AES key to use (normally created using KeyCrypter#deriveKey and cached as it is time consuming to create from a password) * @throws KeyCrypterException Thrown if the wallet encryption fails. If so, the wallet state is unchanged. */ public void encrypt(KeyCrypter keyCrypter, KeyParameter aesKey) { keyChainGroupLock.lock(); try { keyChainGroup.encrypt(keyCrypter, aesKey); } finally { keyChainGroupLock.unlock(); } saveNow(); }
/** * Encrypt the wallet using the KeyCrypter and the AES key. A good default KeyCrypter to use is * {@link org.bitcoinj.crypto.KeyCrypterScrypt}. * * @param keyCrypter The KeyCrypter that specifies how to encrypt/ decrypt a key * @param aesKey AES key to use (normally created using KeyCrypter#deriveKey and cached as it is time consuming to create from a password) * @throws KeyCrypterException Thrown if the wallet encryption fails. If so, the wallet state is unchanged. */ public void encrypt(KeyCrypter keyCrypter, KeyParameter aesKey) { keyChainGroupLock.lock(); try { keyChainGroup.encrypt(keyCrypter, aesKey); } finally { keyChainGroupLock.unlock(); } saveNow(); }
/** * Encrypt the wallet using the KeyCrypter and the AES key. A good default KeyCrypter to use is * {@link org.bitcoinj.crypto.KeyCrypterScrypt}. * * @param keyCrypter The KeyCrypter that specifies how to encrypt/ decrypt a key * @param aesKey AES key to use (normally created using KeyCrypter#deriveKey and cached as it is time consuming to create from a password) * @throws KeyCrypterException Thrown if the wallet encryption fails. If so, the wallet state is unchanged. */ public void encrypt(KeyCrypter keyCrypter, KeyParameter aesKey) { keyChainGroupLock.lock(); try { keyChainGroup.encrypt(keyCrypter, aesKey); } finally { keyChainGroupLock.unlock(); } saveNow(); }
/** * Convenience wrapper around {@link Wallet#encrypt(org.bitcoinj.crypto.KeyCrypter, * org.spongycastle.crypto.params.KeyParameter)} which uses the default Scrypt key derivation algorithm and * parameters to derive a key from the given password. */ public void encrypt(CharSequence password) { keyChainGroupLock.lock(); try { final KeyCrypterScrypt scrypt = new KeyCrypterScrypt(); keyChainGroup.encrypt(scrypt, scrypt.deriveKey(password)); } finally { keyChainGroupLock.unlock(); } saveNow(); }
/** * Convenience wrapper around {@link Wallet#encrypt(org.bitcoinj.crypto.KeyCrypter, * org.spongycastle.crypto.params.KeyParameter)} which uses the default Scrypt key derivation algorithm and * parameters to derive a key from the given password. */ public void encrypt(CharSequence password) { keyChainGroupLock.lock(); try { final KeyCrypterScrypt scrypt = new KeyCrypterScrypt(); keyChainGroup.encrypt(scrypt, scrypt.deriveKey(password)); } finally { keyChainGroupLock.unlock(); } saveNow(); }
/** * Convenience wrapper around {@link Wallet#encrypt(org.bitcoinj.crypto.KeyCrypter, * org.spongycastle.crypto.params.KeyParameter)} which uses the default Scrypt key derivation algorithm and * parameters to derive a key from the given password. */ public void encrypt(CharSequence password) { keyChainGroupLock.lock(); try { final KeyCrypterScrypt scrypt = new KeyCrypterScrypt(); keyChainGroup.encrypt(scrypt, scrypt.deriveKey(password)); } finally { keyChainGroupLock.unlock(); } saveNow(); }
/** * Convenience wrapper around {@link Wallet#encrypt(org.bitcoinj.crypto.KeyCrypter, * org.spongycastle.crypto.params.KeyParameter)} which uses the default Scrypt key derivation algorithm and * parameters to derive a key from the given password. */ public void encrypt(CharSequence password) { keyChainGroupLock.lock(); try { final KeyCrypterScrypt scrypt = new KeyCrypterScrypt(); keyChainGroup.encrypt(scrypt, scrypt.deriveKey(password)); } finally { keyChainGroupLock.unlock(); } saveNow(); }
@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()); }
group.encrypt(scrypt, aesKey); List<Protos.Key> protoKeys3 = group.serializeToProtobuf(); group = KeyChainGroup.fromProtobufEncrypted(PARAMS, protoKeys3, scrypt);
@Test public void deterministicUpgradeEncrypted() throws Exception { group = new KeyChainGroup(PARAMS); final ECKey key = new ECKey(); group.importKeys(key); final KeyCrypterScrypt crypter = new KeyCrypterScrypt(); final KeyParameter aesKey = crypter.deriveKey("abc"); assertTrue(group.isDeterministicUpgradeRequired()); group.encrypt(crypter, aesKey); assertTrue(group.isDeterministicUpgradeRequired()); try { group.upgradeToDeterministic(0, null); fail(); } catch (DeterministicUpgradeRequiresPassword e) { // Expected. } group.upgradeToDeterministic(0, aesKey); assertFalse(group.isDeterministicUpgradeRequired()); final DeterministicSeed deterministicSeed = group.getActiveKeyChain().getSeed(); assertNotNull(deterministicSeed); assertTrue(deterministicSeed.isEncrypted()); byte[] entropy = checkNotNull(group.getActiveKeyChain().toDecrypted(aesKey).getSeed()).getEntropyBytes(); // Check we used the right key: oldest non rotating. byte[] truncatedBytes = Arrays.copyOfRange(key.getSecretBytes(), 0, 16); assertArrayEquals(entropy, truncatedBytes); }
group.encrypt(scrypt, aesKey); assertTrue(group.isEncrypted()); assertTrue(group.checkPassword("password"));