本文整理汇总了Java中org.bitcoinj.crypto.KeyCrypterException类的典型用法代码示例。如果您正苦于以下问题:Java KeyCrypterException类的具体用法?Java KeyCrypterException怎么用?Java KeyCrypterException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KeyCrypterException类属于org.bitcoinj.crypto包,在下文中一共展示了KeyCrypterException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onSignResult
import org.bitcoinj.crypto.KeyCrypterException; //导入依赖的package包/类
@Override
public void onSignResult(@Nullable Exception error, ExchangeEntry exchangeEntry) {
if (error != null) {
getSupportFragmentManager().popBackStack();
// Ignore wallet decryption errors
if (!(error instanceof KeyCrypterException)) {
DialogBuilder builder = DialogBuilder.warn(this, com.fillerino.wallet.R.string.trade_error);
builder.setMessage(getString(com.fillerino.wallet.R.string.trade_error_sign_tx_message, error.getMessage()));
builder.setPositiveButton(com.fillerino.wallet.R.string.button_ok, null)
.create().show();
}
} else if (exchangeEntry != null) {
getSupportFragmentManager().popBackStack();
replaceFragment(TradeStatusFragment.newInstance(exchangeEntry, true), containerRes);
}
}
示例2: onAddCoinTaskFinished
import org.bitcoinj.crypto.KeyCrypterException; //导入依赖的package包/类
@Override
public void onAddCoinTaskFinished(Exception error, WalletAccount newAccount) {
if (Dialogs.dismissAllowingStateLoss(getFragmentManager(), ADD_COIN_TASK_BUSY_DIALOG_TAG)) return;
if (error != null) {
if (error instanceof KeyCrypterException) {
showPasswordRetryDialog();
} else {
ACRA.getErrorReporter().handleSilentException(error);
Toast.makeText(getActivity(), com.fillerino.wallet.R.string.error_generic, Toast.LENGTH_LONG).show();
}
} else {
destinationAccount = newAccount;
destinationType = newAccount.getCoinType();
onHandleNext();
}
addCoinAndProceedTask = null;
}
示例3: decrypt
import org.bitcoinj.crypto.KeyCrypterException; //导入依赖的package包/类
/**
* Queue a request to decrypt this wallet. This returns immediately, as the
* actual work is done on the network thread in order to ensure the thread
* context is correct. Unhandled errors are reported back to Network.
*
* @param password password to decrypt the wallet with
* @param onSuccess callback on success
* @param onWalletNotEncrypted callback if the wallet is not encrypted
* @param onCrypterError callback in case of an error in the key crypter
* @param timeout timeout on queueing the work request
* @param timeUnit time unit for the timeout
*/
public void decrypt(String password, Consumer<Object> onSuccess,
Consumer<Object> onWalletNotEncrypted,
Consumer<KeyCrypterException> onCrypterError,
final long timeout, final TimeUnit timeUnit) {
this.networkExecutor.execute((Runnable) () -> {
final Wallet wallet = wallet();
if (!wallet.isEncrypted()) {
onCrypterError.accept(null);
} else {
final KeyCrypter keyCrypter = wallet().getKeyCrypter();
if (keyCrypter == null) {
throw new IllegalStateException("Wallet is encrypted but has no key crypter.");
} else {
try {
wallet().decrypt(keyCrypter.deriveKey(password));
encrypted.set(false);
onSuccess.accept(null);
} catch (KeyCrypterException ex) {
onCrypterError.accept(ex);
}
}
}
});
}
示例4: signMessage
import org.bitcoinj.crypto.KeyCrypterException; //导入依赖的package包/类
public static MasternodeSignature signMessage(String strMessage, StringBuilder errorMessage, ECKey key)
{
//ECKey ecKey = ECKey.fromPublicOnly(key.getBytes());
try {
byte dataToHash [] = (Utils.BITCOIN_SIGNED_MESSAGE_HEADER_BYTES+strMessage).getBytes(Charsets.UTF_8);
ECKey.ECDSASignature signature = key.sign(Sha256Hash.twiceOf(dataToHash));
return new MasternodeSignature(signature.encodeToDER());
}
catch (KeyCrypterException x)
{
}
errorMessage.append("Sign failed");
return null;
}
示例5: forwardCoins
import org.bitcoinj.crypto.KeyCrypterException; //导入依赖的package包/类
private static void forwardCoins(Transaction tx) {
try {
Coin value = tx.getValueSentToMe(kit.wallet());
System.out.println("Forwarding " + value.toFriendlyString());
// Now send the coins back! Send with a small fee attached to ensure rapid confirmation.
final Coin amountToSend = value.subtract(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE);
final Wallet.SendResult sendResult = kit.wallet().sendCoins(kit.peerGroup(), forwardingAddress, amountToSend);
checkNotNull(sendResult); // We should never try to send more coins than we have!
System.out.println("Sending ...");
// Register a callback that is invoked when the transaction has propagated across the network.
// This shows a second style of registering ListenableFuture callbacks, it works when you don't
// need access to the object the future returns.
sendResult.broadcastComplete.addListener(new Runnable() {
@Override
public void run() {
// The wallet has changed now, it'll get auto saved shortly or when the app shuts down.
System.out.println("Sent coins onwards! Transaction hash is " + sendResult.tx.getHashAsString());
}
}, MoreExecutors.directExecutor());
} catch (KeyCrypterException | InsufficientMoneyException e) {
// We don't use encrypted wallets in this example - can never happen.
throw new RuntimeException(e);
}
}
示例6: doRaiseFee
import org.bitcoinj.crypto.KeyCrypterException; //导入依赖的package包/类
private void doRaiseFee(final KeyParameter encryptionKey) {
// construct child-pays-for-parent
final TransactionOutput outputToSpend = checkNotNull(findSpendableOutput(wallet, transaction, feeRaise));
final Transaction transactionToSend = new Transaction(Constants.NETWORK_PARAMETERS);
transactionToSend.addInput(outputToSpend);
transactionToSend.addOutput(outputToSpend.getValue().subtract(feeRaise),
wallet.freshAddress(KeyPurpose.CHANGE));
transactionToSend.setPurpose(Transaction.Purpose.RAISE_FEE);
final SendRequest sendRequest = SendRequest.forTx(transactionToSend);
sendRequest.aesKey = encryptionKey;
try {
wallet.signTransaction(sendRequest);
log.info("raise fee: cpfp {}", transactionToSend);
wallet.commitTx(transactionToSend);
application.broadcastTransaction(transactionToSend);
state = State.DONE;
updateView();
dismiss();
} catch (final KeyCrypterException x) {
badPasswordView.setVisibility(View.VISIBLE);
state = State.INPUT;
updateView();
passwordView.requestFocus();
log.info("raise fee: bad spending password");
}
}
示例7: cannotImportEncryptedKey
import org.bitcoinj.crypto.KeyCrypterException; //导入依赖的package包/类
@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));
}
示例8: cannotMixParams
import org.bitcoinj.crypto.KeyCrypterException; //导入依赖的package包/类
@Test(expected = KeyCrypterException.class)
public void cannotMixParams() throws Exception {
chain = chain.toEncrypted("foobar");
KeyCrypterScrypt scrypter = new KeyCrypterScrypt(2); // Some bogus params.
ECKey key1 = new ECKey().encrypt(scrypter, scrypter.deriveKey("other stuff"));
chain.importKeys(key1);
}
示例9: onAddCoinTaskFinished
import org.bitcoinj.crypto.KeyCrypterException; //导入依赖的package包/类
@Override
public void onAddCoinTaskFinished(Exception error, WalletAccount newAccount) {
if (Dialogs.dismissAllowingStateLoss(getSupportFragmentManager(), ADD_COIN_TASK_BUSY_DIALOG_TAG)) return;
addCoinTask = null;
final Intent result = new Intent();
if (error != null) {
if (error instanceof KeyCrypterException) {
new AlertDialog.Builder(this)
.setTitle(getString(com.fillerino.wallet.R.string.unlocking_wallet_error_title))
.setMessage(com.fillerino.wallet.R.string.unlocking_wallet_error_detail)
.setPositiveButton(com.fillerino.wallet.R.string.button_retry, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
showAddCoinDialog();
}
})
.setNegativeButton(com.fillerino.wallet.R.string.button_cancel, null)
.create().show();
} else {
String message = getResources().getString(com.fillerino.wallet.R.string.add_coin_error,
selectedCoin.getName(), error.getMessage());
Toast.makeText(AddCoinsActivity.this, message, Toast.LENGTH_LONG).show();
setResult(RESULT_CANCELED, result);
finish();
}
} else {
result.putExtra(Constants.ARG_ACCOUNT_ID, newAccount.getId());
setResult(RESULT_OK, result);
finish();
}
}
示例10: checkAESKey
import org.bitcoinj.crypto.KeyCrypterException; //导入依赖的package包/类
@Override
public boolean checkAESKey(KeyParameter aesKey) {
checkNotNull(aesKey, "Cannot check null KeyParameter");
checkState(getKeyCrypter() != null, "Key chain not encrypted");
try {
return rootKey.decrypt(aesKey).getPubKeyPoint().equals(rootKey.getPubKeyPoint());
} catch (KeyCrypterException e) {
return false;
}
}
示例11: checkAESKey
import org.bitcoinj.crypto.KeyCrypterException; //导入依赖的package包/类
@Override
public boolean checkAESKey(KeyParameter aesKey) {
checkNotNull(aesKey, "Cannot check null KeyParameter");
checkNotNull(getKeyCrypter(), "Key not encrypted");
try {
return Arrays.equals(publicKey,
Crypto.getPublicKey(entropy.decrypt(aesKey).getPrivKeyBytes()));
} catch (KeyCrypterException e) {
return false;
}
}
示例12: doRaiseFee
import org.bitcoinj.crypto.KeyCrypterException; //导入依赖的package包/类
private void doRaiseFee(final KeyParameter encryptionKey)
{
// construct child-pays-for-parent
final TransactionOutput outputToSpend = checkNotNull(findSpendableOutput(wallet, transaction));
final Transaction transactionToSend = new Transaction(Constants.NETWORK_PARAMETERS);
transactionToSend.addInput(outputToSpend);
transactionToSend.addOutput(outputToSpend.getValue().subtract(FEE_RAISE), wallet.freshAddress(KeyPurpose.CHANGE));
transactionToSend.setPurpose(Transaction.Purpose.RAISE_FEE);
final SendRequest sendRequest = SendRequest.forTx(transactionToSend);
sendRequest.aesKey = encryptionKey;
try
{
wallet.signTransaction(sendRequest);
log.info("raise fee: cpfp {}", transactionToSend);
wallet.commitTx(transactionToSend);
application.broadcastTransaction(transactionToSend);
state = State.DONE;
updateView();
dismiss();
}
catch (final KeyCrypterException x)
{
badPasswordView.setVisibility(View.VISIBLE);
state = State.INPUT;
updateView();
passwordView.requestFocus();
log.info("raise fee: bad spending password");
}
}
示例13: decrypt
import org.bitcoinj.crypto.KeyCrypterException; //导入依赖的package包/类
private static void decrypt() {
if (password == null) {
System.err.println("You must provide a --password");
return;
}
if (!wallet.isEncrypted()) {
System.err.println("This wallet is not encrypted.");
return;
}
try {
wallet.decrypt(password);
} catch (KeyCrypterException e) {
System.err.println("Password incorrect.");
}
}
示例14: decryptWallet
import org.bitcoinj.crypto.KeyCrypterException; //导入依赖的package包/类
public void decryptWallet(BAPassword password) throws NoWalletPasswordException{
if(isWalletEncrypted())
if(password.hasPassword()){
try {
mWalletWrapper.decryptWallet(password.toString());
}
catch(KeyCrypterException returnException) {
throw new NoWalletPasswordException("Illegal Password");
}
LOG.info("Decrypted wallet with password: " + password.toString());
}
else
throw new NoWalletPasswordException("Illegal Password");
}
示例15: checkIfPasswordDecryptsWallet
import org.bitcoinj.crypto.KeyCrypterException; //导入依赖的package包/类
/**
* Will check if the given password can decrypt the wallet.<br>
* If wallet is encrypted, at the end of the check will keep the wallet encrypted.<br>
* If wallet is not encrypted or the password does decrypt the wallet, this will return true;
*
* @param password
* @return
* @throws NoWalletPasswordException
*/
private boolean checkIfPasswordDecryptsWallet(BAPassword password){
if(Authenticator.getWalletOperation().isWalletEncrypted()){
try{
Authenticator.getWalletOperation().decryptWallet(password);
Authenticator.getWalletOperation().encryptWallet(password);
}
catch(KeyCrypterException | NoWalletPasswordException e){
return false;
}
}
return true;
}