Java Code Examples for net.bither.bitherj.crypto.EncryptedData#decrypt()

The following examples show how to use net.bither.bitherj.crypto.EncryptedData#decrypt() . 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: HDMBId.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public byte[] decryptHDMBIdPassword(CharSequence password) {
    HDMBId hdmbId = AbstractDb.addressProvider.getHDMBId();
    if (!Utils.isEmpty(hdmbId.getEncryptedBitherPasswordString())) {
        encryptedBitherPassword = new EncryptedData(hdmbId.getEncryptedBitherPasswordString());
    }
    decryptedPassword = encryptedBitherPassword.decrypt(password);
    return decryptedPassword;
}
 
Example 2
Source File: DesktopHDMKeychain.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public DesktopHDMKeychain(EncryptedData encryptedMnemonicSeed, CharSequence password) throws
        HDMBitherIdNotMatchException, MnemonicException.MnemonicLengthException {
    mnemonicSeed = encryptedMnemonicSeed.decrypt(password);
    hdSeed = seedFromMnemonic(mnemonicSeed);
    isFromXRandom = encryptedMnemonicSeed.isXRandom();
    EncryptedData encryptedHDSeed = new EncryptedData(hdSeed, password, isFromXRandom);
    ArrayList<DesktopHDMAddress> as = new ArrayList<DesktopHDMAddress>();
    ArrayList<HDMAddress.Pubs> uncompPubs = new ArrayList<HDMAddress.Pubs>();

    ECKey k = new ECKey(mnemonicSeed, null);
    String address = k.toAddress();
    k.clearPrivateKey();
    String firstAddress = getFirstAddressFromSeed(password);
    wipeMnemonicSeed();
    wipeHDSeed();

    this.hdSeedId = AbstractDb.desktopAddressProvider.addHDKey(encryptedMnemonicSeed
                    .toEncryptedString(), encryptedHDSeed.toEncryptedString(), firstAddress,
            isFromXRandom, address, null, null);
    if (as.size() > 0) {
        //   EnDesktopAddressProvider.getInstance().completeHDMAddresses(getHdSeedId(), as);

        if (uncompPubs.size() > 0) {
            //  EnDesktopAddressProvider.getInstance().prepareHDMAddresses(getHdSeedId(), uncompPubs);
            for (HDMAddress.Pubs p : uncompPubs) {
                AbstractDb.addressProvider.setHDMPubsRemote(getHdSeedId(), p.index, p.remote);
            }
        }
    }
}
 
Example 3
Source File: HDAccount.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public HDAccount(EncryptedData encryptedMnemonicSeed, CharSequence password, boolean
        isSyncedComplete)
        throws MnemonicException.MnemonicLengthException {
    mnemonicSeed = encryptedMnemonicSeed.decrypt(password);
    hdSeed = seedFromMnemonic(mnemonicSeed);
    isFromXRandom = encryptedMnemonicSeed.isXRandom();
    EncryptedData encryptedHDSeed = new EncryptedData(hdSeed, password, isFromXRandom);
    DeterministicKey master = HDKeyDerivation.createMasterPrivateKey(hdSeed);
    DeterministicKey account = getAccount(master);
    account.clearPrivateKey();
    initHDAccount(account, encryptedMnemonicSeed, encryptedHDSeed, isFromXRandom,
            isSyncedComplete, null);
}
 
Example 4
Source File: HDMKeychain.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public boolean checkSingularBackupWithPassword(CharSequence password) {
    if (isInRecovery()) {
        return true;
    }
    if (getAllCompletedAddresses().size() == 0) {
        return true;
    }
    String backup = AbstractDb.addressProvider.getSingularModeBackup(getHdSeedId());
    if (backup == null) {
        return true;
    }
    EncryptedData encrypted = new EncryptedData(backup);
    byte[] mnemonic = encrypted.decrypt(password);
    boolean result;
    try {
        byte[] seed = seedFromMnemonic(mnemonic);
        byte[] pub = getAllCompletedAddresses().get(0).getPubCold();
        DeterministicKey master = HDKeyDerivation.createMasterPrivateKey(seed);
        DeterministicKey purpose = master.deriveHardened(44);
        DeterministicKey coinType = purpose.deriveHardened(0);
        DeterministicKey account = coinType.deriveHardened(0);
        DeterministicKey external = account.deriveSoftened(0);
        DeterministicKey first = external.deriveSoftened(0);
        master.wipe();
        purpose.wipe();
        coinType.wipe();
        account.wipe();
        external.wipe();
        Utils.wipeBytes(seed);
        result = Arrays.equals(first.getPubKey(), pub);
        first.wipe();
    } catch (MnemonicException.MnemonicLengthException e) {
        e.printStackTrace();
        result = false;
    }
    Utils.wipeBytes(mnemonic);
    return result;
}
 
Example 5
Source File: HDAccountCold.java    From bitherj with Apache License 2.0 4 votes vote down vote up
public HDAccountCold(EncryptedData encryptedMnemonicSeed, CharSequence password) throws
        MnemonicException.MnemonicLengthException {
    this(encryptedMnemonicSeed.decrypt(password), password, encryptedMnemonicSeed.isXRandom());
}