Java Code Examples for org.bitcoinj.crypto.KeyCrypterScrypt#deriveKey()

The following examples show how to use org.bitcoinj.crypto.KeyCrypterScrypt#deriveKey() . 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: CoreWalletsService.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
public void removeWalletPassword(String password) {
    verifyWalletIsAvailableAndEncrypted();
    KeyCrypterScrypt keyCrypterScrypt = getKeyCrypterScrypt();

    KeyParameter aesKey = keyCrypterScrypt.deriveKey(password);
    if (!walletsManager.checkAESKey(aesKey))
        throw new IllegalStateException("incorrect password");

    walletsManager.decryptWallets(aesKey);
    walletsManager.backupWallets();
}
 
Example 2
Source File: KeyDerivationTasks.java    From green_android with GNU General Public License v3.0 4 votes vote down vote up
public KeyDerivationTasks(KeyCrypterScrypt scrypt, String password, @Nullable Duration targetTime) {
    keyDerivationTask = new Task<KeyParameter>() {
        @Override
        protected KeyParameter call() throws Exception {
            long start = System.currentTimeMillis();
            try {
                log.info("Started key derivation");
                KeyParameter result = scrypt.deriveKey(password);
                timeTakenMsec = (int) (System.currentTimeMillis() - start);
                log.info("Key derivation done in {}ms", timeTakenMsec);
                return result;
            } catch (Throwable e) {
                log.error("Exception during key derivation", e);
                throw e;
            }
        }
    };

    // And the fake progress meter ... if the vals were calculated correctly progress bar should reach 100%
    // a brief moment after the keys were derived successfully.
    progressTask = new Task<Void>() {
        private KeyParameter aesKey;

        @Override
        protected Void call() throws Exception {
            if (targetTime != null) {
                long startTime = System.currentTimeMillis();
                long curTime;
                long targetTimeMillis = targetTime.toMillis();
                while ((curTime = System.currentTimeMillis()) < startTime + targetTimeMillis) {
                    double progress = (curTime - startTime) / (double) targetTimeMillis;
                    updateProgress(progress, 1.0);

                    // 60fps would require 16msec sleep here.
                    Uninterruptibles.sleepUninterruptibly(20, TimeUnit.MILLISECONDS);
                }
                // Wait for the encryption thread before switching back to main UI.
                updateProgress(1.0, 1.0);
            } else {
                updateProgress(-1, -1);
            }
            aesKey = keyDerivationTask.get();
            return null;
        }

        @Override
        protected void succeeded() {
            checkGuiThread();
            onFinish(aesKey, timeTakenMsec);
        }
    };
    progress = progressTask.progressProperty();
}
 
Example 3
Source File: KeyDerivationTasks.java    From thunder with GNU Affero General Public License v3.0 4 votes vote down vote up
public KeyDerivationTasks (KeyCrypterScrypt scrypt, String password, @Nullable Duration targetTime) {
    keyDerivationTask = new Task<KeyParameter>() {
        @Override
        protected KeyParameter call () throws Exception {
            long start = System.currentTimeMillis();
            try {
                log.info("Started key derivation");
                KeyParameter result = scrypt.deriveKey(password);
                timeTakenMsec = (int) (System.currentTimeMillis() - start);
                log.info("Key derivation done in {}ms", timeTakenMsec);
                return result;
            } catch (Throwable e) {
                log.error("Exception during key derivation", e);
                throw e;
            }
        }
    };

    // And the fake progress meter ... if the vals were calculated correctly progress bar should reach 100%
    // a brief moment after the keys were derived successfully.
    progressTask = new Task<Void>() {
        private KeyParameter aesKey;

        @Override
        protected Void call () throws Exception {
            if (targetTime != null) {
                long startTime = System.currentTimeMillis();
                long curTime;
                long targetTimeMillis = targetTime.toMillis();
                while ((curTime = System.currentTimeMillis()) < startTime + targetTimeMillis) {
                    double progress = (curTime - startTime) / (double) targetTimeMillis;
                    updateProgress(progress, 1.0);

                    // 60fps would require 16msec sleep here.
                    Uninterruptibles.sleepUninterruptibly(20, TimeUnit.MILLISECONDS);
                }
                // Wait for the encryption thread before switching back to main UI.
                updateProgress(1.0, 1.0);
            } else {
                updateProgress(-1, -1);
            }
            aesKey = keyDerivationTask.get();
            return null;
        }

        @Override
        protected void succeeded () {
            checkGuiThread();
            onFinish(aesKey, timeTakenMsec);
        }
    };
    progress = progressTask.progressProperty();
}
 
Example 4
Source File: KeyDerivationTasks.java    From GreenBits with GNU General Public License v3.0 4 votes vote down vote up
public KeyDerivationTasks(KeyCrypterScrypt scrypt, String password, @Nullable Duration targetTime) {
    keyDerivationTask = new Task<KeyParameter>() {
        @Override
        protected KeyParameter call() throws Exception {
            long start = System.currentTimeMillis();
            try {
                log.info("Started key derivation");
                KeyParameter result = scrypt.deriveKey(password);
                timeTakenMsec = (int) (System.currentTimeMillis() - start);
                log.info("Key derivation done in {}ms", timeTakenMsec);
                return result;
            } catch (Throwable e) {
                log.error("Exception during key derivation", e);
                throw e;
            }
        }
    };

    // And the fake progress meter ... if the vals were calculated correctly progress bar should reach 100%
    // a brief moment after the keys were derived successfully.
    progressTask = new Task<Void>() {
        private KeyParameter aesKey;

        @Override
        protected Void call() throws Exception {
            if (targetTime != null) {
                long startTime = System.currentTimeMillis();
                long curTime;
                long targetTimeMillis = targetTime.toMillis();
                while ((curTime = System.currentTimeMillis()) < startTime + targetTimeMillis) {
                    double progress = (curTime - startTime) / (double) targetTimeMillis;
                    updateProgress(progress, 1.0);

                    // 60fps would require 16msec sleep here.
                    Uninterruptibles.sleepUninterruptibly(20, TimeUnit.MILLISECONDS);
                }
                // Wait for the encryption thread before switching back to main UI.
                updateProgress(1.0, 1.0);
            } else {
                updateProgress(-1, -1);
            }
            aesKey = keyDerivationTask.get();
            return null;
        }

        @Override
        protected void succeeded() {
            checkGuiThread();
            onFinish(aesKey, timeTakenMsec);
        }
    };
    progress = progressTask.progressProperty();
}
 
Example 5
Source File: KeyDerivationTasks.java    From devcoretalk with GNU General Public License v2.0 4 votes vote down vote up
public KeyDerivationTasks(KeyCrypterScrypt scrypt, String password, @Nullable Duration targetTime) {
    keyDerivationTask = new Task<KeyParameter>() {
        @Override
        protected KeyParameter call() throws Exception {
            long start = System.currentTimeMillis();
            try {
                log.info("Started key derivation");
                KeyParameter result = scrypt.deriveKey(password);
                timeTakenMsec = (int) (System.currentTimeMillis() - start);
                log.info("Key derivation done in {}ms", timeTakenMsec);
                return result;
            } catch (Throwable e) {
                log.error("Exception during key derivation", e);
                throw e;
            }
        }
    };

    // And the fake progress meter ... if the vals were calculated correctly progress bar should reach 100%
    // a brief moment after the keys were derived successfully.
    progressTask = new Task<Void>() {
        private KeyParameter aesKey;

        @Override
        protected Void call() throws Exception {
            if (targetTime != null) {
                long startTime = System.currentTimeMillis();
                long curTime;
                long targetTimeMillis = targetTime.toMillis();
                while ((curTime = System.currentTimeMillis()) < startTime + targetTimeMillis) {
                    double progress = (curTime - startTime) / (double) targetTimeMillis;
                    updateProgress(progress, 1.0);

                    // 60fps would require 16msec sleep here.
                    Uninterruptibles.sleepUninterruptibly(20, TimeUnit.MILLISECONDS);
                }
                // Wait for the encryption thread before switching back to main UI.
                updateProgress(1.0, 1.0);
            } else {
                updateProgress(-1, -1);
            }
            aesKey = keyDerivationTask.get();
            return null;
        }

        @Override
        protected void succeeded() {
            checkGuiThread();
            onFinish(aesKey, timeTakenMsec);
        }
    };
    progress = progressTask.progressProperty();
}
 
Example 6
Source File: KeyDerivationTasks.java    From thundernetwork with GNU Affero General Public License v3.0 4 votes vote down vote up
public KeyDerivationTasks(KeyCrypterScrypt scrypt, String password, @Nullable Duration targetTime) {
    keyDerivationTask = new Task<KeyParameter>() {
        @Override
        protected KeyParameter call() throws Exception {
            long start = System.currentTimeMillis();
            try {
                log.info("Started key derivation");
                KeyParameter result = scrypt.deriveKey(password);
                timeTakenMsec = (int) (System.currentTimeMillis() - start);
                log.info("Key derivation done in {}ms", timeTakenMsec);
                return result;
            } catch (Throwable e) {
                log.error("Exception during key derivation", e);
                throw e;
            }
        }
    };

    // And the fake progress meter ... if the vals were calculated correctly progress bar should reach 100%
    // a brief moment after the keys were derived successfully.
    progressTask = new Task<Void>() {
        private KeyParameter aesKey;

        @Override
        protected Void call() throws Exception {
            if (targetTime != null) {
                long startTime = System.currentTimeMillis();
                long curTime;
                long targetTimeMillis = targetTime.toMillis();
                while ((curTime = System.currentTimeMillis()) < startTime + targetTimeMillis) {
                    double progress = (curTime - startTime) / (double) targetTimeMillis;
                    updateProgress(progress, 1.0);

                    // 60fps would require 16msec sleep here.
                    Uninterruptibles.sleepUninterruptibly(20, TimeUnit.MILLISECONDS);
                }
                // Wait for the encryption thread before switching back to main UI.
                updateProgress(1.0, 1.0);
            } else {
                updateProgress(-1, -1);
            }
            aesKey = keyDerivationTask.get();
            return null;
        }

        @Override
        protected void succeeded() {
            checkGuiThread();
            onFinish(aesKey, timeTakenMsec);
        }
    };
    progress = progressTask.progressProperty();
}