user68099: I'm trying to create a transaction on the testnet (manually). I have the following private key: cQKqSNkEdyLJziQSr4iKTUJC95s9HHFo4bY88gi2i6v2quiVVLZb which belongs to the following public address: mkhn3gfrGHmd4b1ZmHLdMsbQd2eHRKg8wN. When I try to sign the transaction, the public (uncompressed) key that I generate, is: 042d7331345e0da6ab1125eb39488a542a9923f31c585c20114d211a9f6bc9f3bf55d1d843cb7cf1d36b32d1cb00d2f140ef028e726a19a766f6ca7cef7b956583. This turns out to be invalid (because the transaction gets rejected by the network). However, when I tried using a tool for signing the transaction, it generated the following (correct) public key: 040b4a4274222d7239d33c17ce39d753eee97103773b7e5a89e62f0ef0121032d7331345e0da6ab1125eb39488a542a9923f31c585c20114d211a9f6bc9f3b.
What is the difference between these keys? How come the first one is incorrect when signing the tx but correct when I generated the public address for it?

user38482: Some observations: the priv key matches with the first compressed address (mkhn3...). It fits to the pubkey in hex, see below. 
The way keys are derived is described here - see also the picture.
http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html

Once you have the pubkey in hex, there are 8 following steps to come to the final bitcoin address:
1 - Public ECDSA Key
2 - SHA-256 hash of 1
3 - RIPEMD-160 Hash of 2
4 - Adding network bytes to 3
5 - SHA-256 hash of 4
6 - SHA-256 hash of 5
7 - First four bytes of 6
8 - Adding 7 at the end of 4
9 - Base58 encoding of 8

The first uncompressed pubkey (which fits to the privkey):

042d7331345e0da6ab1125eb39488a542a9923f31c585c20114d211a9f6bc9f3bf55d1d843cb7cf1d36b32d1cb00d2f140ef028e726a19a766f6ca7cef7b956583

would convert into this bitcoin address: 
myfp2YcyYjksxmdfA74yEuBmaUgt9xWCot

and your second uncompressed pubkey

040b4a4274222d7239d33c17ce39d753eee97103773b7e5a89e62f0ef0121032d7331345e0da6ab1125eb39488a542a9923f31c585c20114d211a9f6bc9f3b

would convert to this bitcoin address:
mmKUwoRgd9YdvRYYXGyumjduRMTAPCnkMz

I am not sure which tools you used to create your keys, it looks like you have somewhere a gap between using compressed and uncompressed keys. 
A very good reference is in the online book from Andreas ("Mastering Bitcoin, 2nd edition"), which is also online readable (see chapter 4...).

68099: <p>I'm trying to create a transaction on the testnet (manually). I have the following private key: <code>cQKqSNkEdyLJziQSr4iKTUJC95s9HHFo4bY88gi2i6v2quiVVLZb</code> which belongs to the following public address: <code>mkhn3gfrGHmd4b1ZmHLdMsbQd2eHRKg8wN</code>. When I try to sign the transaction, the public (uncompressed) key that I generate, is: <code>042d7331345e0da6ab1125eb39488a542a9923f31c585c20114d211a9f6bc9f3bf55d1d843cb7cf1d36b32d1cb00d2f140ef028e726a19a766f6ca7cef7b956583</code>. This turns out to be invalid (because the transaction gets rejected by the network). However, when I tried using a tool for signing the transaction, it generated the following (correct) public key: <code>040b4a4274222d7239d33c17ce39d753eee97103773b7e5a89e62f0ef0121032d7331345e0da6ab1125eb39488a542a9923f31c585c20114d211a9f6bc9f3b</code>.</p>

<p>What is the difference between these keys? How come the first one is incorrect when signing the tx but correct when I generated the public address for it?</p>
 38482: <p>Some observations: the priv key matches with the first compressed address (mkhn3...). It fits to the pubkey in hex, see below. 
The way keys are derived is described here - see also the picture.
<a href="http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html" rel="nofollow noreferrer">http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html</a></p>

<p><a href="https://i.stack.imgur.com/Uw5oB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Uw5oB.png" alt="enter image description here"></a></p>

<p>Once you have the pubkey in hex, there are 8 following steps to come to the final bitcoin address:</p>

<pre><code>1 - Public ECDSA Key
2 - SHA-256 hash of 1
3 - RIPEMD-160 Hash of 2
4 - Adding network bytes to 3
5 - SHA-256 hash of 4
6 - SHA-256 hash of 5
7 - First four bytes of 6
8 - Adding 7 at the end of 4
9 - Base58 encoding of 8
</code></pre>

<p>The first <strong>uncompressed</strong> pubkey (which fits to the privkey):</p>

<blockquote>
  <p>042d7331345e0da6ab1125eb39488a542a9923f31c585c20114d211a9f6bc9f3bf55d1d843cb7cf1d36b32d1cb00d2f140ef028e726a19a766f6ca7cef7b956583</p>
</blockquote>

<p>would convert into this bitcoin address: </p>

<pre><code>myfp2YcyYjksxmdfA74yEuBmaUgt9xWCot
</code></pre>

<p>and your second <strong>uncompressed</strong> pubkey</p>

<blockquote>
  <p>040b4a4274222d7239d33c17ce39d753eee97103773b7e5a89e62f0ef0121032d7331345e0da6ab1125eb39488a542a9923f31c585c20114d211a9f6bc9f3b</p>
</blockquote>

<p>would convert to this bitcoin address:</p>

<pre><code>mmKUwoRgd9YdvRYYXGyumjduRMTAPCnkMz
</code></pre>

<p>I am not sure which tools you used to create your keys, it looks like you have somewhere a gap between using <strong>compressed</strong> and <strong>uncompressed</strong> keys. 
A very good reference is in the online book from Andreas ("Mastering Bitcoin, 2nd edition"), which is also online readable (see chapter 4...).</p>
