<p>You cannot. While both message and transaction signing use ECDSA and double sha256, signed messages slightly modify the message such that it is impossible to create a signature that works for that key in a transaction.</p>

<p>Specifically, bitcoin signed messages are prefixed with the string <code>Bitcoin Signed Message:\n</code> (<code>\n</code> is the newline character, not literally <code>\</code> and <code>n</code>). This means that the data that is actually signed cannot be for a transaction since the data signed for a transaction cannot begin with that string. This design is intentional so that users cannot be tricked into signing a message which can be used in a transaction to take their money.</p>

<p>The output looks different just due to serialization. If the signatures were compatible, you would just deserialize the signed message signature and reserialize it differently. But because the signatures are not compatible, this point is moot.</p>

CC BY-SA 4.0
2020-04-14T06:48:33.977Z
Perhaps point out that this is by design: otherwise you could try to get someone to sign a specific message, and then use it to steal their money.
Pieter Wuille
CC BY-SA 4.0
2020-04-14T07:51:18.757Z
if i have the rawhex that i want to sign. Why can't i construct a message with 'Bitcoin Signed Message:' in front of it and then sign it?
user3554230
CC BY-SA 4.0
2020-04-14T07:52:08.760Z
i guess i am asking if the actual ecdsa function and hashing are identical. It seems like adding a string in front of signed data is pretty easy to do ? how is this serialized vs a traditional tx signature ?
user3554230
CC BY-SA 4.0
2020-04-14T16:03:08.977Z
@user3554230 Signatures for transactions follow a very specific format. They are, for the most part, just the transaction itself with a couple modifications. The data that is signed is not included in the transaction explicitly, verifiers construct it from the transaction that they receive. So you can't just "add a string in front of the signed data" for a signature in a transaction.
Ava Chow
CC BY-SA 4.0
2020-04-14T06:44:05.523Z
2020-04-14T16:01:19.237Z
2020-04-14T16:01:19.237Z
Ava Chow
<p>can i use the sign message function to sign the serialized hex for a p2sh transaction? Are the ecdsa functions used the same or are they different? It looks like the output is in a different format than a traditional tx signature? How can one use this function to sign?</p>

<signature><p2sh><message-signing>
difference between signing a message and signing a p2sh
user3554230
# difference between signing a message and signing a p2sh

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

can i use the sign message function to sign the serialized hex for a p2sh transaction? Are the ecdsa functions used the same or are they different? It looks like the output is in a different format than a traditional tx signature? How can one use this function to sign?

**Tags:** signature, p2sh, message-signing


---

## 1 answers

### Answer by username_1 on 2020-04-14. Score: 1 | Accepted answer

You cannot. While both message and transaction signing use ECDSA and double sha256, signed messages slightly modify the message such that it is impossible to create a signature that works for that key in a transaction.

Specifically, bitcoin signed messages are prefixed with the string `Bitcoin Signed Message:\n` (`\n` is the newline character, not literally `\` and `n`). This means that the data that is actually signed cannot be for a transaction since the data signed for a transaction cannot begin with that string. This design is intentional so that users cannot be tricked into signing a message which can be used in a transaction to take their money.

The output looks different just due to serialization. If the signatures were compatible, you would just deserialize the signed message signature and reserialize it differently. But because the signatures are not compatible, this point is moot.

> **Comments:**
> **username_2**: Perhaps point out that this is by design: otherwise you could try to get someone to sign a specific message, and then use it to steal their money.  
> **username_0**: if i have the rawhex that i want to sign. Why can't i construct a message with 'Bitcoin Signed Message:' in front of it and then sign it?  
> **username_0**: i guess i am asking if the actual ecdsa function and hashing are identical. It seems like adding a string in front of signed data is pretty easy to do ? how is this serialized vs a traditional tx signature ?  
> **username_1**: @username_0 Signatures for transactions follow a very specific format. They are, for the most part, just the transaction itself with a couple modifications. The data that is signed is not included in the transaction explicitly, verifiers construct it from the transaction that they receive. So you can't just "add a string in front of the signed data" for a signature in a transaction.  

---

