本文整理汇总了Java中org.bitcoinj.crypto.KeyCrypter类的典型用法代码示例。如果您正苦于以下问题:Java KeyCrypter类的具体用法?Java KeyCrypter怎么用?Java KeyCrypter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KeyCrypter类属于org.bitcoinj.crypto包,在下文中一共展示了KeyCrypter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encrypt
import org.bitcoinj.crypto.KeyCrypter; //导入依赖的package包/类
/**
* Encrypt the keys in the group using the KeyCrypter and the AES key. A good default KeyCrypter to use is
* {@link org.bitcoinj.crypto.KeyCrypterScrypt}.
*
* @throws org.bitcoinj.crypto.KeyCrypterException Thrown if the wallet encryption fails for some reason,
* leaving the group unchanged.
*/
public void encrypt(KeyCrypter keyCrypter, KeyParameter aesKey) {
checkNotNull(keyCrypter, "Attempting to encrypt with a null KeyCrypter");
checkNotNull(aesKey, "Attempting to encrypt with a null KeyParameter");
lock.lock();
try {
if (seed != null) seed = seed.encrypt(keyCrypter, aesKey);
masterKey = masterKey.encrypt(keyCrypter, aesKey, null);
for (WalletAccount account : accounts.values()) {
if (account.isEncryptable()) {
account.encrypt(keyCrypter, aesKey);
}
}
} finally {
lock.unlock();
}
}
示例2: fromProtobuf
import org.bitcoinj.crypto.KeyCrypter; //导入依赖的package包/类
/**
* Returns the key chain found in the given list of keys.
*/
public static NxtFamilyKey fromProtobuf(List<Protos.Key> keys, @Nullable KeyCrypter crypter)
throws UnreadableWalletException {
if (keys.size() != 2) {
throw new UnreadableWalletException("Expected 2 keys, NXT secret and Curve25519 " +
"pub/priv pair, instead got: " + keys.size());
}
Protos.Key entropyProto = keys.get(0);
DeterministicKey entropyKey = KeyUtils.getDeterministicKey(entropyProto, null, crypter);
Protos.Key publicKeyProto = keys.get(1);
if (publicKeyProto.getType() != Protos.Key.Type.ORIGINAL) {
throw new UnreadableWalletException("Unexpected type for NXT public key: " +
publicKeyProto.getType());
}
byte[] publicKeyBytes = publicKeyProto.getPublicKey().toByteArray();
return new NxtFamilyKey(entropyKey, publicKeyBytes);
}
示例3: deriveKey
import org.bitcoinj.crypto.KeyCrypter; //导入依赖的package包/类
public final void deriveKey(final KeyCrypter keyCrypter, final String password)
{
backgroundHandler.post(new Runnable()
{
@Override
public void run()
{
final KeyParameter encryptionKey = keyCrypter.deriveKey(password); // takes time
callbackHandler.post(new Runnable()
{
@Override
public void run()
{
onSuccess(encryptionKey);
}
});
}
});
}
示例4: encrypt
import org.bitcoinj.crypto.KeyCrypter; //导入依赖的package包/类
/**
* Encrypt the keys in the group using the KeyCrypter and the AES key. A good default KeyCrypter to use is
* {@link org.bitcoinj.crypto.KeyCrypterScrypt}.
*
* @throws org.bitcoinj.crypto.KeyCrypterException Thrown if the wallet encryption fails for some reason,
* leaving the group unchanged.
* @throws DeterministicUpgradeRequiredException Thrown if there are random keys but no HD chain.
*/
public void encrypt(KeyCrypter keyCrypter, KeyParameter aesKey) {
checkNotNull(keyCrypter);
checkNotNull(aesKey);
// This code must be exception safe.
BasicKeyChain newBasic = basic.toEncrypted(keyCrypter, aesKey);
List<DeterministicKeyChain> newChains = new ArrayList<DeterministicKeyChain>(chains.size());
if (chains.isEmpty() && basic.numKeys() == 0) {
// No HD chains and no random keys: encrypting an entirely empty keychain group. But we can't do that, we
// must have something to encrypt: so instantiate a new HD chain here.
createAndActivateNewHDChain();
}
for (DeterministicKeyChain chain : chains)
newChains.add(chain.toEncrypted(keyCrypter, aesKey));
this.keyCrypter = keyCrypter;
basic = newBasic;
chains.clear();
chains.addAll(newChains);
}
示例5: KeyChainGroup
import org.bitcoinj.crypto.KeyCrypter; //导入依赖的package包/类
private KeyChainGroup(NetworkParameters params, @Nullable BasicKeyChain basicKeyChain, List<DeterministicKeyChain> chains,
@Nullable EnumMap<KeyChain.KeyPurpose, DeterministicKey> currentKeys, @Nullable KeyCrypter crypter) {
this.params = params;
this.basic = basicKeyChain == null ? new BasicKeyChain() : basicKeyChain;
this.chains = new LinkedList<DeterministicKeyChain>(checkNotNull(chains));
this.keyCrypter = crypter;
this.currentKeys = currentKeys == null
? new EnumMap<KeyChain.KeyPurpose, DeterministicKey>(KeyChain.KeyPurpose.class)
: currentKeys;
this.currentAddresses = new EnumMap<KeyChain.KeyPurpose, Address>(KeyChain.KeyPurpose.class);
maybeLookaheadScripts();
if (isMarried()) {
for (Map.Entry<KeyChain.KeyPurpose, DeterministicKey> entry : this.currentKeys.entrySet()) {
Address address = makeP2SHOutputScript(entry.getValue(), getActiveKeyChain()).getToAddress(params);
currentAddresses.put(entry.getKey(), address);
}
}
}
示例6: encrypt
import org.bitcoinj.crypto.KeyCrypter; //导入依赖的package包/类
/**
*
* ALICE
* Encrypt the keys in the group using the KeyCrypter and the AES key. A good default KeyCrypter to use is
* {@link org.bitcoinj.crypto.KeyCrypterScrypt}.
*
* @throws org.bitcoinj.crypto.KeyCrypterException Thrown if the wallet encryption fails for some reason,
* leaving the group unchanged.
* @throws DeterministicUpgradeRequiredException Thrown if there are random keys but no HD chain.
*/
public void encrypt(KeyCrypter keyCrypter, KeyParameter aesKey, @Nullable ImmutableList<ChildNumber> rootNodeList) {
checkNotNull(keyCrypter);
checkNotNull(aesKey);
// This code must be exception safe.
BasicKeyChain newBasic = basic.toEncrypted(keyCrypter, aesKey);
List<DeterministicKeyChain> newChains = new ArrayList<DeterministicKeyChain>(chains.size());
if (chains.isEmpty() && basic.numKeys() == 0) {
// No HD chains and no random keys: encrypting an entirely empty keychain group. But we can't do that, we
// must have something to encrypt: so instantiate a new HD chain here.
createAndActivateNewHDChain(rootNodeList);
}
for (DeterministicKeyChain chain : chains) {
log.debug("chain: " + chain.toString());
newChains.add(chain.toEncrypted(keyCrypter, aesKey, rootNodeList));
}
this.keyCrypter = keyCrypter;
basic = newBasic;
chains.clear();
chains.addAll(newChains);
}
示例7: decrypt
import org.bitcoinj.crypto.KeyCrypter; //导入依赖的package包/类
/**
* Queue a request to decrypt this wallet. This returns immediately, as the
* actual work is done on the network thread in order to ensure the thread
* context is correct. Unhandled errors are reported back to Network.
*
* @param password password to decrypt the wallet with
* @param onSuccess callback on success
* @param onWalletNotEncrypted callback if the wallet is not encrypted
* @param onCrypterError callback in case of an error in the key crypter
* @param timeout timeout on queueing the work request
* @param timeUnit time unit for the timeout
*/
public void decrypt(String password, Consumer<Object> onSuccess,
Consumer<Object> onWalletNotEncrypted,
Consumer<KeyCrypterException> onCrypterError,
final long timeout, final TimeUnit timeUnit) {
this.networkExecutor.execute((Runnable) () -> {
final Wallet wallet = wallet();
if (!wallet.isEncrypted()) {
onCrypterError.accept(null);
} else {
final KeyCrypter keyCrypter = wallet().getKeyCrypter();
if (keyCrypter == null) {
throw new IllegalStateException("Wallet is encrypted but has no key crypter.");
} else {
try {
wallet().decrypt(keyCrypter.deriveKey(password));
encrypted.set(false);
onSuccess.accept(null);
} catch (KeyCrypterException ex) {
onCrypterError.accept(ex);
}
}
}
});
}
示例8: getKeyCrypter
import org.bitcoinj.crypto.KeyCrypter; //导入依赖的package包/类
/**
* Get the wallet pocket's KeyCrypter, or null if the wallet pocket is not encrypted.
* (Used in encrypting/ decrypting an ECKey).
*/
@Nullable
@Override
public KeyCrypter getKeyCrypter() {
lock.lock();
try {
return keys.getKeyCrypter();
} finally {
lock.unlock();
}
}
示例9: encrypt
import org.bitcoinj.crypto.KeyCrypter; //导入依赖的package包/类
/**
* Encrypt the keys in the group using the KeyCrypter and the AES key. A good default KeyCrypter to use is
* {@link org.bitcoinj.crypto.KeyCrypterScrypt}.
*
* @throws org.bitcoinj.crypto.KeyCrypterException Thrown if the wallet encryption fails for some reason,
* leaving the group unchanged.
*/
@Override
public void encrypt(KeyCrypter keyCrypter, KeyParameter aesKey) {
Preconditions.checkNotNull(keyCrypter);
Preconditions.checkNotNull(aesKey);
lock.lock();
try {
this.keys = this.keys.toEncrypted(keyCrypter, aesKey);
} finally {
lock.unlock();
}
}
示例10: getKeyCrypter
import org.bitcoinj.crypto.KeyCrypter; //导入依赖的package包/类
/** Returns the {@link KeyCrypter} in use or null if the key chain is not encrypted. */
@Nullable
public KeyCrypter getKeyCrypter() {
lock.lock();
try {
return masterKey.getKeyCrypter();
} finally {
lock.unlock();
}
}
示例11: SimpleHDKeyChain
import org.bitcoinj.crypto.KeyCrypter; //导入依赖的package包/类
SimpleHDKeyChain(DeterministicKey rootkey, @Nullable KeyCrypter crypter) {
this.rootKey = rootkey;
simpleKeyChain = new SimpleKeyChain(crypter);
if (!rootkey.isEncrypted()) {
initializeHierarchyUnencrypted(rootKey);
}
// Else...
// We can't initialize ourselves with just an encrypted seed, so we expected deserialization code to do the
// rest of the setup (loading the root key).
}
示例12: toEncrypted
import org.bitcoinj.crypto.KeyCrypter; //导入依赖的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);
}
示例13: toDecrypted
import org.bitcoinj.crypto.KeyCrypter; //导入依赖的package包/类
@Override
public SimpleHDKeyChain toDecrypted(CharSequence password) {
checkNotNull(password, "Attempt to decrypt with a null password.");
checkArgument(password.length() > 0, "Attempt to decrypt with an empty password.");
KeyCrypter crypter = getKeyCrypter();
checkState(crypter != null, "Chain not encrypted");
KeyParameter derivedKey = crypter.deriveKey(password);
return toDecrypted(derivedKey);
}
示例14: NxtFamilyKey
import org.bitcoinj.crypto.KeyCrypter; //导入依赖的package包/类
public NxtFamilyKey(DeterministicKey entropy, @Nullable KeyCrypter keyCrypter,
@Nullable KeyParameter key) {
checkArgument(!entropy.isEncrypted(), "Entropy must not be encrypted");
this.publicKey = Crypto.getPublicKey(entropy.getPrivKeyBytes());
// Encrypt entropy if needed
if (keyCrypter != null && key != null) {
this.entropy = entropy.encrypt(keyCrypter, key, entropy.getParent());
} else {
this.entropy = entropy;
}
}
示例15: toEncrypted
import org.bitcoinj.crypto.KeyCrypter; //导入依赖的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);
}