• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java KeyChain类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.bitcoinj.wallet.KeyChain的典型用法代码示例。如果您正苦于以下问题:Java KeyChain类的具体用法?Java KeyChain怎么用?Java KeyChain使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



KeyChain类属于org.bitcoinj.wallet包,在下文中一共展示了KeyChain类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: derive

import org.bitcoinj.wallet.KeyChain; //导入依赖的package包/类
@Test
public void derive() throws Exception {
    ECKey key1 = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    ECKey key2 = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);

    final Address address = new Address(UnitTestParams.get(), "n1bQNoEx8uhmCzzA5JPG6sFdtsUQhwiQJV");
    assertEquals(address, key1.toAddress(UnitTestParams.get()));
    assertEquals("mnHUcqUVvrfi5kAaXJDQzBb9HsWs78b42R", key2.toAddress(UnitTestParams.get()).toString());
    assertEquals(key1, chain.findKeyFromPubHash(address.getHash160()));
    assertEquals(key2, chain.findKeyFromPubKey(key2.getPubKey()));

    key1.sign(Sha256Hash.ZERO_HASH);

    ECKey key3 = chain.getKey(KeyChain.KeyPurpose.CHANGE);
    assertEquals("mqumHgVDqNzuXNrszBmi7A2UpmwaPMx4HQ", key3.toAddress(UnitTestParams.get()).toString());
    key3.sign(Sha256Hash.ZERO_HASH);
}
 
开发者ID:egordon,项目名称:CoinJoin,代码行数:18,代码来源:DeterministicKeyChainTest.java


示例2: testRoundTripMarriedWallet

import org.bitcoinj.wallet.KeyChain; //导入依赖的package包/类
@Test
public void testRoundTripMarriedWallet() throws Exception {
    // create 2-of-2 married wallet
    myWallet = new Wallet(PARAMS);
    final DeterministicKeyChain partnerChain = new DeterministicKeyChain(new SecureRandom());
    DeterministicKey partnerKey = DeterministicKey.deserializeB58(null, partnerChain.getWatchingKey().serializePubB58(PARAMS), PARAMS);
    MarriedKeyChain chain = MarriedKeyChain.builder()
            .random(new SecureRandom())
            .followingKeys(partnerKey)
            .threshold(2).build();
    myWallet.addAndActivateHDChain(chain);

    myAddress = myWallet.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);

    Wallet wallet1 = roundTrip(myWallet);
    assertEquals(0, wallet1.getTransactions(true).size());
    assertEquals(Coin.ZERO, wallet1.getBalance());
    assertEquals(2, wallet1.getActiveKeyChain().getSigsRequiredToSpend());
    assertEquals(myAddress, wallet1.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS));
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:21,代码来源:WalletProtobufSerializerTest.java


示例3: encryption

import org.bitcoinj.wallet.KeyChain; //导入依赖的package包/类
public void encryption(SimpleHDKeyChain unencChain) throws UnreadableWalletException {
    DeterministicKey key1 = unencChain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    SimpleHDKeyChain encChain = unencChain.toEncrypted("open secret");
    DeterministicKey encKey1 = encChain.findKeyFromPubKey(key1.getPubKey());
    checkEncryptedKeyChain(encChain, key1);

    // Round-trip to ensure de/serialization works and that we can store two chains and they both deserialize.
    List<Protos.Key> serialized = encChain.toProtobuf();
    System.out.println(protoToString(serialized));
    encChain = SimpleHDKeyChain.fromProtobuf(serialized, encChain.getKeyCrypter());
    checkEncryptedKeyChain(encChain, unencChain.findKeyFromPubKey(key1.getPubKey()));

    DeterministicKey encKey2 = encChain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    // Decrypt and check the keys match.
    SimpleHDKeyChain decChain = encChain.toDecrypted("open secret");
    DeterministicKey decKey1 = decChain.findKeyFromPubHash(encKey1.getPubKeyHash());
    DeterministicKey decKey2 = decChain.findKeyFromPubHash(encKey2.getPubKeyHash());
    assertEquals(decKey1.getPubKeyPoint(), encKey1.getPubKeyPoint());
    assertEquals(decKey2.getPubKeyPoint(), encKey2.getPubKeyPoint());
    assertFalse(decKey1.isEncrypted());
    assertFalse(decKey2.isEncrypted());
    assertNotEquals(encKey1.getParent(), decKey1.getParent());   // parts of a different hierarchy
    // Check we can once again derive keys from the decrypted chain.
    decChain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS).sign(Sha256Hash.ZERO_HASH);
    decChain.getKey(KeyChain.KeyPurpose.CHANGE).sign(Sha256Hash.ZERO_HASH);
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:27,代码来源:SimpleHDKeyChainTest.java


示例4: issuedKeys

import org.bitcoinj.wallet.KeyChain; //导入依赖的package包/类
@Test
public void issuedKeys() throws Bip44KeyLookAheadExceededException {
    List<BitAddress> issuedAddresses = new ArrayList<>();
    assertEquals(0, pocket.getIssuedReceiveAddresses().size());
    assertEquals(0, pocket.keys.getNumIssuedExternalKeys());

    issuedAddresses.add(0, pocket.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS));
    BitAddress freshAddress = pocket.getFreshReceiveAddress();
    assertEquals(freshAddress, pocket.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS));
    assertEquals(1, pocket.getIssuedReceiveAddresses().size());
    assertEquals(1, pocket.keys.getNumIssuedExternalKeys());
    assertEquals(issuedAddresses, pocket.getIssuedReceiveAddresses());

    issuedAddresses.add(0, pocket.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS));
    freshAddress = pocket.getFreshReceiveAddress();
    assertEquals(freshAddress, pocket.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS));
    assertEquals(2, pocket.getIssuedReceiveAddresses().size());
    assertEquals(2, pocket.keys.getNumIssuedExternalKeys());
    assertEquals(issuedAddresses, pocket.getIssuedReceiveAddresses());
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:21,代码来源:WalletPocketHDTest.java


示例5: bloom1

import org.bitcoinj.wallet.KeyChain; //导入依赖的package包/类
@Test
public void bloom1() {
    DeterministicKey key2 = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    DeterministicKey key1 = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);

    int numEntries =
            (((chain.getLookaheadSize() + chain.getLookaheadThreshold()) * 2)   // * 2 because of internal/external
          + chain.numLeafKeysIssued()
          + 4  // one root key + one account key + two chain keys (internal/external)
            ) * 2;  // because the filter contains keys and key hashes.
    assertEquals(numEntries, chain.numBloomFilterEntries());
    BloomFilter filter = chain.getFilter(numEntries, 0.001, 1);
    assertTrue(filter.contains(key1.getPubKey()));
    assertTrue(filter.contains(key1.getPubKeyHash()));
    assertTrue(filter.contains(key2.getPubKey()));
    assertTrue(filter.contains(key2.getPubKeyHash()));

    // The lookahead zone is tested in bloom2 and via KeyChainGroupTest.bloom
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:20,代码来源:DeterministicKeyChainTest.java


示例6: testRoundTripMarriedWallet

import org.bitcoinj.wallet.KeyChain; //导入依赖的package包/类
@Test
public void testRoundTripMarriedWallet() throws Exception {
    // create 2-of-2 married wallet
    myWallet = new Wallet(params);
    final DeterministicKeyChain keyChain = new DeterministicKeyChain(new SecureRandom());
    DeterministicKey partnerKey = DeterministicKey.deserializeB58(null, keyChain.getWatchingKey().serializePubB58());

    myWallet.addFollowingAccountKeys(ImmutableList.of(partnerKey), 2);
    myAddress = myWallet.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);

    Wallet wallet1 = roundTrip(myWallet);
    assertEquals(0, wallet1.getTransactions(true).size());
    assertEquals(Coin.ZERO, wallet1.getBalance());
    assertEquals(2, wallet1.getSigsRequiredToSpend());
    assertEquals(myAddress, wallet1.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS));
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:17,代码来源:WalletProtobufSerializerTest.java


示例7: testRoundTripMarriedWallet

import org.bitcoinj.wallet.KeyChain; //导入依赖的package包/类
@Test
public void testRoundTripMarriedWallet() throws Exception {
    // create 2-of-2 married wallet
    myWallet = new Wallet(params);
    final DeterministicKeyChain partnerChain = new DeterministicKeyChain(new SecureRandom());
    DeterministicKey partnerKey = DeterministicKey.deserializeB58(null, partnerChain.getWatchingKey().serializePubB58(params), params);
    MarriedKeyChain chain = MarriedKeyChain.builder()
            .random(new SecureRandom())
            .followingKeys(partnerKey)
            .threshold(2).build();
    myWallet.addAndActivateHDChain(chain);

    myAddress = myWallet.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);

    Wallet wallet1 = roundTrip(myWallet);
    assertEquals(0, wallet1.getTransactions(true).size());
    assertEquals(Coin.ZERO, wallet1.getBalance());
    assertEquals(2, wallet1.getActiveKeychain().getSigsRequiredToSpend());
    assertEquals(myAddress, wallet1.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS));
}
 
开发者ID:DigiByte-Team,项目名称:digibytej-alice,代码行数:21,代码来源:WalletProtobufSerializerTest.java


示例8: deriveKeyFromWallet

import org.bitcoinj.wallet.KeyChain; //导入依赖的package包/类
private ECKey deriveKeyFromWallet(final Wallet wallet, final int iteration, final KeyChain.KeyPurpose keyPurpose) throws UnreadableWalletException, IOException {
    DeterministicKey key = null;
    for (int i = 0; i <= iteration; i++) {
        key = wallet.freshKey(keyPurpose);
    }

    if (key == null) {
        throw new IOException("Unable to derive key");
    }

    return ECKey.fromPrivate(key.getPrivKey());
}
 
开发者ID:toshiapp,项目名称:toshi-headless-client,代码行数:13,代码来源:HDWallet.java


示例9: getKey

import org.bitcoinj.wallet.KeyChain; //导入依赖的package包/类
@Test
public void getKey() {
    ECKey key1 = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    assertTrue(onKeysAddedRan.getAndSet(false));
    assertEquals(key1, onKeysAdded.getAndSet(null).get(0));
    ECKey key2 = chain.getKey(KeyChain.KeyPurpose.CHANGE);
    assertFalse(onKeysAddedRan.getAndSet(false));
    assertEquals(key2, key1);
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:10,代码来源:BasicKeyChainTest.java


示例10: cannotImportEncryptedKey

import org.bitcoinj.wallet.KeyChain; //导入依赖的package包/类
@Test(expected = KeyCrypterException.class)
public void cannotImportEncryptedKey() {
    final ECKey key1 = new ECKey();
    chain.importKeys(ImmutableList.of(key1));
    chain = chain.toEncrypted("foobar");
    ECKey encryptedKey = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    assertTrue(encryptedKey.isEncrypted());

    BasicKeyChain chain2 = new BasicKeyChain();
    chain2.importKeys(ImmutableList.of(encryptedKey));
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:12,代码来源:BasicKeyChainTest.java


示例11: getLastIssuedKey

import org.bitcoinj.wallet.KeyChain; //导入依赖的package包/类
@Test
public void getLastIssuedKey() {
    assertNull(chain.getLastIssuedKey(KeyChain.KeyPurpose.RECEIVE_FUNDS));
    assertNull(chain.getLastIssuedKey(KeyChain.KeyPurpose.CHANGE));
    DeterministicKey extKey = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    DeterministicKey intKey = chain.getKey(KeyChain.KeyPurpose.CHANGE);
    assertEquals(extKey, chain.getLastIssuedKey(KeyChain.KeyPurpose.RECEIVE_FUNDS));
    assertEquals(intKey, chain.getLastIssuedKey(KeyChain.KeyPurpose.CHANGE));
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:10,代码来源:SimpleHDKeyChainTest.java


示例12: serializeUnencrypted

import org.bitcoinj.wallet.KeyChain; //导入依赖的package包/类
public void serializeUnencrypted(SimpleHDKeyChain keyChain, String expectedSerialization) throws UnreadableWalletException {
    keyChain.setLookaheadSize(10);

    keyChain.maybeLookAhead();
    DeterministicKey key1 = keyChain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    DeterministicKey key2 = keyChain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    DeterministicKey key3 = keyChain.getKey(KeyChain.KeyPurpose.CHANGE);
    List<Protos.Key> keys = keyChain.toProtobuf();
    // 1 master key, 1 account key, 2 internal keys, 3 derived, 20 lookahead and 5 lookahead threshold.
    int numItems =
                      1  // master key/account key
                    + 2  // ext/int parent keys
                    + (keyChain.getLookaheadSize() + keyChain.getLookaheadThreshold()) * 2   // lookahead zone on each chain
            ;
    assertEquals(numItems, keys.size());

    // Get another key that will be lost during round-tripping, to ensure we can derive it again.
    DeterministicKey key4 = keyChain.getKey(KeyChain.KeyPurpose.CHANGE);

    String sb = protoToString(keys);
    assertEquals(expectedSerialization, sb);

    // Round trip the data back and forth to check it is preserved.
    int oldLookaheadSize = keyChain.getLookaheadSize();
    keyChain = SimpleHDKeyChain.fromProtobuf(keys, null);
    assertEquals(expectedSerialization, protoToString(keyChain.toProtobuf()));
    assertEquals(key1, keyChain.findKeyFromPubHash(key1.getPubKeyHash()));
    assertEquals(key2, keyChain.findKeyFromPubHash(key2.getPubKeyHash()));
    assertEquals(key3, keyChain.findKeyFromPubHash(key3.getPubKeyHash()));
    assertEquals(key4, keyChain.getKey(KeyChain.KeyPurpose.CHANGE));
    key1.sign(Sha256Hash.ZERO_HASH);
    key2.sign(Sha256Hash.ZERO_HASH);
    key3.sign(Sha256Hash.ZERO_HASH);
    key4.sign(Sha256Hash.ZERO_HASH);
    assertEquals(oldLookaheadSize, keyChain.getLookaheadSize());
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:37,代码来源:SimpleHDKeyChainTest.java


示例13: checkEncryptedKeyChain

import org.bitcoinj.wallet.KeyChain; //导入依赖的package包/类
private void checkEncryptedKeyChain(SimpleHDKeyChain encChain, DeterministicKey key1) {
    // Check we can look keys up and extend the chain without the AES key being provided.
    DeterministicKey encKey1 = encChain.findKeyFromPubKey(key1.getPubKey());
    DeterministicKey encKey2 = encChain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    assertFalse(key1.isEncrypted());
    assertTrue(encKey1.isEncrypted());
    assertEquals(encKey1.getPubKeyPoint(), key1.getPubKeyPoint());
    final KeyParameter aesKey = checkNotNull(encChain.getKeyCrypter()).deriveKey("open secret");
    encKey1.sign(Sha256Hash.ZERO_HASH, aesKey);
    encKey2.sign(Sha256Hash.ZERO_HASH, aesKey);
    assertTrue(encChain.checkAESKey(aesKey));
    assertFalse(encChain.checkPassword("access denied"));
    assertTrue(encChain.checkPassword("open secret"));
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:15,代码来源:SimpleHDKeyChainTest.java


示例14: testSingleAddressWallet

import org.bitcoinj.wallet.KeyChain; //导入依赖的package包/类
@Test
public void testSingleAddressWallet() throws Exception {
    ECKey key = pocket.keys.getCurrentUnusedKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    BitWalletSingleKey bitWalletSingleKey = new BitWalletSingleKey(DOGE, key);
    bitWalletSingleKey.onConnection(getBlockchainConnection(DOGE));
    assertEquals(DOGE.value("10"), bitWalletSingleKey.getBalance());
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:8,代码来源:WalletPocketHDTest.java


示例15: getKeys

import org.bitcoinj.wallet.KeyChain; //导入依赖的package包/类
@Test
public void getKeys() throws Exception {
    chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    chain.getKey(KeyChain.KeyPurpose.CHANGE);
    chain.maybeLookAhead();
    assertEquals(2, chain.getKeys(false).size());
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:8,代码来源:DeterministicKeyChainTest.java


示例16: events

import org.bitcoinj.wallet.KeyChain; //导入依赖的package包/类
@Test
public void events() throws Exception {
    // Check that we get the right events at the right time.
    final List<List<ECKey>> listenerKeys = Lists.newArrayList();
    long secs = 1389353062L;
    chain = new DeterministicKeyChain(ENTROPY, "", secs);
    chain.addEventListener(new AbstractKeyChainEventListener() {
        @Override
        public void onKeysAdded(List<ECKey> keys) {
            listenerKeys.add(keys);
        }
    }, Threading.SAME_THREAD);
    assertEquals(0, listenerKeys.size());
    chain.setLookaheadSize(5);
    assertEquals(0, listenerKeys.size());
    ECKey key = chain.getKey(KeyChain.KeyPurpose.CHANGE);
    assertEquals(1, listenerKeys.size());  // 1 event
    final List<ECKey> firstEvent = listenerKeys.get(0);
    assertEquals(1, firstEvent.size());
    assertTrue(firstEvent.contains(key));   // order is not specified.
    listenerKeys.clear();

    chain.maybeLookAhead();
    final List<ECKey> secondEvent = listenerKeys.get(0);
    assertEquals(12, secondEvent.size());  // (5 lookahead keys, +1 lookahead threshold) * 2 chains
    listenerKeys.clear();

    chain.getKey(KeyChain.KeyPurpose.CHANGE);
    // At this point we've entered the threshold zone so more keys won't immediately trigger more generations.
    assertEquals(0, listenerKeys.size());  // 1 event
    final int lookaheadThreshold = chain.getLookaheadThreshold() + chain.getLookaheadSize();
    for (int i = 0; i < lookaheadThreshold; i++)
        chain.getKey(KeyChain.KeyPurpose.CHANGE);
    assertEquals(1, listenerKeys.size());  // 1 event
    assertEquals(1, listenerKeys.get(0).size());  // 1 key.
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:37,代码来源:DeterministicKeyChainTest.java


示例17: random

import org.bitcoinj.wallet.KeyChain; //导入依赖的package包/类
@Test
public void random() {
    // Can't test much here but verify the constructor worked and the class is functional. The other tests rely on
    // a fixed seed to be deterministic.
    chain = new DeterministicKeyChain(new SecureRandom(), 384);
    chain.setLookaheadSize(10);
    chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS).sign(Sha256Hash.ZERO_HASH);
    chain.getKey(KeyChain.KeyPurpose.CHANGE).sign(Sha256Hash.ZERO_HASH);
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:10,代码来源:DeterministicKeyChainTest.java


示例18: serializeUnencrypted

import org.bitcoinj.wallet.KeyChain; //导入依赖的package包/类
@Test
public void serializeUnencrypted() throws UnreadableWalletException {
    chain.maybeLookAhead();
    DeterministicKey key1 = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    DeterministicKey key2 = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    DeterministicKey key3 = chain.getKey(KeyChain.KeyPurpose.CHANGE);
    List<Protos.Key> keys = chain.serializeToProtobuf();
    // 1 mnemonic/seed, 1 master key, 1 account key, 2 internal keys, 3 derived, 20 lookahead and 5 lookahead threshold.
    int numItems =
            1  // mnemonic/seed
          + 1  // master key
          + 1  // account key
          + 2  // ext/int parent keys
          + (chain.getLookaheadSize() + chain.getLookaheadThreshold()) * 2   // lookahead zone on each chain
    ;
    assertEquals(numItems, keys.size());

    // Get another key that will be lost during round-tripping, to ensure we can derive it again.
    DeterministicKey key4 = chain.getKey(KeyChain.KeyPurpose.CHANGE);

    final String EXPECTED_SERIALIZATION = checkSerialization(keys, "deterministic-wallet-serialization.txt");

    // Round trip the data back and forth to check it is preserved.
    int oldLookaheadSize = chain.getLookaheadSize();
    chain = DeterministicKeyChain.fromProtobuf(keys, null).get(0);
    assertEquals(EXPECTED_SERIALIZATION, protoToString(chain.serializeToProtobuf()));
    assertEquals(key1, chain.findKeyFromPubHash(key1.getPubKeyHash()));
    assertEquals(key2, chain.findKeyFromPubHash(key2.getPubKeyHash()));
    assertEquals(key3, chain.findKeyFromPubHash(key3.getPubKeyHash()));
    assertEquals(key4, chain.getKey(KeyChain.KeyPurpose.CHANGE));
    key1.sign(Sha256Hash.ZERO_HASH);
    key2.sign(Sha256Hash.ZERO_HASH);
    key3.sign(Sha256Hash.ZERO_HASH);
    key4.sign(Sha256Hash.ZERO_HASH);
    assertEquals(oldLookaheadSize, chain.getLookaheadSize());
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:37,代码来源:DeterministicKeyChainTest.java


示例19: checkEncryptedKeyChain

import org.bitcoinj.wallet.KeyChain; //导入依赖的package包/类
private void checkEncryptedKeyChain(DeterministicKeyChain encChain, DeterministicKey key1) {
    // Check we can look keys up and extend the chain without the AES key being provided.
    DeterministicKey encKey1 = encChain.findKeyFromPubKey(key1.getPubKey());
    DeterministicKey encKey2 = encChain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    assertFalse(key1.isEncrypted());
    assertTrue(encKey1.isEncrypted());
    assertEquals(encKey1.getPubKeyPoint(), key1.getPubKeyPoint());
    final KeyParameter aesKey = checkNotNull(encChain.getKeyCrypter()).deriveKey("open secret");
    encKey1.sign(Sha256Hash.ZERO_HASH, aesKey);
    encKey2.sign(Sha256Hash.ZERO_HASH, aesKey);
    assertTrue(encChain.checkAESKey(aesKey));
    assertFalse(encChain.checkPassword("access denied"));
    assertTrue(encChain.checkPassword("open secret"));
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:15,代码来源:DeterministicKeyChainTest.java


示例20: encryption

import org.bitcoinj.wallet.KeyChain; //导入依赖的package包/类
@Test
public void encryption() throws UnreadableWalletException {
    DeterministicKey key1 = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    DeterministicKeyChain encChain = chain.toEncrypted("open secret");
    DeterministicKey encKey1 = encChain.findKeyFromPubKey(key1.getPubKey());
    checkEncryptedKeyChain(encChain, key1);

    // Round-trip to ensure de/serialization works and that we can store two chains and they both deserialize.
    List<Protos.Key> serialized = encChain.serializeToProtobuf();
    List<Protos.Key> doubled = Lists.newArrayListWithExpectedSize(serialized.size() * 2);
    doubled.addAll(serialized);
    doubled.addAll(serialized);
    final List<DeterministicKeyChain> chains = DeterministicKeyChain.fromProtobuf(doubled, encChain.getKeyCrypter());
    assertEquals(2, chains.size());
    encChain = chains.get(0);
    checkEncryptedKeyChain(encChain, chain.findKeyFromPubKey(key1.getPubKey()));
    encChain = chains.get(1);
    checkEncryptedKeyChain(encChain, chain.findKeyFromPubKey(key1.getPubKey()));

    DeterministicKey encKey2 = encChain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    // Decrypt and check the keys match.
    DeterministicKeyChain decChain = encChain.toDecrypted("open secret");
    DeterministicKey decKey1 = decChain.findKeyFromPubHash(encKey1.getPubKeyHash());
    DeterministicKey decKey2 = decChain.findKeyFromPubHash(encKey2.getPubKeyHash());
    assertEquals(decKey1.getPubKeyPoint(), encKey1.getPubKeyPoint());
    assertEquals(decKey2.getPubKeyPoint(), encKey2.getPubKeyPoint());
    assertFalse(decKey1.isEncrypted());
    assertFalse(decKey2.isEncrypted());
    assertNotEquals(encKey1.getParent(), decKey1.getParent());   // parts of a different hierarchy
    // Check we can once again derive keys from the decrypted chain.
    decChain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS).sign(Sha256Hash.ZERO_HASH);
    decChain.getKey(KeyChain.KeyPurpose.CHANGE).sign(Sha256Hash.ZERO_HASH);
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:34,代码来源:DeterministicKeyChainTest.java



注:本文中的org.bitcoinj.wallet.KeyChain类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java XSSimpleType类代码示例发布时间:2022-05-22
下一篇:
Java ContactInfo类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap