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


Java ECKey类代码示例

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


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

示例1: decodePrivateKey

import org.bitcoinj.core.ECKey; //导入依赖的package包/类
public final void decodePrivateKey(final BIP38PrivateKey encryptedKey, final String passphrase) {
    backgroundHandler.post(new Runnable() {
        @Override
        public void run() {
            try {
                final ECKey decryptedKey = encryptedKey.decrypt(passphrase); // takes time

                callbackHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        onSuccess(decryptedKey);
                    }
                });
            } catch (final BIP38PrivateKey.BadPassphraseException x) {
                callbackHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        onBadPassphrase();
                    }
                });
            }
        }
    });
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:25,代码来源:DecodePrivateKeyTask.java

示例2: getAddressesKeys

import org.bitcoinj.core.ECKey; //导入依赖的package包/类
/**
 *
 * @return
 */
@Override
public Map<String, String> getAddressesKeys() {
    Map<String, String> addrKeysMap = new HashMap<>();

    List<ECKey> allWalletKeys = _coin.getWalletManager().wallet().getImportedKeys();
    allWalletKeys.addAll(_coin.getWalletManager().wallet().getIssuedReceiveKeys());

    for (ECKey k : allWalletKeys) {
        Address addr = k.toAddress(Constants.NETWORK_PARAMETERS);
        String hash = WalletUtils.formatAddress(addr, Constants.ADDRESS_FORMAT_GROUP_SIZE, Constants.ADDRESS_FORMAT_LINE_SIZE).toString();

        addrKeysMap.put(hash, k.getPrivateKeyAsHex());
    }

    return addrKeysMap;
}
 
开发者ID:ehanoc,项目名称:xwallet,代码行数:21,代码来源:BitcoinManager.java

示例3: CLTVScriptPair

import org.bitcoinj.core.ECKey; //导入依赖的package包/类
CLTVScriptPair(ECKey newPsynymKey, long expireDate) {
	ScriptBuilder sb = new ScriptBuilder();
	
	//the part that freezes the tx output, special 5 byte number
	sb.data(encodeExpireDate(expireDate));
	//sb.smallNum(num)
	sb.op(ScriptOpCodes.OP_CHECKLOCKTIMEVERIFY);
	sb.op(ScriptOpCodes.OP_DROP);
	
	//standard p2pkh part
	sb.op(ScriptOpCodes.OP_DUP);
	sb.op(ScriptOpCodes.OP_HASH160);
	sb.data(newPsynymKey.getPubKeyHash());
	sb.op(ScriptOpCodes.OP_EQUALVERIFY);
	sb.op(ScriptOpCodes.OP_CHECKSIG);
	
	this.redeemScript = sb.build();
	System.out.println("cltvscripiar yielded a locktime of " + new Date(getLockTime()*1000));
	assert(expireDate == getLockTime());

	
	this.pubKeyScript = ScriptBuilder.createP2SHOutputScript(redeemScript);
	this.pubkeyHash = newPsynymKey.getPubKeyHash();
	this.pubkey = newPsynymKey.getPubKey();
}
 
开发者ID:kit-tm,项目名称:bitnym,代码行数:26,代码来源:CLTVScriptPair.java

示例4: findOldestKeyAfter

import org.bitcoinj.core.ECKey; //导入依赖的package包/类
/** Returns the first ECKey created after the given UNIX time, or null if there is none. */
@Nullable
public ECKey findOldestKeyAfter(long timeSecs) {
    lock.lock();
    try {
        ECKey oldest = null;
        for (ECKey key : hashToKeys.values()) {
            final long keyTime = key.getCreationTimeSeconds();
            if (keyTime > timeSecs) {
                if (oldest == null || oldest.getCreationTimeSeconds() > keyTime)
                    oldest = key;
            }
        }
        return oldest;
    } finally {
        lock.unlock();
    }
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:19,代码来源:BasicKeyChain.java

示例5: decodeFromBitcoin

import org.bitcoinj.core.ECKey; //导入依赖的package包/类
/**
 * Returns a decoded signature.
 *
 * @param requireCanonicalEncoding if the encoding of the signature must
 * be canonical.
 * @param requireCanonicalSValue if the S-value must be canonical (below half
 * the order of the curve).
 * @throws RuntimeException if the signature is invalid or unparseable in some way.
 */
public static TransactionSignature decodeFromBitcoin(byte[] bytes,
                                                     boolean requireCanonicalEncoding,
                                                     boolean requireCanonicalSValue) throws VerificationException {
    // Bitcoin encoding is DER signature + sighash byte.
    if (requireCanonicalEncoding && !isEncodingCanonical(bytes))
        throw new VerificationException("Signature encoding is not canonical.");
    ECKey.ECDSASignature sig;
    try {
        sig = ECKey.ECDSASignature.decodeFromDER(bytes);
    } catch (IllegalArgumentException e) {
        throw new VerificationException("Could not decode DER", e);
    }
    if (requireCanonicalSValue && !sig.isCanonical())
        throw new VerificationException("S-value is not canonical.");

    // In Bitcoin, any value of the final byte is valid, but not necessarily canonical. See javadocs for
    // isEncodingCanonical to learn more about this. So we must store the exact byte found.
    return new TransactionSignature(sig.r, sig.s, bytes[bytes.length - 1]);
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:29,代码来源:TransactionSignature.java

示例6: estimateBytesForSigning

import org.bitcoinj.core.ECKey; //导入依赖的package包/类
private int estimateBytesForSigning(CoinSelection selection) {
    int size = 0;
    for (TransactionOutput output : selection.gathered) {
        try {
            Script script = output.getScriptPubKey();
            ECKey key = null;
            Script redeemScript = null;
            if (script.isSentToAddress()) {
                key = findKeyFromPubHash(script.getPubKeyHash());
                checkNotNull(key, "Coin selection includes unspendable outputs");
            } else if (script.isPayToScriptHash()) {
                redeemScript = findRedeemDataFromScriptHash(script.getPubKeyHash()).redeemScript;
                checkNotNull(redeemScript, "Coin selection includes unspendable outputs");
            }
            size += script.getNumberOfBytesRequiredToSpend(key, redeemScript);
        } catch (ScriptException e) {
            // If this happens it means an output script in a wallet tx could not be understood. That should never
            // happen, if it does it means the wallet has got into an inconsistent state.
            throw new IllegalStateException(e);
        }
    }
    return size;
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:24,代码来源:Wallet.java

示例7: isInputStandard

import org.bitcoinj.core.ECKey; //导入依赖的package包/类
/** Checks if the given input passes some of the AreInputsStandard checks. Not complete. */
public static RuleViolation isInputStandard(TransactionInput input) {
    for (ScriptChunk chunk : input.getScriptSig().getChunks()) {
        if (chunk.data != null && !chunk.isShortestPossiblePushData())
            return RuleViolation.SHORTEST_POSSIBLE_PUSHDATA;
        if (chunk.isPushData()) {
            ECDSASignature signature;
            try {
                signature = ECKey.ECDSASignature.decodeFromDER(chunk.data);
            } catch (IllegalArgumentException x) {
                // Doesn't look like a signature.
                signature = null;
            }
            if (signature != null) {
                if (!TransactionSignature.isEncodingCanonical(chunk.data))
                    return RuleViolation.SIGNATURE_CANONICAL_ENCODING;
                if (!signature.isCanonical())
                    return RuleViolation.SIGNATURE_CANONICAL_ENCODING;
            }
        }
    }
    return RuleViolation.NONE;
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:24,代码来源:DefaultRiskAnalysis.java

示例8: getKeys

import org.bitcoinj.core.ECKey; //导入依赖的package包/类
List<ECKey> getKeys(boolean includeLookahead, boolean includeParents) {
    List<ECKey> keys = basicKeyChain.getKeys();
    if (!includeLookahead) {
        int treeSize = internalParentKey.getPath().size();
        List<ECKey> issuedKeys = new LinkedList<>();
        for (ECKey key : keys) {
            DeterministicKey detkey = (DeterministicKey) key;
            DeterministicKey parent = detkey.getParent();
            if (!includeParents && parent == null) continue;
            if (!includeParents && detkey.getPath().size() <= treeSize) continue;
            if (internalParentKey.equals(parent) && detkey.getChildNumber().i() >= issuedInternalKeys) continue;
            if (externalParentKey.equals(parent) && detkey.getChildNumber().i() >= issuedExternalKeys) continue;
            issuedKeys.add(detkey);
        }
        return issuedKeys;
    }
    return keys;
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:19,代码来源:DeterministicKeyChain.java

示例9: toDecrypted

import org.bitcoinj.core.ECKey; //导入依赖的package包/类
@Override
public BasicKeyChain toDecrypted(KeyParameter aesKey) {
    lock.lock();
    try {
        checkState(keyCrypter != null, "Wallet is already decrypted");
        // Do an up-front check.
        if (numKeys() > 0 && !checkAESKey(aesKey))
            throw new KeyCrypterException("Password/key was incorrect.");
        BasicKeyChain decrypted = new BasicKeyChain();
        for (ECKey key : hashToKeys.values()) {
            decrypted.importKeyLocked(key.decrypt(aesKey));
        }
        return decrypted;
    } finally {
        lock.unlock();
    }
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:18,代码来源:BasicKeyChain.java

示例10: findKeysBefore

import org.bitcoinj.core.ECKey; //导入依赖的package包/类
/** Returns a list of all ECKeys created after the given UNIX time. */
public List<ECKey> findKeysBefore(long timeSecs) {
    lock.lock();
    try {
        List<ECKey> results = Lists.newLinkedList();
        for (ECKey key : hashToKeys.values()) {
            final long keyTime = key.getCreationTimeSeconds();
            if (keyTime < timeSecs) {
                results.add(key);
            }
        }
        return results;
    } finally {
        lock.unlock();
    }
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:17,代码来源:BasicKeyChain.java

示例11: toEncrypted

import org.bitcoinj.core.ECKey; //导入依赖的package包/类
/**
 * Encrypt the wallet using the KeyCrypter and the AES key. A good default KeyCrypter to use is
 * {@link org.bitcoinj.crypto.KeyCrypterScrypt}.
 *
 * @param keyCrypter The KeyCrypter that specifies how to encrypt/ decrypt a key
 * @param aesKey AES key to use (normally created using KeyCrypter#deriveKey and cached as it is time consuming
 *               to create from a password)
 * @throws KeyCrypterException Thrown if the wallet encryption fails. If so, the wallet state is unchanged.
 */
@Override
public BasicKeyChain toEncrypted(KeyCrypter keyCrypter, KeyParameter aesKey) {
    lock.lock();
    try {
        checkNotNull(keyCrypter);
        checkState(this.keyCrypter == null, "Key chain is already encrypted");
        BasicKeyChain encrypted = new BasicKeyChain(keyCrypter);
        for (ECKey key : hashToKeys.values()) {
            ECKey encryptedKey = key.encrypt(keyCrypter, aesKey);
            // Check that the encrypted key can be successfully decrypted.
            // This is done as it is a critical failure if the private key cannot be decrypted successfully
            // (all bitcoin controlled by that private key is lost forever).
            // For a correctly constructed keyCrypter the encryption should always be reversible so it is just
            // being as cautious as possible.
            if (!ECKey.encryptionIsReversible(key, encryptedKey, keyCrypter, aesKey))
                throw new KeyCrypterException("The key " + key.toString() + " cannot be successfully decrypted after encryption so aborting wallet encryption.");
            encrypted.importKeyLocked(encryptedKey);
        }
        return encrypted;
    } finally {
        lock.unlock();
    }
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:33,代码来源:BasicKeyChain.java

示例12: getToken

import org.bitcoinj.core.ECKey; //导入依赖的package包/类
public Optional<String> getToken() {
        final ListenableFuture<String> masterPassword = encyptionKeyProvider.getMasterPassword();
        if (!masterPassword.isDone()) {
            return Optional.empty();
        }
        final String key = encyptionKeyProvider.getImmediatePassword();
        final String s = key + " meta";
        final ECKey privKey = ECKey.fromPrivate(Sha256Hash.twiceOf(s.getBytes(Charsets.UTF_8)).getBytes());

/*
        @POST
        @Path("/token")
        @Produces(MediaType.APPLICATION_OCTET_STREAM)
        public Response createToken(@QueryParam("timestamp") Long nonce, @QueryParam("signature") String signature) {
*/

//        }
        final long timeStamp = Instant.now().toEpochMilli();
        try {
            final String url = rootPath + "auth/token";
            final HttpResponse<String> token = Unirest.post(url)
                    .queryString("timestamp", timeStamp)
                    .queryString("signature", privKey.signMessage(String.valueOf(timeStamp)))
                    .asString();
            if (token.getStatus() != 200) {
                return Optional.empty();
            }
            return Optional.of(token.getBody());
        } catch (UnirestException e) {
            LOGGER.error("exception from remote service when trying to get token", e);
            return Optional.empty();
        }

    }
 
开发者ID:MineboxOS,项目名称:minebox,代码行数:35,代码来源:RemoteTokenService.java

示例13: isValidEthereumAddress

import org.bitcoinj.core.ECKey; //导入依赖的package包/类
public boolean isValidEthereumAddress(String address) {
    try {
        org.ethereum.crypto.ECKey.fromPublicOnly(Hex.decode(address.replace("0x", "")));
        return true;
    } catch (Throwable e) {
        return false;
    }
}
 
开发者ID:modum-io,项目名称:tokenapp-backend,代码行数:9,代码来源:AddressService.java

示例14: getKeys

import org.bitcoinj.core.ECKey; //导入依赖的package包/类
public Keys getKeys() {

        ECKey key = new ECKey();
        byte[] address = key.getPubKey();
        String addressAsString = key.toAddress(getNetworkParameters()).toString();
        byte[] privateKey = key.getPrivKeyBytes();
        String addressAsStringWithPrivate = key.toStringWithPrivate(getNetworkParameters()).toString();
        return new Keys()
                .setAddress(address)
                .setAddressAsString(addressAsString)
                .setPrivateKey(privateKey)
                .setAddressAsStringWithPrivate(addressAsStringWithPrivate);
    }
 
开发者ID:modum-io,项目名称:tokenapp-backend,代码行数:14,代码来源:BitcoinKeyGenerator.java

示例15: get

import org.bitcoinj.core.ECKey; //导入依赖的package包/类
@Override
public String get() {
    synchronized (lock) {
        ECKey ecKey = ECKey.fromPrivate(startPrivateKey);
        String privateKeyToCheck = ecKey.getPrivateKeyAsWiF(Constants.NETWORK_PARAMS);
        startPrivateKey = startPrivateKey.add(BigInteger.ONE);
        keyCount = keyCount.add(BigInteger.ONE);
        logKeyRate();
        return privateKeyToCheck;
    }
}
 
开发者ID:eztam-,项目名称:bitcoin-bruteforce,代码行数:12,代码来源:InputKeySupplier.java


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