Java Code Examples for net.bither.bitherj.qrcode.QRCodeUtil

The following examples show how to use net.bither.bitherj.qrcode.QRCodeUtil. 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-android   Source File: DialogPrivateKeyQrCode.java    License: Apache License 2.0 6 votes vote down vote up
public DialogPrivateKeyQrCode(Activity context, String keyString,
                              BitherSetting.QRCodeType type, String address) {
    super(context, R.style.tipsDialog);
    this.activity = context;
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    getWindow().getAttributes().dimAmount = 0.8f;
    setCanceledOnTouchOutside(true);
    if (type == BitherSetting.QRCodeType.Bither) {
        this.content = QRCodeUtil.encodeQrCodeString(keyString);
    } else {
        this.content = keyString;
    }
    this.address = address;
    setContentView(R.layout.dialog_private_key_qr_code);
    setOnDismissListener(this);
    initView();
    getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.MATCH_PARENT);
    new FancyQrCodeThread(this.content, ivQr.getLayoutParams().width, Color.BLACK,
            Color.WHITE, this, false).start();
}
 
Example 3
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 4
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 5
Source Project: bitherj   Source File: PrivateKeyUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static HDAccountCold getHDAccountCold(String str, CharSequence password) {
    HDAccountCold hdAccountCold = null;
    String[] strs = QRCodeUtil.splitOfPasswordSeed(str);
    if (strs.length % 3 != 0) {
        log.error("Backup: PrivateKeyFromString format error");
        return null;
    }
    for (int i = 0;
         i < strs.length;
         i += 3) {

        if (strs[i].indexOf(QRCodeUtil.HD_QR_CODE_FLAG) == 0) {
            try {
                String encryptedString = strs[i].substring(1) + QRCodeUtil.QR_CODE_SPLIT + strs[i + 1]
                        + QRCodeUtil.QR_CODE_SPLIT + strs[i + 2];
                hdAccountCold = new HDAccountCold(new EncryptedData(encryptedString), password);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    return hdAccountCold;
}
 
Example 6
Source Project: bitherj   Source File: PrivateKeyUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static String formatEncryptPrivateKeyForDb(String encryptPrivateKey) {
    if (Utils.isEmpty(encryptPrivateKey)) {
        return encryptPrivateKey;
    }
    String[] strs = QRCodeUtil.splitOfPasswordSeed(encryptPrivateKey);
    byte[] temp = Utils.hexStringToByteArray(strs[2]);
    byte[] salt = new byte[KeyCrypterScrypt.SALT_LENGTH];
    if (temp.length == KeyCrypterScrypt.SALT_LENGTH + 1) {
        System.arraycopy(temp, 1, salt, 0, salt.length);
    } else {
        salt = temp;
    }
    strs[2] = Utils.bytesToHexString(salt);
    return Utils.joinString(strs, QRCodeUtil.QR_CODE_SPLIT);

}
 
Example 7
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 8
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 9
Source Project: bither-desktop-java   Source File: SendHDMBitcoinPanel.java    License: 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 10
Source Project: bither-desktop-java   Source File: UserPreference.java    License: Apache License 2.0 5 votes vote down vote up
public QRCodeUtil.QRQuality getQRQuality() {
    int ordinal = getInt(QR_QUALITY, -1);
    if (ordinal < QRCodeUtil.QRQuality.values().length && ordinal >= 0) {
        return QRCodeUtil.QRQuality.values()[ordinal];
    }
    return QRCodeUtil.QRQuality.Normal;

}
 
Example 11
Source Project: bither-desktop-java   Source File: UserPreference.java    License: Apache License 2.0 5 votes vote down vote up
public void setQRQuality(QRCodeUtil.QRQuality qrQuality) {
    int index = -1;
    if (qrQuality != null) {
        index = qrQuality.ordinal();
    }
    setValue(QR_QUALITY, Integer.toString(index));

}
 
Example 12
Source Project: bither-android   Source File: EnterpriseHDMSeedActivity.java    License: 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 13
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == ImportFromQRTag) {
        final String seedStr = data.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT);
        if (seedStr.indexOf(QRCodeUtil.Enterprise_HDM_QR_CODE_FLAG) == 0) {
            DialogPassword dialogPassword = new DialogPassword(this, new
                    ImportSeedPasswordListener(seedStr));
            dialogPassword.setCheckPre(false);
            dialogPassword.setCheckPasswordListener(new ICheckPasswordListener() {
                @Override
                public boolean checkPassword(SecureCharSequence password) {
                    String keyString = seedStr.substring(1);
                    String[] passwordSeeds = QRCodeUtil.splitOfPasswordSeed(keyString);
                    String encreyptString = Utils.joinString(new String[]{passwordSeeds[0],
                            passwordSeeds[1], passwordSeeds[2]}, QRCodeUtil.QR_CODE_SPLIT);
                    EncryptedData encryptedData = new EncryptedData(encreyptString);
                    byte[] result = null;
                    try {
                        result = encryptedData.decrypt(password);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return result != null;
                }
            });
            dialogPassword.setTitle(R.string.import_private_key_qr_code_password);
            dialogPassword.show();
        } else {
            DropdownMessage.showDropdownMessage(AddEnterpriseHDMSeedActivity.this, R.string
                    .enterprise_hdm_seed_import_format_error);
        }
        return;
    }
    super.onActivityResult(requestCode, resultCode, data);
}
 
Example 14
Source Project: bither-android   Source File: ColdAdvanceActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onOptionIndexSelected(int index) {
    if (index >= 0 && index < getOptionCount()) {
        AppSharedPreference.getInstance().setQRQuality(QRCodeUtil.QRQuality.values()
                [index]);
    }
}
 
Example 15
Source Project: bither-android   Source File: HdmSendActivity.java    License: 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 16
Source Project: bither-android   Source File: HotAdvanceActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onOptionIndexSelected(int index) {
    if (index >= 0 && index < getOptionCount()) {
        AppSharedPreference.getInstance().setQRQuality(QRCodeUtil.QRQuality.values()
                [index]);
    }
}
 
Example 17
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 18
Source Project: bither-android   Source File: MonitorBitherColdUtil.java    License: 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 19
Source Project: bither-android   Source File: AppSharedPreference.java    License: Apache License 2.0 5 votes vote down vote up
public QRCodeUtil.QRQuality getQRQuality() {
    int ordinal = this.mPreferences.getInt(QR_QUALITY, 0);
    if (ordinal < QRCodeUtil.QRQuality.values().length && ordinal >= 0) {
        return QRCodeUtil.QRQuality.values()[ordinal];
    }
    return QRCodeUtil.QRQuality.Normal;

}
 
Example 20
Source Project: bither-android   Source File: AppSharedPreference.java    License: Apache License 2.0 5 votes vote down vote up
public void setQRQuality(QRCodeUtil.QRQuality qrQuality) {
    int index = -1;
    if (qrQuality != null) {
        index = qrQuality.ordinal();
    }
    this.mPreferences.edit().putInt(QR_QUALITY, index).commit();
}
 
Example 21
Source Project: bitherj   Source File: TransactionsUtil.java    License: 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 22
Source Project: bitherj   Source File: PrivateKeyUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static String getEncryptedString(ECKey ecKey) {
    String salt = "1";
    if (ecKey.getKeyCrypter() instanceof KeyCrypterScrypt) {
        KeyCrypterScrypt scrypt = (KeyCrypterScrypt) ecKey.getKeyCrypter();
        salt = Utils.bytesToHexString(scrypt.getSalt());
    }
    EncryptedPrivateKey key = ecKey.getEncryptedPrivateKey();
    return Utils.bytesToHexString(key.getEncryptedBytes()) + QRCodeUtil.QR_CODE_SPLIT + Utils
            .bytesToHexString(key.getInitialisationVector()) + QRCodeUtil.QR_CODE_SPLIT + salt;
}
 
Example 23
Source Project: bitherj   Source File: PrivateKeyUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static String changePassword(String str, CharSequence oldpassword, CharSequence newPassword) {
    String[] strs = QRCodeUtil.splitOfPasswordSeed(str);
    if (strs.length != 3) {
        log.error("change Password: PrivateKeyFromString format error");
        return null;
    }

    byte[] temp = Utils.hexStringToByteArray(strs[2]);
    if (temp.length != KeyCrypterScrypt.SALT_LENGTH + 1 && temp.length != KeyCrypterScrypt.SALT_LENGTH) {
        log.error("decryption:  salt lenth is {} not {}", temp.length, KeyCrypterScrypt.SALT_LENGTH + 1);
        return null;
    }
    byte[] salt = new byte[KeyCrypterScrypt.SALT_LENGTH];
    if (temp.length == KeyCrypterScrypt.SALT_LENGTH) {
        salt = temp;
    } else {
        System.arraycopy(temp, 1, salt, 0, salt.length);
    }
    KeyCrypterScrypt crypter = new KeyCrypterScrypt(salt);
    EncryptedPrivateKey epk = new EncryptedPrivateKey(Utils.hexStringToByteArray
            (strs[1]), Utils.hexStringToByteArray(strs[0]));

    byte[] decrypted = crypter.decrypt(epk, crypter.deriveKey(oldpassword));
    EncryptedPrivateKey encryptedPrivateKey = crypter.encrypt(decrypted, crypter.deriveKey(newPassword));
    byte[] newDecrypted = crypter.decrypt(encryptedPrivateKey, crypter.deriveKey(newPassword));
    if (!Arrays.equals(decrypted, newDecrypted)) {
        throw new KeyCrypterException("change Password, cannot be successfully decrypted after encryption so aborting wallet encryption.");
    }
    Utils.wipeBytes(decrypted);
    Utils.wipeBytes(newDecrypted);
    return Utils.bytesToHexString(encryptedPrivateKey.getEncryptedBytes())
            + QRCodeUtil.QR_CODE_SPLIT + Utils.bytesToHexString(encryptedPrivateKey.getInitialisationVector())
            + QRCodeUtil.QR_CODE_SPLIT + strs[2];

}
 
Example 24
Source Project: bitherj   Source File: PrivateKeyUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static String getEncryptPrivateKeyStringFromAllAddresses() {
    String content = "";
    List<Address> privates = AddressManager.getInstance().getPrivKeyAddresses();
    for (int i = 0;
         i < privates.size();
         i++) {
        Address address = privates.get(i);
        content += address.getFullEncryptPrivKey();
        if (i < privates.size() - 1) {
            content += QRCodeUtil.QR_CODE_SPLIT;
        }
    }
    HDMKeychain keychain = AddressManager.getInstance().getHdmKeychain();
    if (keychain != null) {
        if (Utils.isEmpty(content)) {
            content += keychain.getQRCodeFullEncryptPrivKey();
        } else {
            content += QRCodeUtil.QR_CODE_SPLIT + keychain.getQRCodeFullEncryptPrivKey();
        }
    }
    HDAccount hdAccount = AddressManager.getInstance().getHDAccountHot();
    if (hdAccount != null) {
        if (Utils.isEmpty(content)) {
            content += hdAccount.getQRCodeFullEncryptPrivKey();
        } else {
            content += QRCodeUtil.QR_CODE_SPLIT + hdAccount.getQRCodeFullEncryptPrivKey();
        }
    }
    HDAccountCold hdAccountCold = AddressManager.getInstance().getHDAccountCold();
    if (hdAccountCold != null) {
        if (Utils.isEmpty(content)) {
            content += hdAccountCold.getQRCodeFullEncryptPrivKey();
        } else {
            content += QRCodeUtil.QR_CODE_SPLIT + hdAccountCold.getQRCodeFullEncryptPrivKey();
        }
    }
    return content;
}
 
Example 25
Source Project: bitherj   Source File: PrivateKeyUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static List<Address> getECKeysFromBackupString(String str, CharSequence password) {
    String[] strs = QRCodeUtil.splitOfPasswordSeed(str);
    if (strs.length % 3 != 0) {
        log.error("Backup: PrivateKeyFromString format error");
        return null;
    }
    ArrayList<Address> list = new ArrayList<Address>();
    for (int i = 0;
         i < strs.length;
         i += 3) {
        if (strs[i].indexOf(QRCodeUtil.HDM_QR_CODE_FLAG) == 0) {
            continue;
        }
        if (strs[i].indexOf(QRCodeUtil.HD_QR_CODE_FLAG) == 0){
            continue;
        }
        String encryptedString = strs[i] + QRCodeUtil.QR_CODE_SPLIT + strs[i + 1]
                + QRCodeUtil.QR_CODE_SPLIT + strs[i + 2];
        ECKey key = getECKeyFromSingleString(encryptedString, password);

        if (key == null) {
            return null;
        } else {
            Address address = new Address(key.toAddress(), key.getPubKey(), encryptedString,
                    false, key.isFromXRandom());
            key.clearPrivateKey();
            list.add(address);
        }
    }
    return list;
}
 
Example 26
Source Project: bitherj   Source File: PrivateKeyUtil.java    License: 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 27
Source Project: bitherj   Source File: PrivateKeyUtil.java    License: 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 28
Source Project: bitherj   Source File: UpgradeAddressUtil.java    License: Apache License 2.0 5 votes vote down vote up
private static List<Address> initPrivateKeyListByDesc() {
    List<Address> privKeyAddresses = new ArrayList<Address>();

    File[] files = Utils.getPrivateDir().listFiles();
    if (files != null) {
        for (File file : files) {
            if (file.getName().contains(Address.PUBLIC_KEY_FILE_NAME_SUFFIX)) {
                String content = Utils.readFile(file);
                String[] strings = content.split(Address.KEY_SPLIT_STRING);
                String address = file.getName().substring(0,
                        file.getName().length() - Address.PUBLIC_KEY_FILE_NAME_SUFFIX.length());
                String publicKey = strings[0];
                int isSyncComplete = Integer.valueOf(strings[1]);
                long sortTime = Long.valueOf(strings[2]);
                boolean isFromXRandom = false;
                if (strings.length == 4) {
                    isFromXRandom = Utils.compareString(strings[3], QRCodeUtil.XRANDOM_FLAG);
                }
                String privateKeyFullFileName = Utils.format(BitherjSettings
                        .PRIVATE_KEY_FILE_NAME, Utils.getPrivateDir(), address);
                String encryptPrivate = QRCodeUtil.getNewVersionEncryptPrivKey(Utils.readFile(new File(privateKeyFullFileName)));
                encryptPrivate = PrivateKeyUtil.formatEncryptPrivateKeyForDb(encryptPrivate);
                Address add = new Address(address, Utils.hexStringToByteArray(publicKey), sortTime
                        , isSyncComplete == 1, isFromXRandom, false, encryptPrivate);
                privKeyAddresses.add(add);

            }
        }
        if (privKeyAddresses.size() > 0) {
            Collections.sort(privKeyAddresses);
        }
    }
    return privKeyAddresses;
}
 
Example 29
Source Project: bitherj   Source File: UpgradeAddressUtil.java    License: Apache License 2.0 5 votes vote down vote up
private static List<Address> initWatchOnlyListByDesc() {
    List<Address> watchOnlyAddresses = new ArrayList<Address>();
    File[] files = Utils.getWatchOnlyDir().listFiles();
    if (files != null) {
        for (File file : files) {
            if (file.getName().contains(Address.PUBLIC_KEY_FILE_NAME_SUFFIX)) {
                String content = Utils.readFile(file);
                String[] strings = content.split(Address.KEY_SPLIT_STRING);
                String address = file.getName().substring(0,
                        file.getName().length() - Address.PUBLIC_KEY_FILE_NAME_SUFFIX.length());
                String publicKey = strings[0];
                int isSyncComplete = Integer.valueOf(strings[1]);
                long sortTime = Long.valueOf(strings[2]);
                boolean isFromXRandom = false;
                if (strings.length == 4) {
                    isFromXRandom = Utils.compareString(strings[3], QRCodeUtil.XRANDOM_FLAG);
                }
                Address add = new Address(address, Utils.hexStringToByteArray(publicKey), sortTime
                        , isSyncComplete == 1, isFromXRandom, false, null);
                watchOnlyAddresses.add(add);

            }
        }
        if (watchOnlyAddresses.size() > 0) {
            Collections.sort(watchOnlyAddresses);
        }
    }
    return watchOnlyAddresses;
}
 
Example 30
Source Project: bitherj   Source File: UpgradeAddressUtil.java    License: Apache License 2.0 5 votes vote down vote up
private static List<Address> initTrashListByDesc() {
    File[] files = Utils.getTrashDir().listFiles();
    List<Address> trashAddresses = new ArrayList<Address>();
    if (files != null) {
        for (File file : files) {
            if (file.getName().contains(Address.PUBLIC_KEY_FILE_NAME_SUFFIX)) {
                String content = Utils.readFile(file);
                String[] strings = content.split(Address.KEY_SPLIT_STRING);
                String address = file.getName().substring(0,
                        file.getName().length() - Address.PUBLIC_KEY_FILE_NAME_SUFFIX.length());
                String publicKey = strings[0];
                int isSyncComplete = Integer.valueOf(strings[1]);
                long sortTime = Long.valueOf(strings[2]);
                boolean isFromXRandom = false;
                if (strings.length == 4) {
                    isFromXRandom = Utils.compareString(strings[3], QRCodeUtil.XRANDOM_FLAG);
                }

                String privateKeyFullFileName = Utils.format(BitherjSettings
                        .PRIVATE_KEY_FILE_NAME, Utils.getTrashDir(), address);
                String encryptPrivate = QRCodeUtil.getNewVersionEncryptPrivKey(Utils.readFile(new File(privateKeyFullFileName)));
                encryptPrivate = PrivateKeyUtil.formatEncryptPrivateKeyForDb(encryptPrivate);
                Address add = new Address(address, Utils.hexStringToByteArray(publicKey), sortTime
                        , isSyncComplete == 1, isFromXRandom, true, encryptPrivate);
                add.setTrashed(true);
                trashAddresses.add(add);
            }
        }
        if (trashAddresses.size() > 0) {
            Collections.sort(trashAddresses);
        }
    }
    return trashAddresses;
}