Java Code Examples for net.bither.bitherj.utils.PrivateKeyUtil

The following examples show how to use net.bither.bitherj.utils.PrivateKeyUtil. These examples are extracted from open source projects. 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 Project: bither-desktop-java   Source File: BackupUtil.java    License: 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 2
Source Project: bither-desktop-java   Source File: BackupUtil.java    License: 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 3
Source Project: bither-desktop-java   Source File: KeyUtil.java    License: 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 4
Source Project: bither-desktop-java   Source File: VerifyMessagePanel.java    License: 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 5
Source Project: bither-android   Source File: BackupUtil.java    License: 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 6
Source Project: bither-android   Source File: BackupUtil.java    License: 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 7
Source Project: bitherj   Source File: ImportPrivateKey.java    License: 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 8
Source Project: bitherj   Source File: Address.java    License: 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 9
Source Project: bither-desktop-java   Source File: BackupUtil.java    License: 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 10
Source Project: bither-desktop-java   Source File: BackupUtil.java    License: 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 11
Source Project: bither-desktop-java   Source File: KeyUtil.java    License: 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 12
Source Project: bither-desktop-java   Source File: VerifyMessagePanel.java    License: 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 13
Source Project: bither-desktop-java   Source File: BackupUtil.java    License: 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 14
Source Project: bither-desktop-java   Source File: BackupUtil.java    License: 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 15
Source Project: bither-desktop-java   Source File: CheckUtil.java    License: 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 16
Source Project: bither-desktop-java   Source File: ImportPrivateKeyPanel.java    License: 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 17
Source Project: bither-desktop-java   Source File: ExportPrivateKeyPanel.java    License: 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 Project: bither-desktop-java   Source File: ExportPrivateKeyPanel.java    License: 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 19
Source Project: bither-android   Source File: OptionColdFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    new DialogPassword(getActivity(), new IDialogPasswordListener() {
        @Override
        public void onPasswordEntered(SecureCharSequence password) {
            password.wipe();
            String content = PrivateKeyUtil.getEncryptPrivateKeyStringFromAllAddresses();
            Intent intent = new Intent(getActivity(), BitherQRCodeActivity.class);
            intent.putExtra(BitherSetting.INTENT_REF.TITLE_STRING,
                    getString(R.string.clone_to_title));
            intent.putExtra(BitherSetting.INTENT_REF.QR_CODE_STRING, content);
            startActivity(intent);
        }
    }).show();
}
 
Example 20
Source Project: bither-android   Source File: BackupUtil.java    License: Apache License 2.0 5 votes vote down vote up
private static ECKey getEckeyFormBackupCold(String address, CharSequence password) {
    if (!FileUtil.existSdCardMounted()) {
        return null;
    }
    try {
        File[] files = FileUtil.getBackupSdCardDir().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 21
Source Project: bither-android   Source File: BackupUtil.java    License: 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 22
Source Project: bither-android   Source File: KeyUtil.java    License: 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;

}
 
Example 23
Source Project: bither-android   Source File: CheckUtil.java    License: 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 24
@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 25
Source Project: bitherj   Source File: ImportPrivateKey.java    License: 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 Project: bitherj   Source File: PasswordSeed.java    License: Apache License 2.0 5 votes vote down vote up
public boolean checkPassword(CharSequence password) {
    ECKey ecKey = PrivateKeyUtil.getECKeyFromSingleString(keyStr, password);
    String ecKeyAddress;
    if (ecKey == null) {
        return false;
    } else {
        ecKeyAddress = ecKey.toAddress();
        ecKey.clearPrivateKey();
    }
    return Utils.compareString(this.address,
            ecKeyAddress);

}
 
Example 27
Source Project: bitherj   Source File: HDMSingular.java    License: 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 28
Source Project: bitherj   Source File: Address.java    License: 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 29
Source Project: bitherj   Source File: HDAccount.java    License: 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 30
Source Project: bither-desktop-java   Source File: BackupUtil.java    License: 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;

    }