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

Java EncryptedData类代码示例

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

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



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

示例1: serializeEncryptableItem

import org.bitcoinj.crypto.EncryptedData; //导入依赖的package包/类
public static Protos.Key.Builder serializeEncryptableItem(EncryptableItem item) {
    Protos.Key.Builder proto = Protos.Key.newBuilder();
    if (item.isEncrypted() && item.getEncryptedData() != null) {
        // The encrypted data can be missing for an "encrypted" key in the case of a deterministic wallet for
        // which the leaf keys chain to an encrypted parent and rederive their private keys on the fly. In that
        // case the caller in DeterministicKeyChain will take care of setting the type.
        EncryptedData data = item.getEncryptedData();
        proto.getEncryptedDataBuilder()
                .setEncryptedPrivateKey(ByteString.copyFrom(data.encryptedBytes))
                .setInitialisationVector(ByteString.copyFrom(data.initialisationVector));
        // We don't allow mixing of encryption types at the moment.
        checkState(item.getEncryptionType() == org.bitcoinj.wallet.Protos.Wallet.EncryptionType.ENCRYPTED_SCRYPT_AES, "We don't allow mixing of encryption types at the moment");
        proto.setType(Protos.Key.Type.ENCRYPTED_SCRYPT_AES);
    } else {
        final byte[] secret = item.getSecretBytes();
        // The secret might be missing in the case of a watching wallet, or a key for which the private key
        // is expected to be rederived on the fly from its parent.
        if (secret != null)
            proto.setSecretBytes(ByteString.copyFrom(secret));
        proto.setType(Protos.Key.Type.ORIGINAL);
    }
    return proto;
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:24,代码来源:KeyUtils.java


示例2: testEncryptedCreate

import org.bitcoinj.crypto.EncryptedData; //导入依赖的package包/类
@Test
public void testEncryptedCreate() throws Exception {
    ECKey unencryptedKey = new ECKey();
    byte[] originalPrivateKeyBytes = checkNotNull(unencryptedKey.getPrivKeyBytes());
    log.info("Original private key = " + Utils.HEX.encode(originalPrivateKeyBytes));
    EncryptedData encryptedPrivateKey = keyCrypter.encrypt(unencryptedKey.getPrivKeyBytes(), keyCrypter.deriveKey(PASSWORD1));
    ECKey encryptedKey = ECKey.fromEncrypted(encryptedPrivateKey, keyCrypter, unencryptedKey.getPubKey());
    assertTrue(encryptedKey.isEncrypted());
    assertNull(encryptedKey.getSecretBytes());
    ECKey rebornUnencryptedKey = encryptedKey.decrypt(keyCrypter.deriveKey(PASSWORD1));
    assertTrue(!rebornUnencryptedKey.isEncrypted());
    assertArrayEquals(originalPrivateKeyBytes, rebornUnencryptedKey.getPrivKeyBytes());
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:14,代码来源:ECKeyTest.java


示例3: load

import org.bitcoinj.crypto.EncryptedData; //导入依赖的package包/类
public void load(File file, String password) throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    KeyStore keystore = mapper.readValue(new FileInputStream(file), KeyStore.class);

    Protos.ScryptParameters.Builder scryptParametersBuilder
            = Protos.ScryptParameters.newBuilder()
            .setSalt(ByteString.copyFrom(base64Url().decode(keystore.getScrypt().getSalt())))
            .setN(keystore.getScrypt().getN())
            .setR(keystore.getScrypt().getR())
            .setP(keystore.getScrypt().getP());

    KeyCrypterScrypt crypterScrypt = new KeyCrypterScrypt(scryptParametersBuilder.build());
    KeyParameter aesKey = crypterScrypt.deriveKey(password);

    for (KeyEntry entry : keystore.getKeys()) {
        byte[] key = base64Url().decode(entry.getPk());
        byte[] iv = base64Url().decode(entry.getIv());

        EncryptedData data = new EncryptedData(iv, key);
        ECKey ecKey = ECKey.fromPrivate(crypterScrypt.decrypt(data, aesKey));

        KeyContentValues kcv = new KeyContentValues();
        kcv.putNickname(entry.getAlias());
        kcv.putAddress(ecKey.toAddress(MainNetParams.get()).toString());
        kcv.putPriv(ecKey.getPrivKeyBytes());
        kcv.putPub(ecKey.getPubKey());

        KeySelection ks = new KeySelection();
        ks.nickname(entry.getAlias());

        if(kcv.update(mContext.getContentResolver(), ks) != 1) {
            kcv.insert(mContext.getContentResolver());
        };

    }
}
 
开发者ID:skubit,项目名称:bitid-android,代码行数:37,代码来源:BitKeystoreImporter.java


示例4: store

import org.bitcoinj.crypto.EncryptedData; //导入依赖的package包/类
public void store(OutputStream os, String password)
        throws Exception {
    final Cursor c = mContext.getContentResolver()
            .query(KeyColumns.CONTENT_URI, null, null, null, null);

    KeyCursor kc = new KeyCursor(c);
    kc.moveToFirst();

    KeyCrypterScrypt crypterScrypt = new KeyCrypterScrypt(512);
    KeyParameter aesKey = crypterScrypt.deriveKey(password);

    Protos.ScryptParameters params = crypterScrypt.getScryptParameters();
    ScryptHeader scryptHeader = new ScryptHeader();
    scryptHeader.setN(params.getN());
    scryptHeader.setR(params.getR());
    scryptHeader.setP(params.getP());
    scryptHeader.setSalt(BaseEncoding.base64Url().encode(params.getSalt().toByteArray()));

    KeyStore keyStore = new KeyStore();
    keyStore.setScrypt(scryptHeader);

    for (int i = 0; i < kc.getCount(); i++) {
        kc.moveToPosition(i);

        EncryptedData data = crypterScrypt.encrypt(kc.getPriv(), aesKey);
        String ecKey64 = BaseEncoding.base64Url().encode(data.encryptedBytes);

        KeyEntry entry = new KeyEntry();
        entry.setAlias(kc.getNickname());
        entry.setKty("EC");
        entry.setCrv("P-256");
        entry.setPk(ecKey64);
        entry.setIv(BaseEncoding.base64Url().encode(data.initialisationVector));
        keyStore.addKey(entry);
    }

    ObjectMapper mapper = new ObjectMapper();
    mapper.writeValue(os, keyStore);
    os.close();

}
 
开发者ID:skubit,项目名称:bitid-android,代码行数:42,代码来源:BitKeystoreExporter.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java MediaDescription类代码示例发布时间:2022-05-22
下一篇:
Java AndroidDnsServer类代码示例发布时间: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