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


Java ECKey.fromPublicOnly方法代码示例

本文整理汇总了Java中org.bitcoinj.core.ECKey.fromPublicOnly方法的典型用法代码示例。如果您正苦于以下问题:Java ECKey.fromPublicOnly方法的具体用法?Java ECKey.fromPublicOnly怎么用?Java ECKey.fromPublicOnly使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bitcoinj.core.ECKey的用法示例。


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

示例1: Address

import org.bitcoinj.core.ECKey; //导入方法依赖的package包/类
/**
     * Constructor an HD address.
     *
     * @param NetworkParameters params
     * @param DeterministicKey cKey deterministic key for this address
     * @param int child index of this address in its chain
     *
     */
    public Address(NetworkParameters params, DeterministicKey cKey, int child) {

        this.params = params;
        childNum = child;

        DeterministicKey dk = HDKeyDerivation.deriveChildKey(cKey, new ChildNumber(childNum, false));
        // compressed WIF private key format
        if(dk.hasPrivKey()) {
//            byte[] prepended0Byte = ArrayUtils.addAll(new byte[1], dk.getPrivKeyBytes());
        	byte[] getPrivKeyBytes = dk.getPrivKeyBytes();
        	byte[] prepended0Byte = new byte[1 + getPrivKeyBytes.length];
        	prepended0Byte[0] = 0;
            System.arraycopy(getPrivKeyBytes, 0, prepended0Byte, 1, getPrivKeyBytes.length);
            
            ecKey = ECKey.fromPrivate(new BigInteger(prepended0Byte), true);
        }
        else {
            ecKey = ECKey.fromPublicOnly(dk.getPubKey());
        }

        long now = Utils.now().getTime() / 1000;    // use Unix time (in seconds)
        ecKey.setCreationTimeSeconds(now);

        pubKey = ecKey.getPubKey();
        pubKeyHash = ecKey.getPubKeyHash();

        strPath = dk.getPathAsString();
    }
 
开发者ID:matthiaszimmermann,项目名称:bitcoin-paper-wallet,代码行数:37,代码来源:Address.java

示例2: deserializeFromProtobuf

import org.bitcoinj.core.ECKey; //导入方法依赖的package包/类
private void deserializeFromProtobuf(List<Protos.Key> keys) throws UnreadableWalletException {
    lock.lock();
    try {
        checkState(hashToKeys.isEmpty(), "Tried to deserialize into a non-empty chain");
        for (Protos.Key key : keys) {
            if (key.getType() != Protos.Key.Type.ORIGINAL && key.getType() != Protos.Key.Type.ENCRYPTED_SCRYPT_AES)
                continue;
            boolean encrypted = key.getType() == Protos.Key.Type.ENCRYPTED_SCRYPT_AES;
            byte[] priv = key.hasSecretBytes() ? key.getSecretBytes().toByteArray() : null;
            if (!key.hasPublicKey())
                throw new UnreadableWalletException("Public key missing");
            byte[] pub = key.getPublicKey().toByteArray();
            ECKey ecKey;
            if (encrypted) {
                checkState(keyCrypter != null, "This wallet is encrypted but encrypt() was not called prior to deserialization");
                if (!key.hasEncryptedData())
                    throw new UnreadableWalletException("Encrypted private key data missing");
                Protos.EncryptedData proto = key.getEncryptedData();
                EncryptedData e = new EncryptedData(proto.getInitialisationVector().toByteArray(),
                        proto.getEncryptedPrivateKey().toByteArray());
                ecKey = ECKey.fromEncrypted(e, keyCrypter, pub);
            } else {
                if (priv != null)
                    ecKey = ECKey.fromPrivateAndPrecalculatedPublic(priv, pub);
                else
                    ecKey = ECKey.fromPublicOnly(pub);
            }
            ecKey.setCreationTimeSeconds(key.getCreationTimestamp() / 1000);
            importKeyLocked(ecKey);
        }
    } finally {
        lock.unlock();
    }
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:35,代码来源:BasicKeyChain.java

示例3: isSignatureCorrect

import org.bitcoinj.core.ECKey; //导入方法依赖的package包/类
private boolean isSignatureCorrect(ECDSASignature signature, byte[] challengeString) {
	Sha256Hash hash = Sha256Hash.wrap(Sha256Hash.hash(challengeString));
	ECKey verificationKey = ECKey.fromPublicOnly(partnerProof.getScriptPair().getPubKey());
	return verificationKey.verify(hash, signature);
}
 
开发者ID:kit-tm,项目名称:bitnym,代码行数:6,代码来源:ChallengeResponseVerifier.java


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