According to this function:

public boolean verify(Sha256Hash sigHash, ECDSASignature signature) {
        return ECKey.verify(sigHash.getBytes(), signature, getPubKey());

I do not understand which must be the content of the variable sighash.

Here is my function where the creation of signature happend:

public ECDSASignature scriptSig(Receiver r) {
        System.out.println("First step :\n");
                .println("CREATION OF SCRIPTSIG-----OR----- OUTPUT TRANSACTION");

        r = super.getReceiver();

        Wallet rwallet = r.getReceiverWalletList().get(0);

        BigInteger R = rwallet.getClientKey().getPrivKey();

        BigInteger S = new BigInteger(r.getReceiverWalletList().get(0).getClientKey().getPubKey()); // i
                                                                                // had
                                                                                // .getPubkeyHash()

        // constructs a signature with the given components
        ECDSASignature receiverSig = new ECDSASignature(R, S);

        return receiverSig;

and here i am trying to verify my signature:

sha256hash = new Sha256Hash(receiver.getReceiverWalletList()
            redeemerSignature = scriptSig(receiver);


if (receiver.getReceiverWalletList().get(0).getClientKey()
                        .verify(sha256hash, redeemerSignature))
                    System.out.println("The transaction finished SUCCESSFULLY");

                            .println("The transaction finished UNSUCCESSFULLY");

I think i my problem is the right input in sha256hash = new Sha256Hash(...) instance.

Any help?


I suppose you use the BitCoinJ library.

You are not creating a signature the correct way; an ECDSASignature object should be initialized with the ECDSA signature parameters (r,s), not the actual private and public keys. The constructor you are using, implies that the ECDSA signature has been computed already, you somehow got r and s and you initiate the signature object.

To achieve your required functionality, use the doSign(Sha256Hash input, BigInteger privateKeyForSigning) method of your ECKey and the output will be your desired ECDSASignature object.

The input on doSign should be the same with the input on verify, which is always the SHA256 of your message to be signed. If you want to spend an P2PKH output you must sign the public key, check this post for more information.

  • I actually created my ECDSASignature object by using the sign(Sha256 input). My input was : Sha256Hash input=new Sha256Hash(rwallet.getClientKey().getPrivKeyBytes()); And then in verification function in both ways first with:rKey .verify(sha256hash, redeemerSignature)) and second with : ECKey .verify(sha256hash.getBytes(), redeemerSignature, rKey.getPubKey())) works correct.
    – gtopal
    Dec 30 '15 at 7:58
  • Eventually, @Konstantinos you are right about the thing that I have to sign a message and not the getPrivKeyBytes() result,as it will reveal information about my private key. I think the best thing is to sign a Transaction object,but for my program's functionality requirements...i will sign a message( which in fact will be a String).
    – gtopal
    Jan 9 '16 at 20:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.