net.bither.bitherj.crypto.SecureCharSequence Java Examples

The following examples show how to use net.bither.bitherj.crypto.SecureCharSequence. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ColdAddressFragmentHDMListItemView.java    From bither-android with Apache License 2.0 6 votes vote down vote up
private void showPublicKeyQrCode(final SecureCharSequence password){
    if(!dp.isShowing()){
        dp.show();
    }
    new Thread(){
        @Override
        public void run() {
            try{
                final String pub = keychain.getExternalChainRootPubExtendedAsHex(password);
                password.wipe();
                post(new Runnable() {
                    @Override
                    public void run() {
                        dp.dismiss();
                        new DialogSimpleQr(getContext(), pub,
                                R.string.hdm_cold_pub_key_qr_code_name).show();
                    }
                });
            } catch (Exception e){
                e.printStackTrace();
            }
        }
    }.start();
}
 
Example #2
Source File: HotAdvanceActivity.java    From bither-android with Apache License 2.0 6 votes vote down vote up
/**
 * end
 */

private void callPassword() {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (PasswordSeed.hasPasswordSeed()) {
                DialogPassword dialogPassword = new DialogPassword(HotAdvanceActivity.this,
                        new IDialogPasswordListener() {
                            @Override
                            public void onPasswordEntered(SecureCharSequence password) {
                                AddressManager addressManager = AddressManager.getInstance();
                                if (addressManager.hasHDAccountHot()) {
                                    addressManager.getHDAccountHot().addSegwitPub(password);
                                }
                                resetTx();
                            }
                        });
                dialogPassword.show();
            } else {
                resetTx();
            }
        }
    });
}
 
Example #3
Source File: SendBitcoinPanel.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
protected void onSend() {
    bitcoinAddress = tfAddress.getText().trim();
    if (Utils.validBicoinAddress(bitcoinAddress)) {
        if (Utils.compareString(bitcoinAddress, changeAddress)) {
            new MessageDialog(LocaliserUtils.getString("select_change_address_change_to_same_warn")).showMsg();
            return;
        }
        String amtString = tfAmt.getText().trim();
        long btc = GenericUtils.toNanoCoins(amtString, 0).longValue();
        try {
            SecureCharSequence secureCharSequence = new SecureCharSequence(currentPassword.getPassword());
            CompleteTransactionRunnable completeTransactionRunnable = new CompleteTransactionRunnable(
                    Bither.getActionAddress(), btc, bitcoinAddress, changeAddress, secureCharSequence);
            completeTransactionRunnable.setRunnableListener(completeTransactionListener);
            new Thread(completeTransactionRunnable).start();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
 
Example #4
Source File: ColdAddressFragmentHDMListItemView.java    From bither-android with Apache License 2.0 6 votes vote down vote up
@Override
protected List<DialogWithActions.Action> getActions() {
    ArrayList<DialogWithActions.Action> actions = new ArrayList<DialogWithActions.Action>();
    actions.add(new DialogWithActions.Action(R.string.hdm_cold_pub_key_qr_code_name, new Runnable() {

        @Override
        public void run() {
            new DialogPassword(getContext(), new IDialogPasswordListener() {
                @Override
                public void onPasswordEntered(SecureCharSequence password) {
                    showPublicKeyQrCode(password);
                }
            }).show();
        }
    }));
    actions.add(new DialogWithActions.Action(R.string.hdm_server_qr_code_name, new Runnable() {

        @Override
        public void run() {
            requestHDMServerQrCode();
        }
    }));
    return actions;
}
 
Example #5
Source File: SplitBCCHDAccountSendActivity.java    From bither-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void validateValues() {
    boolean isValidAmounts = false;
        btcAmount = getAmount(AbstractDb.hdAccountAddressProvider.getUnspentOutputByBlockNo(splitCoin.getForkBlockHeight(),
                AddressManager.getInstance().getHDAccountHot().getHdSeedId()));
    if (btcAmount > 0) {
        isValidAmounts = true;
    }
    toAddress = etAddress.getText().toString().trim();
    boolean isValidAddress = Utils.validSplitBitCoinAddress(toAddress,splitCoin);
    boolean isValidPassword = true;
    if (etPassword.getVisibility() == View.VISIBLE) {
        SecureCharSequence password = new SecureCharSequence(etPassword.getText());
        isValidPassword = Utils.validPassword(password) && password.length() >= 6 &&
                password.length() <= getResources().getInteger(R.integer.password_length_max);
        password.wipe();
    }
    btnSend.setEnabled(isValidAddress && isValidAmounts && isValidPassword);
}
 
Example #6
Source File: BCCAssetsHDAccountMonitoredActivity.java    From bither-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void validateValues() {
    boolean isValidAmounts = false;
    btcAmount = getAmount(outs);
    if (btcAmount > 0) {
        isValidAmounts = true;
    }
    toAddress = etAddress.getText().toString().trim();
    boolean isValidAddress = Utils.validBicoinAddress(toAddress);
    boolean isValidPassword = true;
    if (etPassword.getVisibility() == View.VISIBLE) {
        SecureCharSequence password = new SecureCharSequence(etPassword.getText());
        isValidPassword = Utils.validPassword(password) && password.length() >= 6 &&
                password.length() <= getResources().getInteger(R.integer.password_length_max);
        password.wipe();
    }
    btnSend.setEnabled(isValidAddress && isValidAmounts && isValidPassword);
}
 
Example #7
Source File: BCCAssetsDetectHotActivity.java    From bither-android with Apache License 2.0 6 votes vote down vote up
private void send() {
    try {
        CompleteTransactionRunnable completeRunnable = new
                CompleteTransactionRunnable(addressPosition, btcAmount
                , toAddress, toAddress, new SecureCharSequence(etPassword.getText()), false,outs);
        completeRunnable.setHandler(completeTransactionHandler);
        Thread thread = new Thread(completeRunnable);
        dp.setThread(thread);
        if (!dp.isShowing()) {
            dp.show();
        }
        thread.start();
    } catch (Exception e) {
        e.printStackTrace();
        DropdownMessage.showDropdownMessage(BCCAssetsDetectHotActivity.this,
                R.string.send_failed);
    }
}
 
Example #8
Source File: ImportPrivateKeyPanel.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
@Override
public void onPasswordEntered(SecureCharSequence password) {
    if (password == null) {
        return;
    }

    ImportHDSeedDesktop importHDSeedAndroid = new ImportHDSeedDesktop
            (content, password, new ImportListener() {
                @Override
                public void importSuccess() {

                }
            });
    importHDSeedAndroid.importHDMColdSeed();

}
 
Example #9
Source File: DialogPassword.java    From bither-android with Apache License 2.0 6 votes vote down vote up
@Override
public void afterTextChanged(Editable s) {
    tvError.setVisibility(View.GONE);
    SecureCharSequence p = new SecureCharSequence(etPassword.getText());
    if (p.length() > 0) {
        if (!Utils.validPassword(p)) {
            etPassword.setText(password);
        }
    }
    p.wipe();
    if (etPasswordConfirm.getVisibility() == View.VISIBLE) {
        SecureCharSequence pc = new SecureCharSequence(etPasswordConfirm.getText());
        if (pc.length() > 0) {
            if (!Utils.validPassword(pc)) {
                etPasswordConfirm.setText(passwordConfirm);
            }
        }
        pc.wipe();
    }
    checkValid();
    password.wipe();
    passwordConfirm.wipe();
}
 
Example #10
Source File: CheckUtil.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
public static Check initCheckForHDMKeychain(final HDMKeychain keychain, final SecureCharSequence password) {
    String title = LocaliserUtils.getString("hdm_keychain_check_title_cold");
    if (UserPreference.getInstance().getAppMode() == BitherjSettings.AppMode.HOT) {
        title = LocaliserUtils.getString("hdm_keychain_check_title_hot");
    }
    Check check = new Check(title, new ICheckAction() {
        @Override
        public boolean check() {
            boolean result = false;
            try {
                result = keychain.checkWithPassword(password);
                if (result) {
                    result = keychain.checkSingularBackupWithPassword(password);
                }
                //TODO need to check backup here?
            } catch (Exception e) {
                e.printStackTrace();
            }
            password.wipe();
            return result;
        }
    });
    return check;
}
 
Example #11
Source File: AdvancePanel.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
private void callPassword() {
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            if (PasswordSeed.hasPasswordSeed()) {
                closePanel();
                PasswordPanel dialogPassword = new PasswordPanel(new IDialogPasswordListener() {
                    @Override
                    public void onPasswordEntered(SecureCharSequence password) {
                        resetTx();

                    }
                });
                dialogPassword.showPanel();

            } else {
                resetTx();
            }
        }
    });
}
 
Example #12
Source File: CheckUtil.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
public static Check initCheckForHDAccount(final HDAccount account, final SecureCharSequence
        password) {
    String title = LocaliserUtils.getString("add_hd_account_tab_hd");
    Check check = new Check(title, new ICheckAction() {
        @Override
        public boolean check() {
            boolean result;
            try {
                result = account.checkWithPassword(password);
            } catch (Exception e) {
                result = false;
            }
            password.wipe();
            return result;
        }
    });
    return check;
}
 
Example #13
Source File: SendBitcoinPanel.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
private void validateValues() {
    boolean isValidAmounts = false;

    String amtString = tfAmt.getText().trim();

    if (Utils.isNubmer(amtString)) {
        long btc = GenericUtils.toNanoCoins(amtString, 0).longValue();
        if (btc > 0) {
            isValidAmounts = true;
        } else {
        }
    }
    boolean isValidAddress = Utils.validBicoinAddress(tfAddress.getText().trim());
    SecureCharSequence password = new SecureCharSequence(currentPassword.getPassword());
    boolean isValidPassword = Utils.validPassword(password) && password.length() >= BitherSetting.PASSWORD_LENGTH_MIN &&
            password.length() <= BitherSetting.PASSWORD_LENGTH_MAX;
    password.wipe();
    setOkEnabled(isValidAddress && isValidAmounts && isValidPassword);
}
 
Example #14
Source File: DialogPasswordWithOther.java    From bither-android with Apache License 2.0 6 votes vote down vote up
@Override
public void afterTextChanged(Editable s) {
    tvError.setVisibility(View.GONE);
    SecureCharSequence p = new SecureCharSequence(etPassword.getText());
    if (p.length() > 0) {
        if (!Utils.validPassword(p)) {
            etPassword.setText(password);
        }
    }
    p.wipe();
    if (etPasswordConfirm.getVisibility() == View.VISIBLE) {
        SecureCharSequence pc = new SecureCharSequence(etPasswordConfirm.getText());
        if (pc.length() > 0) {
            if (!Utils.validPassword(pc)) {
                etPasswordConfirm.setText(passwordConfirm);
            }
        }
        pc.wipe();
    }
    checkValid();
    password.wipe();
    passwordConfirm.wipe();
}
 
Example #15
Source File: CheckUtil.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
public static Check initCheckForHDAccount(final HDAccount account, final SecureCharSequence
        password) {
    String title = LocaliserUtils.getString("add_hd_account_tab_hd");
    Check check = new Check(title, new ICheckAction() {
        @Override
        public boolean check() {
            boolean result;
            try {
                result = account.checkWithPassword(password);
            } catch (Exception e) {
                result = false;
            }
            password.wipe();
            return result;
        }
    });
    return check;
}
 
Example #16
Source File: PasswordPanel.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
@Override
public void closePanel() {

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            PasswordPanel.super.closePanel();
            if (listener != null) {
                if (passwordEntered) {

                    listener.onPasswordEntered(new SecureCharSequence(newPassword.getPassword()));
                    newPassword.setText("");
                    repeatNewPassword.setText("");
                } else {
                    listener.onPasswordEntered(null);
                }
            }

        }
    });

}
 
Example #17
Source File: PrivateKeyUtil.java    From bitherj with Apache License 2.0 6 votes vote down vote up
public static String getBIP38PrivateKeyString(Address address, CharSequence password) throws
        AddressFormatException, InterruptedException {
    SecureCharSequence decrypted = getDecryptPrivateKeyString(address.getFullEncryptPrivKey()
            , password);
    String bip38 = Bip38.encryptNoEcMultiply(password, decrypted.toString());
    if (BitherjSettings.DEV_DEBUG) {
        SecureCharSequence d = Bip38.decrypt(bip38, password);
        if (d.equals(decrypted)) {
            log.info("BIP38 right");
        } else {
            throw new RuntimeException("BIP38 wrong " + d.toString() + " , " +
                    "" + decrypted.toString());
        }
    }
    decrypted.wipe();
    return bip38;
}
 
Example #18
Source File: PasswordPanel.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
public SecureCharSequence getPassword() {
    if (password == null) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                if (delegate != null) {
                    delegate.beforePasswordDialogShow();
                }
                PasswordPanel d = new PasswordPanel(PasswordGetter.this);
                d.showPanel();
            }
        });
        try {
            getPasswordLock.lockInterruptibly();
            withPasswordCondition.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            getPasswordLock.unlock();
        }
    }
    return password;
}
 
Example #19
Source File: PasswordPanel.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
public SecureCharSequence getPassword() {
    if (password == null) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                if (delegate != null) {
                    delegate.beforePasswordDialogShow();
                }
                PasswordPanel d = new PasswordPanel(PasswordGetter.this);
                d.showPanel();
            }
        });
        try {
            getPasswordLock.lockInterruptibly();
            withPasswordCondition.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            getPasswordLock.unlock();
        }
    }
    return password;
}
 
Example #20
Source File: ExportPrivateKeyPanel.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
@Override
public void onPasswordEntered(SecureCharSequence password) {
    if (password == null) {
        return;
    }
    switch (btnCurrent) {
        case 0:
            showEncryptQRCode(Bither.getActionAddress().getFullEncryptPrivKey().toUpperCase());
            break;
        case 1:
            showPrivateText(password);
            break;
        case 2:
            showPrivateKeyQRCode(password);
            break;
    }

}
 
Example #21
Source File: HDAccountSendPanel.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
private void send() {
    tx = null;
    HDAccount account = (HDAccount) Bither.getActionAddress();
    SecureCharSequence password = new SecureCharSequence(currentPassword.getPassword());
    try {
        tx = account.newTx(toAddress, btcAmount, password);
    } catch (Exception e) {
        e.printStackTrace();
        btcAmount = 0;
        tx = null;
        String msg = LocaliserUtils.getString("send_failed");
        if (e instanceof KeyCrypterException || e instanceof MnemonicException
                .MnemonicLengthException) {
            msg = LocaliserUtils.getString("password_wrong");
        } else if (e instanceof TxBuilderException) {
            msg = e.getMessage();
        }
        final String m = msg;
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                dp.dispose();
                new MessageDialog(m).showMsg();
            }
        });
    } finally {
        password.wipe();
    }
    if (tx != null) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                showConfirm();
            }
        });
    }
}
 
Example #22
Source File: AddEnterpriseHDMSeedActivity.java    From bither-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onPasswordEntered(final SecureCharSequence password) {
    if (dp != null && !dp.isShowing()) {
        dp.setMessage(R.string.import_private_key_qr_code_importing);
    }
    new ThreadNeedService(dp, AddEnterpriseHDMSeedActivity.this) {

        @Override
        public void runWithService(BlockchainService service) {
            EncryptedData data = new EncryptedData(content.substring(1));
            try {
                EnterpriseHDMSeed seed = new EnterpriseHDMSeed(data.decrypt(new
                        SecureCharSequence(password)), data.isXRandom(), password);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        dp.dismiss();
                        setResult(RESULT_OK);
                        finish();
                    }
                });
            } catch (MnemonicException.MnemonicLengthException e) {
                e.printStackTrace();
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        dp.dismiss();
                        DropdownMessage.showDropdownMessage(AddEnterpriseHDMSeedActivity
                                .this, R.string.enterprise_hdm_seed_add_fail);
                    }
                });
            }
        }
    }.start();
}
 
Example #23
Source File: ExportPrivateKeyPanel.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
private void showPrivateText(SecureCharSequence password) {

        final SecureCharSequence str = PrivateKeyUtil.getDecryptPrivateKeyString(Bither.getActionAddress().getFullEncryptPrivKey(), password);
        password.wipe();
        PrivateTextPanel privateTextPanel = new PrivateTextPanel(str);
        privateTextPanel.showPanel();

    }
 
Example #24
Source File: HDAccountAddPanel.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
private void showHDAccountSeedPhras(final SecureCharSequence password) {
    if (password == null) {
        return;
    }
    new Thread() {
        @Override
        public void run() {
            final List<String> words = new ArrayList<String>();
            try {
                words.addAll(hdAccount.getSeedWords(password));
            } catch (Exception e) {
                e.printStackTrace();

            }
            if (words.size() > 0) {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        HDMSeedPhrasPanel hdmSeedPhrasPanel = new HDMSeedPhrasPanel(words);
                        hdmSeedPhrasPanel.showPanel();

                    }
                });
            }
        }
    }.start();
}
 
Example #25
Source File: BitpieColdSignChangeCoinActivity.java    From bither-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onPasswordEntered(final SecureCharSequence password) {
    Thread thread = new Thread() {
        public void run() {
            final String result = qrCodeBitpieColdSignMessage.getBitherQrCodeStr(password);
            if (Utils.isEmpty(result)) {
                dp.setThread(null);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        dp.dismiss();
                        DropdownMessage.showDropdownMessage(BitpieColdSignChangeCoinActivity.this, R.string.unsigned_transaction_sign_failed);
                    }
                });
                return;
            }
            dp.setThread(null);
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    dp.dismiss();
                    Intent intent = new Intent(BitpieColdSignChangeCoinActivity.this, BitherQRCodeActivity.class);
                    intent.putExtra(BitherSetting.INTENT_REF.QR_CODE_STRING, result);
                    intent.putExtra(BitherSetting.INTENT_REF.TITLE_STRING, getString(R.string.bitpie_signed_change_coin_qr_code_title));
                    intent.putExtra(BitherSetting.INTENT_REF.BITPIE_COLD_SIGN_MESSAGE_TYPE_STRING, qrCodeBitpieColdSignMessage.getSignMessageType().getType());
                    intent.putExtra(BitherSetting.INTENT_REF.BITPIE_COLD_CHANGE_COIN_IS_ONLY_GET_XPUB_STRING, qrCodeBitpieColdSignMessage.isOnlyGetXpub());
                    startActivity(intent);
                    finish();
                }
            });
        }
    };
    dp.setThread(thread);
    thread.start();
    dp.show();
}
 
Example #26
Source File: CheckPrivateKeyPanel.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
@Override
public void onPasswordEntered(SecureCharSequence password) {
    if (password == null) {
        return;
    }
    beginCheck(password);
}
 
Example #27
Source File: PasswordPanel.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
@Override
public void onPasswordEntered(SecureCharSequence password) {
    setPassword(password);
    try {
        getPasswordLock.lock();
        withPasswordCondition.signal();
    } finally {
        getPasswordLock.unlock();
    }
    if (delegate != null && password != null) {
        delegate.afterPasswordDialogDismiss();
    }
}
 
Example #28
Source File: ImportPrivateKeyPanel.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
@Override
public void onPasswordEntered(SecureCharSequence password) {
    if (password == null) {
        return;
    }
    ImportPrivateKeyDesktop importPrivateKey = new ImportPrivateKeyDesktop(
            ImportPrivateKey.ImportPrivateKeyType.Bip38, bip38DecodeString, password);
    importPrivateKey.importPrivateKey();
}
 
Example #29
Source File: EnterpriseHDMSeedActivity.java    From bither-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(final View v) {
    final DialogPassword.PasswordGetter passwordGetter = new DialogPassword
            .PasswordGetter(v.getContext());
    new Thread() {
        @Override
        public void run() {
            SecureCharSequence password = passwordGetter.getPassword();
            if (password == null) {
                return;
            }
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    dp.show();
                }
            });
            final String content = QRCodeUtil.Enterprise_HDM_QR_CODE_FLAG + seed
                    .getEncryptedMnemonicSeed();
            password.wipe();
            passwordGetter.wipe();
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    dp.dismiss();
                    if (content != null) {
                        new DialogSimpleQr(v.getContext(), content, R.string
                                .enterprise_hdm_seed_backup_qr_code_promote).show();
                    }
                }
            });
        }
    }.start();
}
 
Example #30
Source File: CheckUtil.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
public static Check initCheckForPrivateKey(
        final Address address, final SecureCharSequence password) {
    String title = String.format(LocaliserUtils.getString("check_address_private_key_title"), address
            .getShortAddress());
    Check check = new Check(title, new ICheckAction() {

        @Override
        public boolean check() {
            boolean result = new PasswordSeed(address.getAddress(), address.getFullEncryptPrivKey()).checkPassword(password);
            if (!result) {
                try {
                    ECKey eckeyFromBackup = BackupUtil.getEckeyFromBackup(
                            address.getAddress(), password);
                    if (eckeyFromBackup != null) {
                        String encryptPrivateKey = PrivateKeyUtil.getEncryptedString(eckeyFromBackup);
                        if (!Utils.isEmpty(encryptPrivateKey)) {
                            address.recoverFromBackup(encryptPrivateKey);
                            result = true;
                        }
                        eckeyFromBackup.clearPrivateKey();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    password.wipe();
                }


            }
            return result;
        }
    });
    return check;
}