本文整理汇总了Java中org.bitcoinj.crypto.KeyCrypterScrypt类的典型用法代码示例。如果您正苦于以下问题:Java KeyCrypterScrypt类的具体用法?Java KeyCrypterScrypt怎么用?Java KeyCrypterScrypt使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
KeyCrypterScrypt类属于org.bitcoinj.crypto包,在下文中一共展示了KeyCrypterScrypt类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: IdealPasswordParameters
import org.bitcoinj.crypto.KeyCrypterScrypt; //导入依赖的package包/类
public IdealPasswordParameters(String password) {
final int targetTimeMsec = 2000;
int iterations = 16384;
KeyCrypterScrypt scrypt = new KeyCrypterScrypt(iterations);
long now = System.currentTimeMillis();
scrypt.deriveKey(password);
long time = System.currentTimeMillis() - now;
log.info("Initial iterations took {} msec", time);
// N can only be a power of two, so we keep shifting both iterations and doubling time taken
// until we are in sorta the right general area.
while (time < targetTimeMsec) {
iterations <<= 1;
time *= 2;
}
realIterations = iterations;
// Fudge it by +10% to ensure our progress meter is always a bit behind the real encryption. Plus
// without this it seems the real scrypting always takes a bit longer than we estimated for some reason.
realTargetTime = Duration.ofMillis((long) (time * 1.1));
}
示例2: deterministicUpgradeEncrypted
import org.bitcoinj.crypto.KeyCrypterScrypt; //导入依赖的package包/类
@Test
public void deterministicUpgradeEncrypted() throws Exception {
group = new KeyChainGroup(params);
final ECKey key = new ECKey();
group.importKeys(key);
final KeyCrypterScrypt crypter = new KeyCrypterScrypt();
final KeyParameter aesKey = crypter.deriveKey("abc");
assertTrue(group.isDeterministicUpgradeRequired());
group.encrypt(crypter, aesKey);
assertTrue(group.isDeterministicUpgradeRequired());
try {
group.upgradeToDeterministic(0, null);
fail();
} catch (DeterministicUpgradeRequiresPassword e) {
// Expected.
}
group.upgradeToDeterministic(0, aesKey);
assertFalse(group.isDeterministicUpgradeRequired());
final DeterministicSeed deterministicSeed = group.getActiveKeyChain().getSeed();
assertNotNull(deterministicSeed);
assertTrue(deterministicSeed.isEncrypted());
byte[] entropy = checkNotNull(group.getActiveKeyChain().toDecrypted(aesKey).getSeed()).getEntropyBytes();
// Check we used the right key: oldest non rotating.
byte[] truncatedBytes = Arrays.copyOfRange(key.getSecretBytes(), 0, 16);
assertArrayEquals(entropy, truncatedBytes);
}
示例3: confirmClicked
import org.bitcoinj.crypto.KeyCrypterScrypt; //导入依赖的package包/类
@FXML void confirmClicked(ActionEvent event) {
String password = pass1.getText();
if (password.isEmpty() || password.length() < 4) {
informationalAlert("Bad password", "The password you entered is empty or too short.");
return;
}
final KeyCrypterScrypt keyCrypter = (KeyCrypterScrypt) Main.bitcoin.wallet().getKeyCrypter();
checkNotNull(keyCrypter); // We should never arrive at this GUI if the wallet isn't actually encrypted.
KeyDerivationTasks tasks = new KeyDerivationTasks(keyCrypter, password, getTargetTime()) {
@Override
protected void onFinish(KeyParameter aesKey, int timeTakenMsec) {
checkGuiThread();
if (Main.bitcoin.wallet().checkAESKey(aesKey)) {
WalletPasswordController.this.aesKey.set(aesKey);
} else {
log.warn("User entered incorrect password");
fadeOut(progressMeter);
fadeIn(widgetGrid);
fadeIn(explanationLabel);
fadeIn(buttonsBox);
informationalAlert("Wrong password",
"Please try entering your password again, carefully checking for typos or spelling errors.");
}
}
};
progressMeter.progressProperty().bind(tasks.progress);
tasks.start();
fadeIn(progressMeter);
fadeOut(widgetGrid);
fadeOut(explanationLabel);
fadeOut(buttonsBox);
}
示例4: confirmClicked
import org.bitcoinj.crypto.KeyCrypterScrypt; //导入依赖的package包/类
@FXML void confirmClicked(ActionEvent event) {
String password = pass1.getText();
if (password.isEmpty() || password.length() < 4) {
informationalAlert("Bad password", "The password you entered is empty or too short.");
return;
}
final KeyCrypterScrypt keyCrypter = (KeyCrypterScrypt) Main.bitcoin.wallet().getKeyCrypter();
checkNotNull(keyCrypter); // We should never arrive at this GUI if the wallet isn't actually encrypted.
KeyDerivationTasks tasks = new KeyDerivationTasks(keyCrypter, password, getTargetTime()) {
@Override
protected final void onFinish(KeyParameter aesKey, int timeTakenMsec) {
checkGuiThread();
if (Main.bitcoin.wallet().checkAESKey(aesKey)) {
CryptPasswordController.this.aesKey.set(aesKey);
} else {
log.warn("User entered incorrect password");
fadeOut(progressMeter);
fadeIn(widgetGrid);
fadeIn(explanationLabel);
fadeIn(buttonsBox);
informationalAlert("Wrong password",
"Please try entering your password again, carefully checking for typos or spelling errors.");
}
}
};
progressMeter.progressProperty().bind(tasks.progress);
tasks.start();
fadeIn(progressMeter);
fadeOut(widgetGrid);
fadeOut(explanationLabel);
fadeOut(buttonsBox);
}
示例5: cannotMixParams
import org.bitcoinj.crypto.KeyCrypterScrypt; //导入依赖的package包/类
@Test(expected = KeyCrypterException.class)
public void cannotMixParams() throws Exception {
chain = chain.toEncrypted("foobar");
KeyCrypterScrypt scrypter = new KeyCrypterScrypt(2); // Some bogus params.
ECKey key1 = new ECKey().encrypt(scrypter, scrypter.deriveKey("other stuff"));
chain.importKeys(key1);
}
示例6: setUp
import org.bitcoinj.crypto.KeyCrypterScrypt; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
Protos.ScryptParameters.Builder scryptParametersBuilder = Protos.ScryptParameters.newBuilder().setSalt(ByteString.copyFrom(KeyCrypterScrypt.randomSalt()));
ScryptParameters scryptParameters = scryptParametersBuilder.build();
keyCrypter = new KeyCrypterScrypt(scryptParameters);
BriefLogFormatter.init();
}
示例7: confirmClicked
import org.bitcoinj.crypto.KeyCrypterScrypt; //导入依赖的package包/类
@FXML
void confirmClicked (ActionEvent event) {
String password = pass1.getText();
if (password.isEmpty() || password.length() < 4) {
informationalAlert("Bad password", "The password you entered is empty or too short.");
return;
}
final KeyCrypterScrypt keyCrypter = (KeyCrypterScrypt) Main.wallet.getKeyCrypter();
checkNotNull(keyCrypter); // We should never arrive at this GUI if the wallet isn't actually encrypted.
KeyDerivationTasks tasks = new KeyDerivationTasks(keyCrypter, password, getTargetTime()) {
@Override
protected void onFinish (KeyParameter aesKey, int timeTakenMsec) {
checkGuiThread();
if (Main.wallet.checkAESKey(aesKey)) {
WalletPasswordController.this.aesKey.set(aesKey);
} else {
log.warn("User entered incorrect password");
fadeOut(progressMeter);
fadeIn(widgetGrid);
fadeIn(explanationLabel);
fadeIn(buttonsBox);
informationalAlert("Wrong password",
"Please try entering your password again, carefully checking for typos or spelling errors.");
}
}
};
progressMeter.progressProperty().bind(tasks.progress);
tasks.start();
fadeIn(progressMeter);
fadeOut(widgetGrid);
fadeOut(explanationLabel);
fadeOut(buttonsBox);
}
示例8: doInBackground
import org.bitcoinj.crypto.KeyCrypterScrypt; //导入依赖的package包/类
protected Wallet doInBackground(Void... params) {
Intent intent = new Intent(CoinService.ACTION_CLEAR_CONNECTIONS, null,
walletApplication, CoinServiceImpl.class);
walletApplication.startService(intent);
ArrayList<String> seedWords = new ArrayList<String>();
for (String word : seed.trim().split(" ")) {
if (word.isEmpty()) continue;
seedWords.add(word);
}
try {
this.publishProgress("");
walletApplication.setEmptyWallet();
wallet = new Wallet(seedWords, seedPassword);
KeyParameter aesKey = null;
if (password != null && !password.isEmpty()) {
KeyCrypterScrypt crypter = new KeyCrypterScrypt();
aesKey = crypter.deriveKey(password);
wallet.encrypt(crypter, aesKey);
}
for (CoinType type : coinsToCreate) {
this.publishProgress(type.getName());
wallet.createAccount(type, false, aesKey);
}
walletApplication.setWallet(wallet);
walletApplication.saveWalletNow();
} catch (Exception e) {
log.error("Error creating a wallet", e);
errorMessage = e.getMessage();
}
return wallet;
}
示例9: toEncrypted
import org.bitcoinj.crypto.KeyCrypterScrypt; //导入依赖的package包/类
@Override
public SimpleHDKeyChain toEncrypted(CharSequence password) {
checkNotNull(password, "Attempt to encrypt with a null password.");
checkArgument(password.length() > 0, "Attempt to encrypt with an empty password.");
checkState(!rootKey.isEncrypted(), "Attempt to encrypt a root key that is already encrypted.");
checkState(!rootKey.isPubKeyOnly(), "Attempt to encrypt a watching chain.");
KeyCrypter scrypt = new KeyCrypterScrypt();
KeyParameter derivedKey = scrypt.deriveKey(password);
return toEncrypted(scrypt, derivedKey);
}
示例10: toEncrypted
import org.bitcoinj.crypto.KeyCrypterScrypt; //导入依赖的package包/类
@Override
public NxtFamilyKey toEncrypted(CharSequence password) {
checkNotNull(password, "Attempt to encrypt with a null password.");
checkArgument(password.length() > 0, "Attempt to encrypt with an empty password.");
checkState(!entropy.isEncrypted(), "Attempt to encrypt a key that is already encrypted.");
KeyCrypter scrypt = new KeyCrypterScrypt();
KeyParameter derivedKey = scrypt.deriveKey(password);
return toEncrypted(scrypt, derivedKey);
}
示例11: confirmClicked
import org.bitcoinj.crypto.KeyCrypterScrypt; //导入依赖的package包/类
@FXML void confirmClicked(ActionEvent event) {
String password = pass1.getText();
if (password.isEmpty() || password.length() < 4) {
informationalAlert("Bad password", "The password you entered is empty or too short.");
return;
}
final KeyCrypterScrypt keyCrypter = (KeyCrypterScrypt) Main.bitcoin.wallet().getKeyCrypter();
checkNotNull(keyCrypter); // We should never arrive at this GUI if the wallet isn't actually encrypted.
KeyDerivationTasks tasks = new KeyDerivationTasks(keyCrypter, password, getTargetTime()) {
@Override
protected void onFinish(KeyParameter aesKey) {
super.onFinish(aesKey);
checkGuiThread();
if (Main.bitcoin.wallet().checkAESKey(aesKey)) {
WalletPasswordController.this.aesKey.set(aesKey);
} else {
log.warn("User entered incorrect password");
fadeOut(progressMeter);
fadeIn(widgetGrid);
fadeIn(explanationLabel);
fadeIn(buttonsBox);
informationalAlert("Wrong password",
"Please try entering your password again, carefully checking for typos or spelling errors.");
}
}
};
progressMeter.progressProperty().bind(tasks.progress);
tasks.start();
fadeIn(progressMeter);
fadeOut(widgetGrid);
fadeOut(explanationLabel);
fadeOut(buttonsBox);
}
示例12: setPasswordClicked
import org.bitcoinj.crypto.KeyCrypterScrypt; //导入依赖的package包/类
public void setPasswordClicked(ActionEvent event) {
if (!pass1.getText().equals(pass2.getText())) {
informationalAlert("Passwords do not match", "Try re-typing your chosen passwords.");
return;
}
String password = pass1.getText();
// This is kind of arbitrary and we could do much more to help people pick strong passwords.
if (password.length() < 4) {
informationalAlert("Password too short", "You need to pick a password at least five characters or longer.");
return;
}
fadeIn(progressMeter);
fadeIn(padlockImage);
fadeOut(widgetGrid);
fadeOut(explanationLabel);
fadeOut(closeButton);
// Figure out how fast this computer can scrypt. We do it on the UI thread because the delay should be small
// and so we don't really care about blocking here.
IdealPasswordParameters params = new IdealPasswordParameters(password);
KeyCrypterScrypt scrypt = new KeyCrypterScrypt(params.realIterations);
// Write the target time to the wallet so we can make the progress bar work when entering the password.
WalletPasswordController.setTargetTime(params.realTargetTime);
// Deriving the actual key runs on a background thread.
KeyDerivationTasks tasks = new KeyDerivationTasks(scrypt, password, params.realTargetTime) {
@Override
protected void onFinish(KeyParameter aesKey) {
// The actual encryption part doesn't take very long as most private keys are derived on demand.
Main.bitcoin.wallet().encrypt(scrypt, aesKey);
informationalAlert("Wallet encrypted",
"You can remove the password at any time from the settings screen.");
overlayUI.done();
}
};
progressMeter.progressProperty().bind(tasks.progress);
tasks.start();
}
示例13: setUp
import org.bitcoinj.crypto.KeyCrypterScrypt; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
secureRandom = new SecureRandom();
byte[] salt = new byte[KeyCrypterScrypt.SALT_LENGTH];
secureRandom.nextBytes(salt);
Protos.ScryptParameters.Builder scryptParametersBuilder = Protos.ScryptParameters.newBuilder().setSalt(ByteString.copyFrom(salt));
ScryptParameters scryptParameters = scryptParametersBuilder.build();
keyCrypter = new KeyCrypterScrypt(scryptParameters);
BriefLogFormatter.init();
}
示例14: encryptionWhilstEmpty
import org.bitcoinj.crypto.KeyCrypterScrypt; //导入依赖的package包/类
@Test
public void encryptionWhilstEmpty() throws Exception {
group = new KeyChainGroup(params);
group.setLookaheadSize(5);
KeyCrypterScrypt scrypt = new KeyCrypterScrypt(2);
final KeyParameter aesKey = scrypt.deriveKey("password");
group.encrypt(scrypt, aesKey);
assertTrue(group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS).isEncrypted());
final ECKey key = group.currentKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
group.decrypt(aesKey);
assertFalse(checkNotNull(group.findKeyFromPubKey(key.getPubKey())).isEncrypted());
}
示例15: serialization
import org.bitcoinj.crypto.KeyCrypterScrypt; //导入依赖的package包/类
@Test
public void serialization() throws Exception {
System.out.println("KeyChainGroupTest#serialisation group:" + group.getActiveKeyChain().getKeys(true).toString());
assertEquals(INITIAL_KEYS + 1 /* for the seed */, group.serializeToProtobuf().size());
group = KeyChainGroup.fromProtobufUnencrypted(params, group.serializeToProtobuf());
group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
DeterministicKey key1 = group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
DeterministicKey key2 = group.freshKey(KeyChain.KeyPurpose.CHANGE);
group.getBloomFilterElementCount();
List<Protos.Key> protoKeys1 = group.serializeToProtobuf();
assertEquals(INITIAL_KEYS + ((LOOKAHEAD_SIZE + 2) * 2) + 1 /* for the seed */ + 1, protoKeys1.size());
group.importKeys(new ECKey());
List<Protos.Key> protoKeys2 = group.serializeToProtobuf();
assertEquals(INITIAL_KEYS + ((LOOKAHEAD_SIZE + 2) * 2) + 1 /* for the seed */ + 2, protoKeys2.size());
group = KeyChainGroup.fromProtobufUnencrypted(params, protoKeys1);
assertEquals(INITIAL_KEYS + ((LOOKAHEAD_SIZE + 2) * 2) + 1 /* for the seed */ + 1, protoKeys1.size());
assertTrue(group.hasKey(key1));
assertTrue(group.hasKey(key2));
assertEquals(key2, group.currentKey(KeyChain.KeyPurpose.CHANGE));
assertEquals(key1, group.currentKey(KeyChain.KeyPurpose.RECEIVE_FUNDS));
group = KeyChainGroup.fromProtobufUnencrypted(params, protoKeys2);
assertEquals(INITIAL_KEYS + ((LOOKAHEAD_SIZE + 2) * 2) + 1 /* for the seed */ + 2, protoKeys2.size());
assertTrue(group.hasKey(key1));
assertTrue(group.hasKey(key2));
KeyCrypterScrypt scrypt = new KeyCrypterScrypt(2);
final KeyParameter aesKey = scrypt.deriveKey("password");
group.encrypt(scrypt, aesKey);
List<Protos.Key> protoKeys3 = group.serializeToProtobuf();
group = KeyChainGroup.fromProtobufEncrypted(params, protoKeys3, scrypt);
assertTrue(group.isEncrypted());
assertTrue(group.checkPassword("password"));
group.decrypt(aesKey);
// No need for extensive contents testing here, as that's done in the keychain class tests.
}