Java Code Examples for net.bither.bitherj.crypto.hd.DeterministicKey#clearPrivateKey()

The following examples show how to use net.bither.bitherj.crypto.hd.DeterministicKey#clearPrivateKey() . 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: DesktopHDMKeychain.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public static boolean checkPassword(String keysString, CharSequence password) throws
        MnemonicException.MnemonicLengthException {
    String[] passwordSeeds = QRCodeUtil.splitOfPasswordSeed(keysString);
    String address = Base58.hexToBase58WithAddress(passwordSeeds[0]);
    String encreyptString = Utils.joinString(new String[]{passwordSeeds[1], passwordSeeds[2],
            passwordSeeds[3]}, QRCodeUtil.QR_CODE_SPLIT);
    byte[] seed = new EncryptedData(encreyptString).decrypt(password);
    MnemonicCode mnemonic = MnemonicCode.instance();

    byte[] s = mnemonic.toSeed(mnemonic.toMnemonic(seed), "");

    DeterministicKey master = HDKeyDerivation.createMasterPrivateKey(s);

    DeterministicKey purpose = master.deriveHardened(44);

    DeterministicKey coinType = purpose.deriveHardened(0);

    DeterministicKey account = coinType.deriveHardened(0);

    DeterministicKey external = account.deriveSoftened(0);

    external.clearPrivateKey();

    DeterministicKey key = external.deriveSoftened(0);
    boolean result = Utils.compareString(address, Utils.toAddress(key.getPubKeyHash()));
    key.wipe();

    return result;
}
 
Example 2
Source File: HDAccount.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public HDAccount(byte[] mnemonicSeed, CharSequence password, boolean isSyncedComplete) throws
        MnemonicException
        .MnemonicLengthException {
    super();
    this.mnemonicSeed = mnemonicSeed;
    hdSeed = seedFromMnemonic(mnemonicSeed);
    DeterministicKey master = HDKeyDerivation.createMasterPrivateKey(hdSeed);
    EncryptedData encryptedHDSeed = new EncryptedData(hdSeed, password, isFromXRandom);
    EncryptedData encryptedMnemonicSeed = new EncryptedData(mnemonicSeed, password,
            isFromXRandom);
    DeterministicKey account = getAccount(master);
    account.clearPrivateKey();
    initHDAccount(account, encryptedMnemonicSeed, encryptedHDSeed, isFromXRandom,
            isSyncedComplete, null);
}
 
Example 3
Source File: HDAccount.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public HDAccount(SecureRandom random, CharSequence password, HDAccountGenerationDelegate generationDelegate) throws MnemonicException.MnemonicLengthException {
    isFromXRandom = random.getClass().getCanonicalName().indexOf("XRandom") >= 0;
    mnemonicSeed = new byte[16];
    random.nextBytes(mnemonicSeed);
    hdSeed = seedFromMnemonic(mnemonicSeed);
    EncryptedData encryptedHDSeed = new EncryptedData(hdSeed, password, isFromXRandom);
    EncryptedData encryptedMnemonicSeed = new EncryptedData(mnemonicSeed, password,
            isFromXRandom);
    DeterministicKey master = HDKeyDerivation.createMasterPrivateKey(hdSeed);
    DeterministicKey account = getAccount(master);
    account.clearPrivateKey();
    initHDAccount(account, encryptedMnemonicSeed, encryptedHDSeed, isFromXRandom, true,
            generationDelegate);
}
 
Example 4
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 5
Source File: HDMKeychain.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public static boolean checkPassword(String keysString, CharSequence password) throws
        MnemonicException.MnemonicLengthException {
    String[] passwordSeeds = QRCodeUtil.splitOfPasswordSeed(keysString);
    String address = Base58.hexToBase58WithAddress(passwordSeeds[0]);
    String encreyptString = Utils.joinString(new String[]{passwordSeeds[1], passwordSeeds[2],
            passwordSeeds[3]}, QRCodeUtil.QR_CODE_SPLIT);
    byte[] seed = new EncryptedData(encreyptString).decrypt(password);
    MnemonicCode mnemonic = MnemonicCode.instance();

    byte[] s = mnemonic.toSeed(mnemonic.toMnemonic(seed), "");

    DeterministicKey master = HDKeyDerivation.createMasterPrivateKey(s);

    DeterministicKey purpose = master.deriveHardened(44);

    DeterministicKey coinType = purpose.deriveHardened(0);

    DeterministicKey account = coinType.deriveHardened(0);

    DeterministicKey external = account.deriveSoftened(0);

    external.clearPrivateKey();

    DeterministicKey key = external.deriveSoftened(0);
    boolean result = Utils.compareString(address, Utils.toAddress(key.getPubKeyHash()));
    key.wipe();

    return result;
}
 
Example 6
Source File: EnterpriseHDMSeed.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public byte[] getExternalRootPubExtended(CharSequence password) throws MnemonicException
        .MnemonicLengthException {
    DeterministicKey master = masterKey(password);
    DeterministicKey accountKey = getAccount(master);
    DeterministicKey externalChainRoot = getChainRootKey(accountKey, PathType
            .EXTERNAL_ROOT_PATH);
    master.wipe();
    accountKey.wipe();
    byte[] ext = externalChainRoot.getPubKeyExtended();
    externalChainRoot.clearPrivateKey();
    externalChainRoot.clearChainCode();
    return ext;
}
 
Example 7
Source File: HDMAddress.java    From bitherj with Apache License 2.0 4 votes vote down vote up
public String signMessage(String msg, CharSequence password) {
    DeterministicKey key = keychain.getExternalKey(pubs.index, password);
    String result = key.signMessage(msg);
    key.clearPrivateKey();
    return result;
}
 
Example 8
Source File: DesktopHDMAddress.java    From bitherj with Apache License 2.0 4 votes vote down vote up
public String signMessage(String msg, CharSequence password) {
    DeterministicKey key = keychain.getExternalKey(pubs.index, password);
    String result = key.signMessage(msg);
    key.clearPrivateKey();
    return result;
}