private void updateView() { if (seedInfo != null) { seedLayout.setVisibility(View.VISIBLE); seedEncryptedLayout.setVisibility(View.GONE); seedView.setText(seedInfo.seedString); QrUtils.setQr(qrView, getResources(), seedInfo.seedString); if (seedInfo.isSeedPasswordProtected) { seedPasswordProtectedView.setVisibility(View.VISIBLE); } else { seedPasswordProtectedView.setVisibility(View.GONE); } } else if (wallet != null) { if (wallet.getSeed() == null) { if (listener != null) listener.onSeedNotAvailable(); } else if (wallet.getSeed().isEncrypted()) { seedEncryptedLayout.setVisibility(View.VISIBLE); if (password == null) { showUnlockDialog(); } else { maybeStartDecryptTask(); } } else { seedEncryptedLayout.setVisibility(View.GONE); maybeStartDecryptTask(); } } }
KeyParameter aesKey = null; DeterministicKey masterKey = null; DeterministicSeed seed = wallet.getSeed(); if (seed != null) { try { KeyCrypter crypter = wallet.getKeyCrypter(); aesKey = crypter.deriveKey(password); seed = wallet.getSeed().decrypt(crypter, password.toString(), aesKey); masterKey = wallet.getMasterKey().decrypt(crypter, aesKey); } else {
@Test public void serializeEncryptedNormal() throws Exception { wallet.maybeInitializeAllPockets(); wallet.encrypt(crypter, aesKey); assertNull(wallet.getSeed().getMnemonicCode()); Protos.Wallet walletProto = wallet.toProtobuf(); Wallet newWallet = WalletProtobufSerializer.readWallet(walletProto); assertEquals(walletProto.toString(), newWallet.toProtobuf().toString()); wallet.decrypt(aesKey); // One is encrypted, so they should not match assertNotEquals(wallet.toProtobuf().toString(), newWallet.toProtobuf().toString()); newWallet.decrypt(aesKey); assertEquals(wallet.toProtobuf().toString(), newWallet.toProtobuf().toString()); assertArrayEquals(MNEMONIC.toArray(), newWallet.getMnemonicCode().toArray()); }