net.bither.bitherj.utils.PrivateKeyUtil Java Examples

The following examples show how to use net.bither.bitherj.utils.PrivateKeyUtil. 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: BackupUtil.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
private void backupPrivateKey() {
    File file = FileUtil.getBackupFile();

    String backupString = PrivateKeyUtil.getBackupPrivateKeyStr();


    if (!Utils.isEmpty(backupString)) {

        try {
            Utils.writeFile(backupString.getBytes(), file);
            UserPreference.getInstance().setLastBackupKeyTime(
                    new Date(System.currentTimeMillis()));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
 
Example #2
Source File: ImportPrivateKey.java    From bitherj with Apache License 2.0 6 votes vote down vote up
private ECKey getEckey() {
    ECKey ecKey = null;
    DumpedPrivateKey dumpedPrivateKey = null;
    try {
        switch (this.importPrivateKeyType) {
            case Text:
                dumpedPrivateKey = new DumpedPrivateKey(this.content);
                ecKey = dumpedPrivateKey.getKey();
                break;
            case BitherQrcode:
                ecKey = PrivateKeyUtil.getECKeyFromSingleString(content, password);
                break;
            case Bip38:
                dumpedPrivateKey = new DumpedPrivateKey(this.content);
                ecKey = dumpedPrivateKey.getKey();
                break;
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (dumpedPrivateKey != null) {
            dumpedPrivateKey.clearPrivateKey();
        }
    }
    return ecKey;
}
 
Example #3
Source File: Address.java    From bitherj with Apache License 2.0 6 votes vote down vote up
public List<byte[]> signHashes(List<byte[]> unsignedInHashes, CharSequence passphrase) throws
        PasswordException {
    ECKey key = PrivateKeyUtil.getECKeyFromSingleString(this.getFullEncryptPrivKey(), passphrase);
    if (key == null) {
        throw new PasswordException("do not decrypt eckey");
    }
    KeyParameter assKey = key.getKeyCrypter().deriveKey(passphrase);
    List<byte[]> result = new ArrayList<byte[]>();
    for (byte[] unsignedInHash : unsignedInHashes) {
        TransactionSignature signature = new TransactionSignature(key.sign(unsignedInHash,
                assKey), TransactionSignature.SigHash.ALL, false);
        result.add(ScriptBuilder.createInputScript(signature, key).getProgram());
    }
    key.clearPrivateKey();
    return result;
}
 
Example #4
Source File: BackupUtil.java    From bither-android with Apache License 2.0 6 votes vote down vote up
private void backupPrivateKey() {
    File file;
    if (AppSharedPreference.getInstance().getAppMode() == BitherjSettings.AppMode.HOT) {
        file = FileUtil.getBackupKeyOfHot();
    } else {
        file = FileUtil.getBackupFileOfCold();
    }
    String backupString = PrivateKeyUtil.getBackupPrivateKeyStr();

    if (!Utils.isEmpty(backupString)) {
        try {
            Utils.writeFile(backupString.getBytes(), file);
            AppSharedPreference.getInstance().setLastBackupKeyTime(
                    new Date(System.currentTimeMillis()));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
 
Example #5
Source File: BackupUtil.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
private static ECKey getEckeyFormBackupHot(String address, CharSequence password) {
    File file = FileUtil.getBackupFile();
    String str = Utils.readFile(file);
    if (str.contains(address)) {
        String[] backupStrArray = str.split(PrivateKeyUtil.BACKUP_KEY_SPLIT_MUTILKEY_STRING);
        for (String backupStr : backupStrArray) {
            if (backupStr.contains(address)) {
                String[] strArray = QRCodeUtil.splitString(backupStr);
                if (strArray.length > 3) {
                    String keyString = backupStr.substring(strArray[0]
                            .length() + 1);
                    return PrivateKeyUtil.getECKeyFromSingleString(
                            keyString, password);
                }
            }
        }
    }
    return null;
}
 
Example #6
Source File: BackupUtil.java    From bither-android with Apache License 2.0 6 votes vote down vote up
private static ECKey getEckeyFormBackupHot(String address, CharSequence password) {
    File file = FileUtil.getBackupKeyOfHot();
    String str = Utils.readFile(file);
    if (str.contains(address)) {
        String[] backupStrArray = str.split(PrivateKeyUtil.BACKUP_KEY_SPLIT_MUTILKEY_STRING);
        for (String backupStr : backupStrArray) {
            if (backupStr.contains(address)) {
                String[] strArray = QRCodeUtil.splitString(backupStr);
                if (strArray.length > 3) {
                    String keyString = backupStr.substring(strArray[0]
                            .length() + 1);
                    return PrivateKeyUtil.getECKeyFromSingleString(
                            keyString, password);
                }
            }
        }
    }
    return null;
}
 
Example #7
Source File: KeyUtil.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
public static List<Address> addPrivateKeyByRandomWithPassphras(IUEntropy iuEntropy, CharSequence password, int count) {
    PeerUtil.stopPeer();
    List<Address> addressList = new ArrayList<Address>();
    for (int i = 0; i < count; i++) {
        XRandom xRandom = new XRandom(iuEntropy);
        ECKey ecKey = ECKey.generateECKey(xRandom);
        ecKey = PrivateKeyUtil.encrypt(ecKey, password);
        Address address = new Address(ecKey.toAddress(),
                ecKey.getPubKey(), PrivateKeyUtil.getEncryptedString(ecKey), ecKey.isFromXRandom());
        ecKey.clearPrivateKey();
        addressList.add(address);
        AddressManager.getInstance().addAddress(address);

    }
    PeerUtil.startPeer();
    if (UserPreference.getInstance().getAppMode() == BitherjSettings.AppMode.COLD) {
        BackupUtil.backupColdKey(false);
    } else {
        BackupUtil.backupHotKey();
    }

    return addressList;

}
 
Example #8
Source File: VerifyMessagePanel.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
/**
 * Verify the message text against the address specified and update UI
 */
private void verifyMessage() {
    String addressText = WhitespaceTrimmer.trim(verifyingAddress.getText().trim());
    String messageText = messageTextArea.getText().trim();
    String signatureText = signatureTextArea.getText().trim();
    if (Utils.isEmpty(addressText) || Utils.isEmpty(messageText) || Utils.isEmpty(signatureText)) {
        new MessageDialog(LocaliserUtils.getString("verify_message_signature_verify_failed")).showMsg();
    } else {
        boolean isVerify = PrivateKeyUtil.verifyMessage(addressText, messageText, signatureText);
        if (isVerify) {
            new MessageDialog(LocaliserUtils.getString("verify_message_signature_verify_success")).showMsg();
        } else {
            new MessageDialog(LocaliserUtils.getString("verify_message_signature_verify_failed")).showMsg();
        }
    }
}
 
Example #9
Source File: VerifyMessagePanel.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
/**
 * Verify the message text against the address specified and update UI
 */
private void verifyMessage() {
    String addressText = WhitespaceTrimmer.trim(verifyingAddress.getText().trim());
    String messageText = messageTextArea.getText().trim();
    String signatureText = signatureTextArea.getText().trim();
    if (Utils.isEmpty(addressText) || Utils.isEmpty(messageText) || Utils.isEmpty(signatureText)) {
        new MessageDialog(LocaliserUtils.getString("verify_message_signature_verify_failed")).showMsg();
    } else {
        boolean isVerify = PrivateKeyUtil.verifyMessage(addressText, messageText, signatureText);
        if (isVerify) {
            new MessageDialog(LocaliserUtils.getString("verify_message_signature_verify_success")).showMsg();
        } else {
            new MessageDialog(LocaliserUtils.getString("verify_message_signature_verify_failed")).showMsg();
        }
    }
}
 
Example #10
Source File: KeyUtil.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
public static List<Address> addPrivateKeyByRandomWithPassphras(IUEntropy iuEntropy, CharSequence password, int count) {
    PeerUtil.stopPeer();
    List<Address> addressList = new ArrayList<Address>();
    for (int i = 0; i < count; i++) {
        XRandom xRandom = new XRandom(iuEntropy);
        ECKey ecKey = ECKey.generateECKey(xRandom);
        ecKey = PrivateKeyUtil.encrypt(ecKey, password);
        Address address = new Address(ecKey.toAddress(),
                ecKey.getPubKey(), PrivateKeyUtil.getEncryptedString(ecKey), ecKey.isFromXRandom());
        ecKey.clearPrivateKey();
        addressList.add(address);
        AddressManager.getInstance().addAddress(address);

    }
    PeerUtil.startPeer();
    if (UserPreference.getInstance().getAppMode() == BitherjSettings.AppMode.COLD) {
        BackupUtil.backupColdKey(false);
    } else {
        BackupUtil.backupHotKey();
    }

    return addressList;

}
 
Example #11
Source File: BackupUtil.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
private void backupPrivateKey() {
    File file = FileUtil.getBackupFile();

    String backupString = PrivateKeyUtil.getBackupPrivateKeyStr();


    if (!Utils.isEmpty(backupString)) {

        try {
            Utils.writeFile(backupString.getBytes(), file);
            UserPreference.getInstance().setLastBackupKeyTime(
                    new Date(System.currentTimeMillis()));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
 
Example #12
Source File: BackupUtil.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
private static ECKey getEckeyFormBackupHot(String address, CharSequence password) {
    File file = FileUtil.getBackupFile();
    String str = Utils.readFile(file);
    if (str.contains(address)) {
        String[] backupStrArray = str.split(PrivateKeyUtil.BACKUP_KEY_SPLIT_MUTILKEY_STRING);
        for (String backupStr : backupStrArray) {
            if (backupStr.contains(address)) {
                String[] strArray = QRCodeUtil.splitString(backupStr);
                if (strArray.length > 3) {
                    String keyString = backupStr.substring(strArray[0]
                            .length() + 1);
                    return PrivateKeyUtil.getECKeyFromSingleString(
                            keyString, password);
                }
            }
        }
    }
    return null;
}
 
Example #13
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;
}
 
Example #14
Source File: ImportPrivateKeyPanel.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
public void run() {
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {

        }
    });
    List<Address> addressList = PrivateKeyUtil.getECKeysFromBackupString(content, password);
    HDMKeychain hdmKeychain = PrivateKeyUtil.getHDMKeychain(content, password);

    if ((addressList == null || addressList.size() == 0) && (hdmKeychain == null)) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                dp.dispose();
                new MessageDialog(LocaliserUtils.getString("clone_from_failed")).showMsg();
            }
        });
        return;
    }

    KeyUtil.addAddressListByDesc(addressList);
    if (hdmKeychain != null) {
        KeyUtil.setHDKeyChain(hdmKeychain);
    }
    password.wipe();

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            dp.dispose();
            new MessageDialog(LocaliserUtils.getString("clone_from_success")).showMsg();
            closePanel();
            Bither.refreshFrame();
        }
    });
}
 
Example #15
Source File: BackupUtil.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
private static ECKey getEckeyFormBackupCold(String address, CharSequence password) {

        try {
            File[] files = FileUtil.getBackupDir().listFiles();
            if (files == null) {
                return null;
            }
            files = FileUtil.orderByDateDesc(files);
            for (int i = files.length - 1;
                 i >= 0;
                 i++) {
                File file = files[i];
                String str = Utils.readFile(file);
                if (str.contains(address)) {
                    String[] backupStrArray = str.split(PrivateKeyUtil.BACKUP_KEY_SPLIT_MUTILKEY_STRING);
                    for (String backupStr : backupStrArray) {
                        if (backupStr.contains(address)) {
                            String[] strArray = QRCodeUtil.splitString(backupStr);
                            if (strArray.length > 3) {
                                String keyString = backupStr
                                        .substring(strArray[0].length() + 1);
                                return PrivateKeyUtil.getECKeyFromSingleString(
                                        keyString, password);
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;

    }
 
Example #16
Source File: BackupUtil.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
public static String[] getBackupKeyStrList(File file) {
    String keyStrs = Utils.readFile(file);
    String[] result = null;
    if (!Utils.isEmpty(keyStrs)) {
        result = keyStrs.split(PrivateKeyUtil.BACKUP_KEY_SPLIT_MUTILKEY_STRING);
    }
    return result;
}
 
Example #17
Source File: ExportPrivateKeyPanel.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
private void showPrivateKeyQRCode(SecureCharSequence password) {
    final SecureCharSequence str = PrivateKeyUtil.getDecryptPrivateKeyString(Bither.getActionAddress().getFullEncryptPrivKey(), password);
    password.wipe();
    DisplayQRCodePanle displayQRCodePanle = new DisplayQRCodePanle(str.toString());
    displayQRCodePanle.showPanel();


}
 
Example #18
Source File: BackupUtil.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
private static ECKey getEckeyFormBackupCold(String address, CharSequence password) {

        try {
            File[] files = FileUtil.getBackupDir().listFiles();
            if (files == null) {
                return null;
            }
            files = FileUtil.orderByDateDesc(files);
            for (int i = files.length - 1;
                 i >= 0;
                 i++) {
                File file = files[i];
                String str = Utils.readFile(file);
                if (str.contains(address)) {
                    String[] backupStrArray = str.split(PrivateKeyUtil.BACKUP_KEY_SPLIT_MUTILKEY_STRING);
                    for (String backupStr : backupStrArray) {
                        if (backupStr.contains(address)) {
                            String[] strArray = QRCodeUtil.splitString(backupStr);
                            if (strArray.length > 3) {
                                String keyString = backupStr
                                        .substring(strArray[0].length() + 1);
                                return PrivateKeyUtil.getECKeyFromSingleString(
                                        keyString, password);
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;

    }
 
Example #19
Source File: HDAccount.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public String getFullEncryptPrivKey() {
    if (!hasPrivKey()) {
        return null;
    }
    String encryptPrivKey = getEncryptedMnemonicSeed();
    return PrivateKeyUtil.getFullencryptHDMKeyChain(isFromXRandom, encryptPrivKey);
}
 
Example #20
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 #21
Source File: Address.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public String getFullEncryptPrivKey() {
    String encryptPrivKeyString = AbstractDb.addressProvider.getEncryptPrivateKey(getAddress());
    if (Utils.isEmpty(encryptPrivKeyString)) {
        return "";
    } else {
        return PrivateKeyUtil.getFullencryptPrivateKey(Address.this
                , encryptPrivKeyString);
    }
}
 
Example #22
Source File: HDMSingular.java    From bitherj with Apache License 2.0 5 votes vote down vote up
private void setEntropyInterval(byte[] entropy, boolean xrandom) {
    hotMnemonicSeed = Arrays.copyOf(entropy, 32);
    coldMnemonicSeed = Arrays.copyOfRange(entropy, 32, 64);
    Utils.wipeBytes(entropy);
    initHotFirst();
    encryptedColdMnemonicSeed = new EncryptedData(coldMnemonicSeed, password, xrandom);
    coldQr = QRCodeUtil.HDM_QR_CODE_FLAG + PrivateKeyUtil.getFullencryptHDMKeyChain(xrandom, encryptedColdMnemonicSeed.toEncryptedString());
}
 
Example #23
Source File: BackupUtil.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
public static String[] getBackupKeyStrList(File file) {
    String keyStrs = Utils.readFile(file);
    String[] result = null;
    if (!Utils.isEmpty(keyStrs)) {
        result = keyStrs.split(PrivateKeyUtil.BACKUP_KEY_SPLIT_MUTILKEY_STRING);
    }
    return result;
}
 
Example #24
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;
}
 
Example #25
Source File: ImportPrivateKey.java    From bitherj with Apache License 2.0 5 votes vote down vote up
private Address addECKey(ECKey ecKey) {
    String encryptedPrivateString;
    if (importPrivateKeyType == ImportPrivateKeyType.BitherQrcode) {
        encryptedPrivateString = QRCodeUtil.getNewVersionEncryptPrivKey(content);
    } else {
        ecKey = PrivateKeyUtil.encrypt(ecKey, password);
        encryptedPrivateString = PrivateKeyUtil.getEncryptedString(ecKey);
    }
    Address address = new Address(ecKey.toAddress(), ecKey.getPubKey(), encryptedPrivateString
            , false, ecKey.isFromXRandom());
    if (AddressManager.getInstance().getWatchOnlyAddresses().contains(address)) {
        password.wipe();
        importError(CAN_NOT_IMPORT_BITHER_COLD_PRIVATE_KEY);
        return null;
    } else if (AddressManager.getInstance().getPrivKeyAddresses().contains(address)) {
        password.wipe();
        importError(PRIVATE_KEY_ALREADY_EXISTS);
        return null;

    } else {
        if (importPrivateKeyType == ImportPrivateKeyType.BitherQrcode) {
            PasswordSeed passwordSeed = PasswordSeed.getPasswordSeed();
            if (passwordSeed != null && !passwordSeed.checkPassword(password)) {
                password.wipe();
                importError(PASSWORD_IS_DIFFEREND_LOCAL);
                return null;
            }
        } else {
            password.wipe();
        }
        return address;


    }

}
 
Example #26
Source File: ImportPrivateKeyPanel.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
public void run() {
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {

        }
    });
    List<Address> addressList = PrivateKeyUtil.getECKeysFromBackupString(content, password);
    HDMKeychain hdmKeychain = PrivateKeyUtil.getHDMKeychain(content, password);

    if ((addressList == null || addressList.size() == 0) && (hdmKeychain == null)) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                dp.dispose();
                new MessageDialog(LocaliserUtils.getString("clone_from_failed")).showMsg();
            }
        });
        return;
    }

    KeyUtil.addAddressListByDesc(addressList);
    if (hdmKeychain != null) {
        KeyUtil.setHDKeyChain(hdmKeychain);
    }
    password.wipe();

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            dp.dispose();
            new MessageDialog(LocaliserUtils.getString("clone_from_success")).showMsg();
            closePanel();
            Bither.refreshFrame();
        }
    });
}
 
Example #27
Source File: VerifyMessageSignatureActivity.java    From bither-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    final String address = etAddress.getText().toString().trim();
    final String message = etMessage.getText().toString().trim();
    final String signature = etSignature.getText().toString().trim();
    if (Utils.isEmpty(address) || Utils.isEmpty(message) || Utils.isEmpty(signature)) {
        return;
    }
    imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
    setVerifyButtonVerifying();
    new Thread() {
        @Override
        public void run() {
            signed = PrivateKeyUtil.verifyMessage(address, message, signature);
            btnVerify.post(new Runnable() {
                @Override
                public void run() {
                    if(signed){
                        setVerifyButtonSuccess();
                    }else{
                        setVerifyButtonFailed();
                    }
                    DropdownMessage.showDropdownMessage(VerifyMessageSignatureActivity
                                    .this,
                            signed ? R.string.verify_message_signature_verify_success : R
                                    .string.verify_message_signature_verify_failed);
                }
            });
        }
    }.start();
}
 
Example #28
Source File: CheckUtil.java    From bither-android 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(BitherApplication.mContext.getString(R.string
            .check_address_private_key_title), address.getShortAddress());
    Check check = new Check(title, new ICheckAction() {

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

                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            password.wipe();
            return result;
        }
    });
    return check;
}
 
Example #29
Source File: ExportPrivateKeyPanel.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
private void showPrivateKeyQRCode(SecureCharSequence password) {
    final SecureCharSequence str = PrivateKeyUtil.getDecryptPrivateKeyString(Bither.getActionAddress().getFullEncryptPrivKey(), password);
    password.wipe();
    DisplayQRCodePanle displayQRCodePanle = new DisplayQRCodePanle(str.toString());
    displayQRCodePanle.showPanel();


}
 
Example #30
Source File: KeyUtil.java    From bither-android with Apache License 2.0 5 votes vote down vote up
public static List<Address> addPrivateKeyByRandomWithPassphras(BlockchainService service, IUEntropy iuEntropy, CharSequence password, int count) {
    if (service != null) {
        service.stopAndUnregister();
    }
    List<Address> addressList = new ArrayList<Address>();
    for (int i = 0; i < count; i++) {
        XRandom xRandom = new XRandom(iuEntropy);
        ECKey ecKey = ECKey.generateECKey(xRandom);
        ecKey = PrivateKeyUtil.encrypt(ecKey, password);
        Address address = new Address(ecKey.toAddress(),
                ecKey.getPubKey(), PrivateKeyUtil.getEncryptedString(ecKey), true, ecKey.isFromXRandom());
        ecKey.clearPrivateKey();
        addressList.add(address);
        AddressManager.getInstance().addAddress(address);

    }
    if (AppSharedPreference.getInstance().getAppMode() == BitherjSettings.AppMode.COLD) {
        BackupUtil.backupColdKey(false);
    } else {
        BackupUtil.backupHotKey();
    }
    if (service != null) {
        service.startAndRegister();
    }
    return addressList;

}