当前位置: 首页>>代码示例>>Java>>正文


Java PrivateKey类代码示例

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


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

示例1: reconstruct

import org.hyperledger.common.PrivateKey; //导入依赖的package包/类
/**
 * Reconstruct a secret from a collection of shares. Provided they are suffcient.
 *
 * @param shares an array of secret shares
 * @return secret if successfully recreated. The algorithm can not check for success if the shares ver not created with verbose serialization.
 * @throws HyperLedgerException
 */
public static PrivateKey reconstruct(String[] shares) throws HyperLedgerException {
    SecretShare ss[] = new SecretShare[shares.length];

    boolean comp = true;
    for (int i = 0; i < shares.length; ++i) {
        byte[] raw = ByteUtils.fromBase58WithChecksum(shares[i]);
        byte[] prefix = Arrays.copyOfRange(raw, 0, 2);
        boolean verbose = Arrays.areEqual(prefix, compressed) || !Arrays.areEqual(prefix, legacy);
        if (!verbose && !Arrays.areEqual(prefix, compressedShort) && !Arrays.areEqual(prefix, legacyShort)) {
            throw new HyperLedgerException("Not a key share");
        }
        ss[i] = new SecretShare();
        ss[i].shareNumber = raw[2] & 0xff;
        ss[i].share = new BigInteger(1, Arrays.copyOfRange(raw, verbose ? 6 : 3, 40));
        comp = raw[1] == compressed[1];
    }
    return new PrivateKey(ss256.reconstruct(ss), comp);
}
 
开发者ID:DigitalAssetCom,项目名称:-deprecated-hlp-candidate,代码行数:26,代码来源:ShamirsSecretShares.java

示例2: test

import org.hyperledger.common.PrivateKey; //导入依赖的package包/类
@Test
public void test() throws HyperLedgerException {

    byte[] offset = new byte[32];
    for (int j = 0; j < 10; ++j) {
        PrivateKey key = PrivateKey.createNew();
        for (int i = 0; i < 10; ++i) {
            random.nextBytes(offset);
            BigInteger o = new BigInteger(offset);
            PrivateKey ok = key.offsetKey(o);
            PublicKey pk = key.getPublic().offsetKey(o);
            assertEquals(ok.getPublic(), pk);
            BigInteger no = o.negate();
            assertEquals(key, ok.offsetKey(no));
        }
    }
}
 
开发者ID:DigitalAssetCom,项目名称:-deprecated-hlp-candidate,代码行数:18,代码来源:HomomorphicTest.java

示例3: testGenerator

import org.hyperledger.common.PrivateKey; //导入依赖的package包/类
@Test
public void testGenerator() throws HyperLedgerException {
    MasterPrivateKey ekprivate = MasterPrivateKey.createNew();
    MasterPublicKey ekpublic = ekprivate.getMasterPublic();

    for (int i = 0; i < 20; ++i) {
        PrivateKey fullControl = ekprivate.getKey(i);
        PublicKey readOnly = ekpublic.getKey(i);

        assertEquals(fullControl.getPublic(), readOnly);
        assertTrue(fullControl.getAddress().equals(readOnly.getAddress()));

        byte[] toSign = new byte[100];
        random.nextBytes(toSign);
        byte[] signature = fullControl.sign(toSign);

        assertTrue(readOnly.verify(toSign, signature));
    }
}
 
开发者ID:DigitalAssetCom,项目名称:-deprecated-hlp-candidate,代码行数:20,代码来源:ExtendedKeyTest.java

示例4: testJSON

import org.hyperledger.common.PrivateKey; //导入依赖的package包/类
@Test
public void testJSON() throws HyperLedgerException, IOException, JSONException {
    JSONArray tests = readArray(TESTS);
    for (int i = 0; i < tests.length(); ++i) {
        JSONObject test = tests.getJSONObject(i);
        if (test.getString("type").equals("WIF")) {
            PrivateKey key = PrivateKey.parseWIF(test.getString("key"));
            int m = test.getInt("M");
            boolean verbose = test.getBoolean("verbose");
            JSONArray shares = test.getJSONArray("shares");
            for (int j = 0; j < shares.length(); ++j) {
                assertTrue(shares.getString(j).equals(ShamirsSecretShares.getShare(key, j, m, verbose)));
            }
        }
    }
}
 
开发者ID:DigitalAssetCom,项目名称:-deprecated-hlp-candidate,代码行数:17,代码来源:ShamirsSecretSharesTest.java

示例5: setup

import org.hyperledger.common.PrivateKey; //导入依赖的package包/类
@Override
public void setup() throws Exception {
    PrivateKey key = PrivateKey.parseWIF("Kxj5wXRXPxVZScsHkK6Dwo2k7enphcW9wWidvZ93wTALHDXjDo2U");
    KeyListChain keyChain = new KeyListChain(key);
    BaseAccount account = new BaseAccount(keyChain);
    api.mine(keyChain.getNextReceiverAddress());
    BID topBlockId = api.getBlockIds(null, 1).idList.get(0);
    APIBlock topBlock = api.getBlock(topBlockId);
    account.sync(api);

    Transaction tx = topBlock.getTransaction(0);

    txs = new ArrayList<>(getRounds());
    for (int j = 0; j < getRounds(); j++) {
        System.out.println("Preparing round " + j);
        ArrayList<Transaction> txsForOneRound = new ArrayList<>(getCount());
        txs.add(txsForOneRound);
        for (int i = 0; i < getCount(); i++) {

            TransactionFactory tf = new BaseTransactionFactory(account);
            tx = tf.propose(key.getAddress(), 5000000000L - BaseTransactionFactory.MINIMUM_FEE).sign(keyChain);
            txsForOneRound.add(tx);
        }
    }
}
 
开发者ID:DigitalAssetCom,项目名称:-deprecated-hlp-candidate,代码行数:26,代码来源:SendTransactionThroughputMeasure.java

示例6: BlockSignatureConfig

import org.hyperledger.common.PrivateKey; //导入依赖的package包/类
public BlockSignatureConfig(boolean enabled, String minerPrivateKeyWIF, int requiredSignatureCount, List<String> publicKeyStrings) throws HyperLedgerException {
    this.enabled = enabled;
    if (enabled) {
        publicKeys = new ArrayList<>(publicKeyStrings.size());
        minerPrivateKey = PrivateKey.parseWIF(minerPrivateKeyWIF);
        PublicKey minerPublicKey = minerPrivateKey.getPublic();
        this.requiredSignatureCount = requiredSignatureCount;
        int counter = 0;
        for (String s : publicKeyStrings) {
            PublicKey publicKey = new PublicKey(ByteUtils.fromHex(s), true);
            publicKeys.add(publicKey);
            if (minerPublicKey.equals(publicKey)) {
                privateKeyIndex = counter;
            }
            counter++;
        }
    }
}
 
开发者ID:DigitalAssetCom,项目名称:-deprecated-hlp-candidate,代码行数:19,代码来源:BlockSignatureConfig.java

示例7: wifTest

import org.hyperledger.common.PrivateKey; //导入依赖的package包/类
@Test
public void wifTest() throws IOException, JSONException, HyperLedgerException {
    JSONArray testData = readObjectArray(WIF);
    for (int i = 0; i < testData.length(); ++i) {
        JSONArray test = testData.getJSONArray(i);
        PrivateKey kp = PrivateKey.parseWIF(test.getString(1));
        assertTrue(test.getString(0).equals(kp.getAddress().toString()));
        String serialized = PrivateKey.serializeWIF(kp);
        assertTrue(test.getString(1).equals(serialized));
    }
}
 
开发者ID:DigitalAssetCom,项目名称:-deprecated-hlp-candidate,代码行数:12,代码来源:WIFTest.java

示例8: rfc6979

import org.hyperledger.common.PrivateKey; //导入依赖的package包/类
@Test
@Ignore
public void rfc6979() throws IOException, JSONException, HyperLedgerException {
    JSONArray tests = readArray(TESTS);
    for (int i = 0; i < tests.length(); ++i) {
        JSONObject test = tests.getJSONObject(i);
        PrivateKey key = PrivateKey.parseWIF(test.getString("key"));
        byte[] message = test.getString("message").getBytes();
        byte[] expectedSignature = ByteUtils.fromHex(test.getString("expectedSignature"));
        byte[] signature = key.sign(message);
        assertTrue(Arrays.equals(expectedSignature, signature));
    }
}
 
开发者ID:DigitalAssetCom,项目名称:-deprecated-hlp-candidate,代码行数:14,代码来源:RFC6979Test.java

示例9: testECDSASpeed

import org.hyperledger.common.PrivateKey; //导入依赖的package包/类
@Test
public void testECDSASpeed() throws HyperLedgerException {
    PrivateKey key = PrivateKey.createNew(true);
    byte[] data = new byte[32];
    random.nextBytes(data);
    byte[] signature = key.sign(data);
    long cpu = -mxb.getCurrentThreadUserTime();
    for (int i = 0; i < 100; ++i) {
        assertTrue(key.getPublic().verify(data, signature));
    }
    cpu += mxb.getCurrentThreadUserTime();
    double speed = 100.0 / (cpu / 10.0e9);
    System.out.println("ECDSA validation speed : " + speed + " signatures/second");
    assertTrue(speed > 100.0);
}
 
开发者ID:DigitalAssetCom,项目名称:-deprecated-hlp-candidate,代码行数:16,代码来源:ExtendedKeyTest.java

示例10: testAddressSerialization

import org.hyperledger.common.PrivateKey; //导入依赖的package包/类
@Test
public void testAddressSerialization() throws IOException, ClassNotFoundException {
    Address address = PrivateKey.createNew(true).getAddress();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(baos);
    out.writeObject(address);
    out.flush();

    byte[] bytes = baos.toByteArray();
    Address address2 = (Address) new ObjectInputStream(new ByteArrayInputStream(bytes)).readObject();

    assertEquals(address, address2);
}
 
开发者ID:DigitalAssetCom,项目名称:-deprecated-hlp-candidate,代码行数:15,代码来源:AddressSerializationTest.java

示例11: HyperLedgerRule

import org.hyperledger.common.PrivateKey; //导入依赖的package包/类
public HyperLedgerRule(BCSAPI bcsapi, Address minerAddress, BitcoinBlockStore blockStore, int coinbaseMaturity) throws HyperLedgerException {
    this.bcsapi = bcsapi;
    this.blockStore = blockStore;
    this.coinbaseMaturity = coinbaseMaturity;
    this.minerAddress = minerAddress;
    // the below private key is the origin of the miner address in hte test-config.json, do not change them
    PrivateKey privateKey = PrivateKey.parseWIF("Kxj5wXRXPxVZScsHkK6Dwo2k7enphcW9wWidvZ93wTALHDXjDo2U");
    keyChain = new KeyListChain(privateKey);
    minerAccount = new BaseAccount(keyChain);
}
 
开发者ID:DigitalAssetCom,项目名称:-deprecated-hlp-candidate,代码行数:11,代码来源:HyperLedgerRule.java

示例12: build

import org.hyperledger.common.PrivateKey; //导入依赖的package包/类
public Transaction build() {
    for (PrivateKey key : endorserKeys) {
        Endorser endorser = Endorser.create(Hash.of(outputs.get(0)).toByteArray(), key);
        endorsers.add(endorser);
    }
    return new Transaction(inputs, outputs, endorsers);
}
 
开发者ID:hyperledger-archives,项目名称:fabric-api-archive,代码行数:8,代码来源:TransactionBuilder.java

示例13: randomTx

import org.hyperledger.common.PrivateKey; //导入依赖的package包/类
public static Transaction randomTx() {
    return new TransactionBuilder()
            .input(new TID(randomBytes(32)))
            .output(randomBytes(100))
            .endorse(PrivateKey.createNew(crypto))
            .build();
}
 
开发者ID:hyperledger-archives,项目名称:fabric-api-archive,代码行数:8,代码来源:TransactionTest.java

示例14: signatureValidationSucceeds

import org.hyperledger.common.PrivateKey; //导入依赖的package包/类
@Test
public void signatureValidationSucceeds() {
    PrivateKey key = PrivateKey.createNew(crypto);

    Transaction t = new TransactionBuilder()
            .output(randomBytes(100))
            .endorse(key)
            .build();

    assertTrue(t.verify(t.getEndorsers().get(0), key.getPublic()));
}
 
开发者ID:hyperledger-archives,项目名称:fabric-api-archive,代码行数:12,代码来源:TransactionTest.java

示例15: signatureValidationFails

import org.hyperledger.common.PrivateKey; //导入依赖的package包/类
@Test
public void signatureValidationFails() {
    PrivateKey key1 = PrivateKey.createNew(crypto);
    PrivateKey key2 = PrivateKey.createNew(crypto);

    Transaction t = new TransactionBuilder()
            .output(randomBytes(100))
            .endorse(key1)
            .build();

    assertFalse(t.verify(t.getEndorsers().get(0), key2.getPublic()));
}
 
开发者ID:hyperledger-archives,项目名称:fabric-api-archive,代码行数:13,代码来源:TransactionTest.java


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