<p>Signing the bytes of the private key of <code>ECKey key</code> is unacceptable because you are vulnerable for realeasing information about your private key.</p>

<p>In the case of signing a <strong>message</strong>(as a String) you have to estimate the :</p>

<pre><code> byte[] result= sha256(message)
</code></pre>

<p>The result will be a byte[] and this array finally will insert to the :</p>

<pre><code> Sha256Hash input= new Sha256Hash(result);
</code></pre>

<p>Then the procedure is simple in order to produce the <strong>ECDSASignature</strong>.
You have to do the following:</p>

<pre><code>ECDSASignature signature= key.sign(input);
</code></pre>

<p>and finally in order to validate your signature you have to check the following:</p>

<pre><code>key.verify(input, signature)
</code></pre>

CC BY-SA 3.0
2016-01-10T16:27:33.520Z
2016-01-10T16:27:33.520Z
gtopal
<p>I have my <code>ECKey key</code>. In order to create an <code>ECDSASignature</code> object with BitcoinJ, we have to call <code>ECDSASignature mySignature = key.sign(Sha256Hash input)</code>.</p>

<p>Is the <code>Sha256Hash input</code> my message? Or is it the result of <code>Sha256(byte[] myArray)</code>?</p>

<p>What if I don't have a message to sign? Is it acceptable to sign the <code>key.getPrivKeyBytes()</code> in order to create an <code>ECDSASignature</code>, or it is unacceptable because it reveals information including in <code>getPrivKeyBytes()</code> and as a result reveal my private key?</p>

<p>And if it is unacceptable what must be my message? Can I can sign whatever I want in order to create my <code>ECDSASignature</code>?</p>

CC BY-SA 3.0
2016-01-09T17:28:14.093Z
Are you trying to sign a transaction? There are better ways of doing that in bitcoinj. What are you trying to sign?
Nick ODell
CC BY-SA 3.0
2016-01-09T17:34:35.530Z
Let's say that first: i am trying to sign a transaction and as a second secnario that i am going to sign a message in the form of String variable.Which are these better ways?Thanks.
gtopal
CC BY-SA 3.0
2016-01-09T19:09:30.400Z
http://bitcoin.stackexchange.com/questions/3374/how-to-redeem-a-basic-tx
amaclin
CC BY-SA 3.0
2016-01-09T20:32:27.770Z
Thanks. I will actually create a message (as a String variable) rather than a whole transaction,and finally i will sign this message to fulfill my program's functionality desires.
gtopal
CC BY-SA 3.0
2016-01-09T21:55:05.047Z
@Top If you're trying to sign a transaction, you should use `Wallet.signTransaction(Wallet.SendRequest.forTx(transaction));` If you're trying to sign a message, you should hash the message first with SHA256.
Nick ODell
<private-key><bitcoinj><ecdsa><java>
ECKey.ECDSASignature creation
gtopal
# ECKey.ECDSASignature creation

(Asked by: username_0 on 2016-01-09)

I have my `ECKey key`. In order to create an `ECDSASignature` object with BitcoinJ, we have to call `ECDSASignature mySignature = key.sign(Sha256Hash input)`.

Is the `Sha256Hash input` my message? Or is it the result of `Sha256(byte[] myArray)`?

What if I don't have a message to sign? Is it acceptable to sign the `key.getPrivKeyBytes()` in order to create an `ECDSASignature`, or it is unacceptable because it reveals information including in `getPrivKeyBytes()` and as a result reveal my private key?

And if it is unacceptable what must be my message? Can I can sign whatever I want in order to create my `ECDSASignature`?

**Tags:** private-key, bitcoinj, ecdsa, java

> **Comments:**
> **username_1**: Are you trying to sign a transaction? There are better ways of doing that in bitcoinj. What are you trying to sign?  
> **username_0**: Let's say that first: i am trying to sign a transaction and as a second secnario that i am going to sign a message in the form of String variable.Which are these better ways?Thanks.  
> **username_2**: http://bitcoin.stackexchange.com/questions/3374/how-to-redeem-a-basic-tx  
> **username_0**: Thanks. I will actually create a message (as a String variable) rather than a whole transaction,and finally i will sign this message to fulfill my program's functionality desires.  
> **username_1**: @Top If you're trying to sign a transaction, you should use `Wallet.signTransaction(Wallet.SendRequest.forTx(transaction));` If you're trying to sign a message, you should hash the message first with SHA256.  

---

## 1 answers

### Answer by username_0 on 2016-01-10. Score: 1 | Accepted answer

Signing the bytes of the private key of ECKey key is unacceptable because you are vulnerable for realeasing information about your private key.
In the case of signing a message(as a String) you have to estimate the :
 byte[] result= sha256(message)

The result will be a byte[] and this array finally will insert to the :
 Sha256Hash input= new Sha256Hash(result);

Then the procedure is simple in order to produce the ECDSASignature.
You have to do the following:
ECDSASignature signature= key.sign(input);

and finally in order to validate your signature you have to check the following:
key.verify(input, signature)


---

