• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java KeyCrypterException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.bitcoinj.crypto.KeyCrypterException的典型用法代码示例。如果您正苦于以下问题:Java KeyCrypterException类的具体用法?Java KeyCrypterException怎么用?Java KeyCrypterException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



KeyCrypterException类属于org.bitcoinj.crypto包,在下文中一共展示了KeyCrypterException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
    }
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:17,代码来源:TradeActivity.java


示例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;
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:19,代码来源:TradeSelectFragment.java


示例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);
                }
            }
        }
    });
}
 
开发者ID:rnicoll,项目名称:cate,代码行数:38,代码来源:Network.java


示例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;
}
 
开发者ID:HashEngineering,项目名称:dashj,代码行数:19,代码来源:DarkSendSigner.java


示例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);
    }
}
 
开发者ID:bitcoinj,项目名称:bitcoinj,代码行数:25,代码来源:ForwardingService.java


示例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");
    }
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:36,代码来源:RaiseFeeDialogFragment.java


示例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));
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:12,代码来源:BasicKeyChainTest.java


示例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);
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:8,代码来源:BasicKeyChainTest.java


示例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();
    }

}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:33,代码来源:AddCoinsActivity.java


示例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;
    }
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:11,代码来源:SimpleHDKeyChain.java


示例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;
    }
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:12,代码来源:NxtFamilyKey.java


示例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");
    }
}
 
开发者ID:soapboxsys,项目名称:ombuds-android,代码行数:39,代码来源:RaiseFeeDialogFragment.java


示例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.");
    }
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:16,代码来源:WalletTool.java


示例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");
}
 
开发者ID:BitcoinAuthenticator,项目名称:Wallet,代码行数:15,代码来源:WalletOperation.java


示例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;
}
 
开发者ID:BitcoinAuthenticator,项目名称:Wallet,代码行数:23,代码来源:Controller.java


示例16: 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.sameThreadExecutor());

        //MasternodeDB.dumpMasternodes();
        FlatDB<MasternodeManager> mndb = new FlatDB<MasternodeManager>(kit.directory().getAbsolutePath(),"mncache.dat", "magicMasternodeCache");
        mndb.dump(Context.get().masternodeManager);
    } catch (KeyCrypterException | InsufficientMoneyException e) {
        // We don't use encrypted wallets in this example - can never happen.
        throw new RuntimeException(e);
    }
}
 
开发者ID:HashEngineering,项目名称:dashj,代码行数:29,代码来源:ForwardingService.java


示例17: deriveKey

import org.bitcoinj.crypto.KeyCrypterException; //导入依赖的package包/类
public final void deriveKey(final Wallet wallet, final String password) {
    checkState(wallet.isEncrypted());
    final KeyCrypter keyCrypter = checkNotNull(wallet.getKeyCrypter());

    backgroundHandler.post(new Runnable() {
        @Override
        public void run() {
            org.bitcoinj.core.Context.propagate(Constants.CONTEXT);

            // Key derivation takes time.
            KeyParameter key = keyCrypter.deriveKey(password);
            boolean wasChanged = false;

            // If the key isn't derived using the desired parameters, derive a new key.
            if (keyCrypter instanceof KeyCrypterScrypt) {
                final long scryptIterations = ((KeyCrypterScrypt) keyCrypter).getScryptParameters().getN();

                if (scryptIterations != scryptIterationsTarget) {
                    log.info("upgrading scrypt iterations from {} to {}; re-encrypting wallet", scryptIterations,
                            scryptIterationsTarget);

                    final KeyCrypterScrypt newKeyCrypter = new KeyCrypterScrypt(scryptIterationsTarget);
                    final KeyParameter newKey = newKeyCrypter.deriveKey(password);

                    // Re-encrypt wallet with new key.
                    try {
                        wallet.changeEncryptionKey(newKeyCrypter, key, newKey);
                        key = newKey;
                        wasChanged = true;
                        log.info("scrypt upgrade succeeded");
                    } catch (final KeyCrypterException x) {
                        log.info("scrypt upgrade failed: {}", x.getMessage());
                    }
                }
            }

            // Hand back the (possibly changed) encryption key.
            final KeyParameter keyToReturn = key;
            final boolean keyToReturnWasChanged = wasChanged;
            callbackHandler.post(new Runnable() {
                @Override
                public void run() {
                    onSuccess(keyToReturn, keyToReturnWasChanged);
                }
            });
        }
    });
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:49,代码来源:DeriveKeyTask.java


示例18: handleGo

import org.bitcoinj.crypto.KeyCrypterException; //导入依赖的package包/类
private void handleGo() {
    final String oldPassword = Strings.emptyToNull(oldPasswordView.getText().toString().trim());
    final String newPassword = Strings.emptyToNull(newPasswordView.getText().toString().trim());

    if (oldPassword != null && newPassword != null)
        log.info("changing spending password");
    else if (newPassword != null)
        log.info("setting spending password");
    else if (oldPassword != null)
        log.info("removing spending password");
    else
        throw new IllegalStateException();

    state = State.CRYPTING;
    updateView();

    backgroundHandler.post(new Runnable() {
        @Override
        public void run() {
            // For the old key, we use the key crypter that was used to derive the password in the first
            // place.
            final KeyParameter oldKey = oldPassword != null ? wallet.getKeyCrypter().deriveKey(oldPassword) : null;

            // For the new key, we create a new key crypter according to the desired parameters.
            final KeyCrypterScrypt keyCrypter = new KeyCrypterScrypt(application.scryptIterationsTarget());
            final KeyParameter newKey = newPassword != null ? keyCrypter.deriveKey(newPassword) : null;

            handler.post(new Runnable() {
                @Override
                public void run() {
                    if (wallet.isEncrypted()) {
                        if (oldKey == null) {
                            log.info("wallet is encrypted, but did not provide spending password");
                            state = State.INPUT;
                            oldPasswordView.requestFocus();
                        } else {
                            try {
                                wallet.decrypt(oldKey);

                                state = State.DONE;
                                log.info("wallet successfully decrypted");
                            } catch (final KeyCrypterException x) {
                                log.info("wallet decryption failed: " + x.getMessage());
                                badPasswordView.setVisibility(View.VISIBLE);
                                state = State.INPUT;
                                oldPasswordView.requestFocus();
                            }
                        }
                    }

                    if (newKey != null && !wallet.isEncrypted()) {
                        wallet.encrypt(keyCrypter, newKey);

                        log.info(
                                "wallet successfully encrypted, using key derived by new spending password ({} scrypt iterations)",
                                keyCrypter.getScryptParameters().getN());
                        state = State.DONE;
                    }

                    updateView();

                    if (state == State.DONE) {
                        application.backupWallet();
                        delayedDismiss();
                    }
                }

                private void delayedDismiss() {
                    handler.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            dismiss();
                        }
                    }, 2000);
                }
            });
        }
    });
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:80,代码来源:EncryptKeysDialogFragment.java


示例19: handleGo

import org.bitcoinj.crypto.KeyCrypterException; //导入依赖的package包/类
private void handleGo()
{
    final boolean isEncrypted = wallet.isEncrypted();
    final String oldPassword = oldPasswordView.getText().toString().trim();
    final String password = newPasswordView.getText().toString().trim();

    state = State.CRYPTING;
    updateView();

    backgroundHandler.post(new Runnable()
    {
        @Override
        public void run()
        {
            final byte[] salt = new byte[KeyCrypterScrypt.SALT_LENGTH];
            new SecureRandom().nextBytes(salt);
            final KeyCrypter keyCrypter = new KeyCrypterScrypt(Protos.ScryptParameters.newBuilder().setSalt(ByteString.copyFrom(salt))
                    .setN(SCRYPT_ITERATIONS).build());

            final KeyParameter oldKey = isEncrypted ? wallet.getKeyCrypter().deriveKey(oldPassword) : null;

            final KeyParameter newKey = password.isEmpty() ? null : keyCrypter.deriveKey(password);

            handler.post(new Runnable()
            {
                @Override
                public void run()
                {
                    try
                    {
                        if (oldKey != null)
                            wallet.decrypt(oldKey);

                        if (newKey != null)
                            wallet.encrypt(keyCrypter, newKey);

                        application.backupWallet();

                        state = State.DONE;
                        updateView();

                        log.info("spending password set or changed");

                        delayedDismiss();
                    }
                    catch (final KeyCrypterException x)
                    {
                        badPasswordView.setVisibility(View.VISIBLE);

                        state = State.INPUT;
                        updateView();

                        oldPasswordView.requestFocus();

                        log.info("remove or change of spending password failed");
                    }
                }

                private void delayedDismiss()
                {
                    handler.postDelayed(new Runnable()
                    {
                        @Override
                        public void run()
                        {
                            dismiss();
                        }
                    }, 2000);
                }
            });
        }
    });
}
 
开发者ID:soapboxsys,项目名称:ombuds-android,代码行数:74,代码来源:EncryptKeysDialogFragment.java


示例20: importKey

import org.bitcoinj.crypto.KeyCrypterException; //导入依赖的package包/类
private static void importKey() {
    ECKey key;
    long creationTimeSeconds = getCreationTimeSeconds();
    if (options.has("privkey")) {
        String data = (String) options.valueOf("privkey");
        if (data.startsWith("5J") || data.startsWith("5H") || data.startsWith("5K")) {
            DumpedPrivateKey dpk;
            try {
                dpk = new DumpedPrivateKey(params, data);
            } catch (AddressFormatException e) {
                System.err.println("Could not parse dumped private key " + data);
                return;
            }
            key = dpk.getKey();
        } else {
            byte[] decode = Utils.parseAsHexOrBase58(data);
            if (decode == null) {
                System.err.println("Could not understand --privkey as either hex or base58: " + data);
                return;
            }
            key = ECKey.fromPrivate(new BigInteger(1, decode));
        }
        if (options.has("pubkey")) {
            // Give the user a hint.
            System.out.println("You don't have to specify --pubkey when a private key is supplied.");
        }
        key.setCreationTimeSeconds(creationTimeSeconds);
    } else if (options.has("pubkey")) {
        byte[] pubkey = Utils.parseAsHexOrBase58((String) options.valueOf("pubkey"));
        key = ECKey.fromPublicOnly(pubkey);
        key.setCreationTimeSeconds(creationTimeSeconds);
    } else {
        throw new IllegalStateException();
    }
    if (wallet.findKeyFromPubKey(key.getPubKey()) != null) {
        System.err.println("That key already exists in this wallet.");
        return;
    }
    try {
        if (wallet.isEncrypted()) {
            KeyParameter aesKey = passwordToKey(true);
            if (aesKey == null)
                return;   // Error message already printed.
            key = key.encrypt(checkNotNull(wallet.getKeyCrypter()), aesKey);
        }
        wallet.importKey(key);
        System.out.println(key.toAddress(params) + " " + key);
    } catch (KeyCrypterException kce) {
        System.err.println("There was an encryption related error when adding the key. The error was '" + kce.getMessage() + "'.");
    }
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:52,代码来源:WalletTool.java



注:本文中的org.bitcoinj.crypto.KeyCrypterException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ConversionException类代码示例发布时间:2022-05-22
下一篇:
Java JobCommitCompletedEvent类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap