/** * Signs the given hash and returns the R and S components as BigIntegers. In the Bitcoin protocol, they are * usually encoded using ASN.1 format, so you want {@link org.bitcoinj.core.ECKey.ECDSASignature#toASN1()} * instead. However sometimes the independent components can be useful, for instance, if you're going to do * further EC maths on them. * @throws KeyCrypterException if this ECKey doesn't have a private part. */ public ECDSASignature sign(Sha256Hash input) throws KeyCrypterException { return sign(input, null); }
/** * Signs the given hash and returns the R and S components as BigIntegers. In the Bitcoin protocol, they are * usually encoded using ASN.1 format, so you want {@link org.bitcoinj.core.ECKey.ECDSASignature#toASN1()} * instead. However sometimes the independent components can be useful, for instance, if you're going to do * further EC maths on them. * @throws KeyCrypterException if this ECKey doesn't have a private part. */ public ECDSASignature sign(Sha256Hash input) throws KeyCrypterException { return sign(input, null); }
/** * Signs the given hash and returns the R and S components as BigIntegers. In the Bitcoin protocol, they are * usually encoded using ASN.1 format, so you want {@link org.bitcoinj.core.ECKey.ECDSASignature#toASN1()} * instead. However sometimes the independent components can be useful, for instance, if you're going to do * further EC maths on them. * @throws KeyCrypterException if this ECKey doesn't have a private part. */ public ECDSASignature sign(Sha256Hash input) throws KeyCrypterException { return sign(input, null); }
/** * Signs the given hash and returns the R and S components as BigIntegers. In the Bitcoin protocol, they are * usually encoded using ASN.1 format, so you want {@link org.bitcoinj.core.ECKey.ECDSASignature#toASN1()} * instead. However sometimes the independent components can be useful, for instance, if you're going to do * further EC maths on them. * @throws KeyCrypterException if this ECKey doesn't have a private part. */ public ECDSASignature sign(Sha256Hash input) throws KeyCrypterException { return sign(input, null); }
@Override public ECKey.ECDSASignature call() throws Exception { return key.sign(hash); } }));
public TransactionSignature calculateWitnessSignature(int inputIndex, ECKey key, @Nullable KeyParameter aesKey, byte[] redeemScript, Coin value, SigHash hashType, boolean anyoneCanPay) { Sha256Hash hash = hashForSignatureWitness(inputIndex, redeemScript, value, hashType, anyoneCanPay); return new TransactionSignature(key.sign(hash, aesKey), hashType, anyoneCanPay); }
public TransactionSignature calculateWitnessSignature( int inputIndex, ECKey key, byte[] redeemScript, Coin value, SigHash hashType, boolean anyoneCanPay) { Sha256Hash hash = hashForSignatureWitness(inputIndex, redeemScript, value, hashType, anyoneCanPay); return new TransactionSignature(key.sign(hash), hashType, anyoneCanPay, true); } /**
public TransactionSignature calculateWitnessSignature( int inputIndex, ECKey key, byte[] redeemScript, Coin value, SigHash hashType, boolean anyoneCanPay) { Sha256Hash hash = hashForSignatureWitness(inputIndex, redeemScript, value, hashType, anyoneCanPay); return new TransactionSignature(key.sign(hash), hashType, anyoneCanPay); }
public TransactionSignature calculateWitnessSignature(int inputIndex, ECKey key, byte[] redeemScript, Coin value, SigHash hashType, boolean anyoneCanPay) { Sha256Hash hash = hashForSignatureWitness(inputIndex, redeemScript, value, hashType, anyoneCanPay); return new TransactionSignature(key.sign(hash), hashType, anyoneCanPay); }
public static byte[] createSignature (ECKey pubkey, byte[] data) throws NoSuchProviderException, NoSuchAlgorithmException { return pubkey.sign(Sha256Hash.of(data)).encodeToDER(); }
public static MasternodeSignature signHash(Sha256Hash hash, ECKey key) { ECKey.ECDSASignature signature = key.sign(hash); return new MasternodeSignature(signature.encodeToDER()); }
public TransactionSignature calculateWitnessSignature(int inputIndex, ECKey key, @Nullable KeyParameter aesKey, Script redeemScript, Coin value, SigHash hashType, boolean anyoneCanPay) { Sha256Hash hash = hashForSignatureWitness(inputIndex, redeemScript.getProgram(), value, hashType, anyoneCanPay); return new TransactionSignature(key.sign(hash, aesKey), hashType, anyoneCanPay); }
public static String sign(ECKey key, String input) throws UnsupportedEncodingException { byte[] data = input.getBytes("UTF8"); Sha256Hash hash = Sha256Hash.of(data); ECDSASignature sig = key.sign(hash, null); byte[] bytes = sig.encodeToDER(); return bytesToHex(bytes); }
public TransactionSignature calculateWitnessSignature( int inputIndex, ECKey key, Script redeemScript, Coin value, SigHash hashType, boolean anyoneCanPay) { Sha256Hash hash = hashForSignatureWitness(inputIndex, redeemScript.getProgram(), value, hashType, anyoneCanPay); return new TransactionSignature(key.sign(hash), hashType, anyoneCanPay, true); }
public TransactionSignature calculateWitnessSignature( int inputIndex, ECKey key, Script redeemScript, Coin value, SigHash hashType, boolean anyoneCanPay) { Sha256Hash hash = hashForSignatureWitness(inputIndex, redeemScript.getProgram(), value, hashType, anyoneCanPay); return new TransactionSignature(key.sign(hash), hashType, anyoneCanPay); }
public TransactionSignature calculateWitnessSignature(int inputIndex, ECKey key, Script redeemScript, Coin value, SigHash hashType, boolean anyoneCanPay) { Sha256Hash hash = hashForSignatureWitness(inputIndex, redeemScript.getProgram(), value, hashType, anyoneCanPay); return new TransactionSignature(key.sign(hash), hashType, anyoneCanPay); }
@Override public Bytestring sign(Bytestring string) { ECKey.ECDSASignature ecdsaSignature = signingKey.sign(Sha256Hash.of(string.bytes)); return new Bytestring(ecdsaSignature.encodeToDER()); }
@Test public void testSomething() { String msg = "hello world"; Sha256Hash hash = Sha256Hash.of(msg.getBytes()); ECKey signingKey = new ECKey(); ECKey verificationKey = ECKey.fromPublicOnly(signingKey.getPubKeyPoint()); ECKey.ECDSASignature sig = signingKey.sign(hash); boolean isVerified = verificationKey.verify(hash, sig); assertTrue("msg " + msg + " can not be signed with " + Arrays.toString(sig.encodeToDER()), isVerified); }
@Test(expected = ECKey.MissingPrivateKeyException.class) public void watchingWalletWithCreationTime() throws Exception { DeterministicKey watchKey = wallet.getWatchingKey(); String serialized = watchKey.serializePubB58(PARAMS); Wallet watchingWallet = Wallet.fromWatchingKeyB58(PARAMS, serialized, 1415282801); DeterministicKey key2 = watchingWallet.freshReceiveKey(); assertEquals(myKey, key2); ECKey key = wallet.freshKey(KeyChain.KeyPurpose.CHANGE); key2 = watchingWallet.freshKey(KeyChain.KeyPurpose.CHANGE); assertEquals(key, key2); key.sign(Sha256Hash.ZERO_HASH); key2.sign(Sha256Hash.ZERO_HASH); }
@Test public void derive() throws Exception { ECKey key1 = chain.getKey(SimpleHDKeyChain.KeyPurpose.RECEIVE_FUNDS); ECKey key2 = chain.getKey(SimpleHDKeyChain.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(SimpleHDKeyChain.KeyPurpose.CHANGE); assertEquals("mqumHgVDqNzuXNrszBmi7A2UpmwaPMx4HQ", key3.toAddress(UnitTestParams.get()).toString()); key3.sign(Sha256Hash.ZERO_HASH); }