0

I was trying different things to verify the signature but couldn't succeed. I have got the following: message in string or decimal array (ASCII code for each char) public key in decimal array (which I can change it into HASH160(Publick Key) using RIPEMD160(SHA256(Public Key))) signature in decimal array Now I wanted to verify that the signature is valid or not using java8 (OpenJDK8), please help!

1
  • I have used bitcoinj-core 0.15.7 library with the following code but I'm getting false always: public static boolean verifySignature(byte[] data, byte[] signature, byte[] pub) throws SignatureDecodeException { boolean verified = false; verified = ECKey.verify(data, signature, pub); return verified; }
    – Bhala T R
    Apr 26, 2020 at 17:16

2 Answers 2

0

The code you are using to verify the signature is correct according to the bitcoinj-core 0.15.7 library. What may be wrong is the data you are verifying.

When spending a Transaction Output in a new transaction, the entire new transaction (with a few modifications) is signed to prevent malleability. For a simple transaction the "signing type", or SIGHASH, is typically SIGHASH_ALL and is represented by the number 0x01000000 (little-endian). This means that, for every transaction input you sign, the output's scriptSig is placed where the signature would go for that input, all other input signature fields are set to empty, and the SIGHASH is appended to the end of the transaction.

Details for verifying a standard transaction has already been answered, and includes step-by-step instructions: How to redeem a basic Tx?

0

public static boolean verifySignature(byte[] data, byte[] signature, byte[] pub) throws SignatureDecodeException, NoSuchAlgorithmException { boolean verified = false; reverse(data); verified = ECKey.verify(data, signature, pub); return verified; } Sometimes reversing the data alone helped getting as TRUE.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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