Java Code Examples for net.bither.bitherj.qrcode.QRCodeUtil#splitString()

The following examples show how to use net.bither.bitherj.qrcode.QRCodeUtil#splitString() . 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 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 File: EnterpriseHDMSendCollectSignatureActivity.java    From bither-android with Apache License 2.0 6 votes vote down vote up
private void addSignature(String qr) {
    boolean success;
    try {
        String[] stringArray = QRCodeUtil.splitString(qr);
        ArrayList<byte[]> sigs = new ArrayList<byte[]>();
        for (String str : stringArray) {
            if (!Utils.isEmpty(str)) {
                sigs.add(Utils.hexStringToByteArray(str));
            }
        }
        success = pool.addSignature(sigs);
    } catch (Exception e) {
        e.printStackTrace();
        success = false;
    }
    if (!success) {
        DropdownMessage.showDropdownMessage(this, R.string
                .enterprise_hdm_keychain_payment_proposal_sign_failed);
    }
}
 
Example 3
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 4
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 5
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 6
Source File: SendHDMBitcoinPanel.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
public boolean setQrCodeResult(String qr) {

            if (!Utils.isEmpty(qr)) {
                try {
                    String[] stringArray = QRCodeUtil.splitString(qr);
                    sigs = new ArrayList<TransactionSignature>();
                    for (String str : stringArray) {
                        if (!Utils.isEmpty(str)) {
                            TransactionSignature transactionSignature = new
                                    TransactionSignature(ECKey.ECDSASignature.decodeFromDER
                                    (Utils.hexStringToByteArray(str)),
                                    TransactionSignature.SigHash.ALL, false);
                            sigs.add(transactionSignature);
                        }
                    }
                } catch (Exception e) {
                    sigs = null;
                    e.printStackTrace();
                    new MessageDialog(LocaliserUtils.getString("send_failed")).showMsg();
                }
            } else {
                sigs = null;
            }
            try {
                lock.lock();
                fetchedCondition.signal();
            } finally {
                lock.unlock();
            }
            return true;

        }
 
Example 7
Source File: HdmSendActivity.java    From bither-android with Apache License 2.0 5 votes vote down vote up
public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == RequestCode) {
        if (resultCode == RESULT_OK) {
            final String qr = data.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT);
            try {
                String[] stringArray = QRCodeUtil.splitString(qr);
                sigs = new ArrayList<TransactionSignature>();
                for (String str : stringArray) {
                    if (!Utils.isEmpty(str)) {
                        TransactionSignature transactionSignature = new
                                TransactionSignature(ECKey.ECDSASignature.decodeFromDER
                                (Utils.hexStringToByteArray(str)),
                                TransactionSignature.SigHash.ALL, false);
                        sigs.add(transactionSignature);
                    }
                }
            } catch (Exception e) {
                sigs = null;
                e.printStackTrace();
                DropdownMessage.showDropdownMessage(HdmSendActivity.this,
                        R.string.send_failed);
            }
        } else {
            sigs = null;
        }
        try {
            lock.lock();
            fetchedCondition.signal();
        } finally {
            lock.unlock();
        }
        return true;
    }
    return false;
}
 
Example 8
Source File: BackupUtil.java    From bither-android with 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 9
Source File: MonitorBitherColdUtil.java    From bither-android with Apache License 2.0 5 votes vote down vote up
private boolean checkQrCodeContent(String content) {
    String[] strs = QRCodeUtil.splitString(content);
    for (String str : strs) {
        boolean checkCompressed = str.length() == 66 || ((str.length() == 67) && (str.indexOf
                (QRCodeUtil.XRANDOM_FLAG) == 0));
        boolean checkUnCompressed = str.length() == 130 || ((str.length() == 131) && (str
                .indexOf(QRCodeUtil.XRANDOM_FLAG) == 0));
        if (!checkCompressed && !checkUnCompressed) {
            return false;
        }
    }
    return true;
}
 
Example 10
Source File: TransactionsUtil.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public static boolean signTransaction(Tx tx, String qrCodeContent)
        throws ScriptException {
    String[] stringArray = QRCodeUtil.splitString(qrCodeContent);
    List<byte[]> hashList = new ArrayList<byte[]>();
    for (String str : stringArray) {
        if (!Utils.isEmpty(str)) {
            hashList.add(Utils.hexStringToByteArray(str));
        }
    }
    tx.signWithSignatures(hashList);
    return tx.verifySignatures();
}
 
Example 11
Source File: PrivateKeyUtil.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public static String getFullencryptPrivateKey(Address address, String encryptPrivKey) {
    String[] strings = QRCodeUtil.splitString(encryptPrivKey);
    byte[] salt = Utils.hexStringToByteArray(strings[2]);
    if (salt.length == KeyCrypterScrypt.SALT_LENGTH) {
        SaltForQRCode saltForQRCode = new SaltForQRCode(salt, address.isCompressed(), address.isFromXRandom());
        strings[2] = Utils.bytesToHexString(saltForQRCode.getQrCodeSalt());
    }
    return Utils.joinString(strings, QRCodeUtil.QR_CODE_SPLIT);
}
 
Example 12
Source File: PrivateKeyUtil.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public static String getFullencryptHDMKeyChain(boolean isFromXRandom, String encryptPrivKey) {
    String[] strings = QRCodeUtil.splitString(encryptPrivKey);
    byte[] salt = Utils.hexStringToByteArray(strings[2]);
    if (salt.length == KeyCrypterScrypt.SALT_LENGTH) {
        SaltForQRCode saltForQRCode = new SaltForQRCode(salt, true, isFromXRandom);
        strings[2] = Utils.bytesToHexString(saltForQRCode.getQrCodeSalt()).toUpperCase();
    }
    return Utils.joinString(strings, QRCodeUtil.QR_CODE_SPLIT);
}
 
Example 13
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 14
Source File: SendHDMBitcoinPanel.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
public boolean setQrCodeResult(String qr) {

            if (!Utils.isEmpty(qr)) {
                try {
                    String[] stringArray = QRCodeUtil.splitString(qr);
                    sigs = new ArrayList<TransactionSignature>();
                    for (String str : stringArray) {
                        if (!Utils.isEmpty(str)) {
                            TransactionSignature transactionSignature = new
                                    TransactionSignature(ECKey.ECDSASignature.decodeFromDER
                                    (Utils.hexStringToByteArray(str)),
                                    TransactionSignature.SigHash.ALL, false);
                            sigs.add(transactionSignature);
                        }
                    }
                } catch (Exception e) {
                    sigs = null;
                    e.printStackTrace();
                    new MessageDialog(LocaliserUtils.getString("send_failed")).showMsg();
                }
            } else {
                sigs = null;
            }
            try {
                lock.lock();
                fetchedCondition.signal();
            } finally {
                lock.unlock();
            }
            return true;

        }