本文整理汇总了Java中org.bitcoinj.crypto.KeyCrypter类的典型用法代码示例。如果您正苦于以下问题:Java KeyCrypter类的具体用法?Java KeyCrypter怎么用?Java KeyCrypter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KeyCrypter类属于org.bitcoinj.crypto包,在下文中一共展示了KeyCrypter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
}
}
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:26,代码来源:Wallet.java
示例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);
}
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:23,代码来源:NxtFamilyKey.java
示例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);
}
});
}
});
}
开发者ID:soapboxsys,项目名称:ombuds-android,代码行数:21,代码来源:DeriveKeyTask.java
示例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);
}
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:27,代码来源:KeyChainGroup.java
示例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);
}
}
}
开发者ID:DigiByte-Team,项目名称:digibytej-alice,代码行数:20,代码来源:KeyChainGroup.java
示例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);
}
开发者ID:DigiByte-Team,项目名称:digibytej-alice,代码行数:31,代码来源:KeyChainGroup.java
示例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);
}
}
}
});
}
开发者ID:rnicoll,项目名称:cate,代码行数:38,代码来源:Network.java
示例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();
}
}
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:15,代码来源:WalletPocketHD.java
示例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();
}
}
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:20,代码来源:WalletPocketHD.java
示例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();
}
}
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:11,代码来源:Wallet.java
示例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).
}
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:11,代码来源:SimpleHDKeyChain.java
示例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);
}
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:11,代码来源:SimpleHDKeyChain.java
示例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);
}
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:10,代码来源:SimpleHDKeyChain.java
示例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;
}
}
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:12,代码来源:NxtFamilyKey.java
示例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);
}
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:10,代码来源:NxtFamilyKey.java
示例16: toDecrypted
import org.bitcoinj.crypto.KeyCrypter; //导入依赖的package包/类
@Override
public NxtFamilyKey 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);
}
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:10,代码来源:NxtFamilyKey.java
示例17: readWallet
import org.bitcoinj.crypto.KeyCrypter; //导入依赖的package包/类
/**
* <p>Loads wallet data from the given protocol buffer and inserts it into the given Wallet object. This is primarily
* useful when you wish to pre-register extension objects. Note that if loading fails the provided Wallet object
* may be in an indeterminate state and should be thrown away.</p>
*
* <p>A wallet can be unreadable for various reasons, such as inability to open the file, corrupt data, internally
* inconsistent data, a wallet extension marked as mandatory that cannot be handled and so on. You should always
* handle {@link UnreadableWalletException} and communicate failure to the user in an appropriate manner.</p>
*
* @throws UnreadableWalletException thrown in various error conditions (see description).
*/
public NxtFamilyWallet readWallet(Protos.WalletPocket walletProto, @Nullable KeyCrypter keyCrypter) throws UnreadableWalletException {
CoinType coinType;
try {
coinType = CoinID.typeFromId(walletProto.getNetworkIdentifier());
} catch (IllegalArgumentException e) {
throw new UnreadableWalletException("Unknown network parameters ID " + walletProto.getNetworkIdentifier());
}
// Read the scrypt parameters that specify how encryption and decryption is performed.
NxtFamilyKey rootKey;
if (keyCrypter != null) {
rootKey = NxtFamilyKey.fromProtobuf(walletProto.getKeyList(), keyCrypter);
} else {
rootKey = NxtFamilyKey.fromProtobuf(walletProto.getKeyList());
}
NxtFamilyWallet pocket;
if (walletProto.hasId()) {
pocket = new NxtFamilyWallet(walletProto.getId(), rootKey, coinType);
} else {
pocket = new NxtFamilyWallet(rootKey, coinType);
}
if (walletProto.hasDescription()) {
pocket.setDescription(walletProto.getDescription());
}
// TODO ready transactions? Check com.fillerino.core.wallet WalletPocketProtobufSerializer
return pocket;
}
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:43,代码来源:NxtFamilyWalletProtobufSerializer.java
示例18: getKeyCrypter
import org.bitcoinj.crypto.KeyCrypter; //导入依赖的package包/类
@Override
public KeyCrypter getKeyCrypter() {
lock.lock();
try {
return rootKey.getKeyCrypter();
} finally {
lock.unlock();
}
}
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:10,代码来源:NxtFamilyWallet.java
示例19: encrypt
import org.bitcoinj.crypto.KeyCrypter; //导入依赖的package包/类
@Override
public void encrypt(KeyCrypter keyCrypter, KeyParameter aesKey) {
Preconditions.checkNotNull(keyCrypter);
Preconditions.checkNotNull(aesKey);
lock.lock();
try {
this.rootKey = this.rootKey.toEncrypted(keyCrypter, aesKey);
} finally {
lock.unlock();
}
}
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:13,代码来源:NxtFamilyWallet.java
示例20: KeyChainGroup
import org.bitcoinj.crypto.KeyCrypter; //导入依赖的package包/类
private KeyChainGroup(NetworkParameters params, @Nullable BasicKeyChain basicKeyChain, List<DeterministicKeyChain> chains,
@Nullable EnumMap<KeyChain.KeyPurpose, DeterministicKey> currentKeys, Multimap<DeterministicKey,
DeterministicKeyChain> followingKeychains, int sigsRequiredToSpend, @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);
this.followingKeychains = HashMultimap.create();
if (followingKeychains != null) {
this.followingKeychains.putAll(followingKeychains);
}
this.sigsRequiredToSpend = sigsRequiredToSpend;
marriedKeysRedeemData = new LinkedHashMap<ByteString, RedeemData>();
maybeLookaheadScripts();
if (!this.followingKeychains.isEmpty()) {
DeterministicKey followedWatchKey = getActiveKeyChain().getWatchingKey();
for (Map.Entry<KeyChain.KeyPurpose, DeterministicKey> entry : this.currentKeys.entrySet()) {
Address address = makeP2SHOutputScript(entry.getValue(), followedWatchKey).getToAddress(params);
currentAddresses.put(entry.getKey(), address);
}
}
}
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:28,代码来源:KeyChainGroup.java
注:本文中的org.bitcoinj.crypto.KeyCrypter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论