<p>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.</p>

CC BY-SA 4.0
2020-05-04T13:34:36.103Z
2020-05-04T13:34:36.103Z
Bhala T R
<p>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.</p>

<p>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 <code>SIGHASH</code>, is typically <code>SIGHASH_ALL</code> and is represented by the number <code>0x01000000</code> (little-endian). This means that, for every transaction input you sign, the output's <code>scriptSig</code> is placed where the signature would go for that input, all other input signature fields are set to empty, and the <code>SIGHASH</code> is appended to the end of the transaction.</p>

<p>Details for verifying a standard transaction has already been answered, and includes step-by-step instructions: <a href="https://bitcoin.stackexchange.com/questions/3374/how-to-redeem-a-basic-tx">How to redeem a basic Tx?</a></p>

CC BY-SA 4.0
2020-04-26T21:27:40.233Z
2020-04-26T21:27:40.233Z
Septem151
<p>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! </p>

CC BY-SA 4.0
2020-04-26T17:16:25.347Z
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
<signature><java>
How to verify signature in java using message and public key?
Bhala T R
# How to verify signature in java using message and public key?

(Asked by: username_0 on 2020-04-26)

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!

**Tags:** signature, java

> **Comments:**
> **username_0**: 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;     }`  

---

## 2 answers

### Answer by username_0 on 2020-05-04. Score: 0 | Accepted answer

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.


---

### Answer by username_1 on 2020-04-26. Score: 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?](https://bitcoin.stackexchange.com/questions/3374/how-to-redeem-a-basic-tx)


---

