<p>If Eve gives you a private key that contains Bitcoins in exchange for a pile of gold coins, she still has a copy of the private key, and can take the Bitcoins back, leaving her with both the gold coins and the Bitcoins.</p>

<p>Instead, tell Eve to send Bitcoins to your address.</p>

CC BY-SA 3.0
2015-09-11T05:14:17.557Z
2015-09-11T05:14:17.557Z
Nick ODell
<p>The problem is rather subtle and results from a combination of behaviors.</p>

<p>First of all, it is perfectly safe to use someone else's private key, at least in a standalone sense. Suppose the private key is <em>P</em> and the public address is <em>A</em>, and suppose you want to spend their money. Then you scan the blockchain for transactions outputs that are addressed to <em>A</em>. When you see one, you create a new transaction to some desired output address <em>B</em> (whether you're paying yourself or paying someone else), and sign it with the private key <em>P</em>. No problems here.</p>

<p>The problem starts when we're talking about wallet software. If you "import" a private key <em>P</em> into your wallet, then it gets added to your personal pool of private keys (and their associated public addresses). Whenever you make an outgoing transaction, some amount will almost always be sent back to yourself as change. If the change goes to address <em>A</em> (with associated private key <em>P</em>), then other people who know the private key <em>P</em> can also spend this money. Ultimately this means that if you import someone else's private key, you might lose control of your own money in some circumstances.</p>

<p>As other people have mentioned, the safe way to handle this situation is to "sweep" the coins associated with address <em>A</em> (using private key <em>P</em>) into addresses that you have exclusive control over. In other words, use that private key to pay yourself, but never use the address as an output for change.</p>

<hr>

<p>As an analogy: Suppose you're in a hall with numbered lockers. It's always possible to deposit money into any locker (only need the address, not the private key). Locker #0 can be opened by both your friend and yourself. Locker #1 and #2 are only openable by you.</p>

<p>If you have cash in lockers #1 and #2, this belongs to you and you alone. Now when you make a transaction, you take cash out of one or both of these lockers, then return some as change. You can also take cash out of locker #0, no problem. But if you <em>return</em> some change into locker #0, then you lose your exclusive control over that cash. So you must only return change to your own lockers #1 and #2, not the shared locker #0.</p>

CC BY-SA 3.0
2015-09-11T15:54:39.300Z
2015-09-11T19:31:44.380Z
2015-09-11T19:31:44.380Z
Nayuki
<p>A question was asked on reddit over here which I gave a reply: <a href="https://www.reddit.com/r/Bitcoin/comments/3khrvm/how_do_i_use_private_keys_to_receive_bitcoin/">https://www.reddit.com/r/Bitcoin/comments/3khrvm/how_do_i_use_private_keys_to_receive_bitcoin/</a></p>

<p>However, <a href="https://www.reddit.com/r/Bitcoin/comments/3khrvm/how_do_i_use_private_keys_to_receive_bitcoin/cuxleaq">luke-jr replies</a> with:</p>

<blockquote>
  <p>Don't do this. You compromise your wallet's security to import a private key that others know.</p>
</blockquote>

<p>without further elaboration. Can someone explain what he's talking about?</p>

<wallet><bitcoin-core><security><private-key-import>
How can importprivkey compromise wallet security when importing a publicly known private key?
greatwolf
# How can importprivkey compromise wallet security when importing a publicly known private key?

(Asked by: username_0 on 2015-09-11)

A question was asked on reddit over here which I gave a reply: <https://www.reddit.com/r/Bitcoin/comments/3khrvm/how_do_i_use_private_keys_to_receive_bitcoin/>

However, [luke-jr replies](https://www.reddit.com/r/Bitcoin/comments/3khrvm/how_do_i_use_private_keys_to_receive_bitcoin/cuxleaq) with:

> Don't do this. You compromise your wallet's security to import a private key that others know.

without further elaboration. Can someone explain what he's talking about?

**Tags:** wallet, bitcoin-core, security, private-key-import


---

## 2 answers

### Answer by username_2 on 2015-09-11. Score: 5 | Accepted answer

The problem is rather subtle and results from a combination of behaviors.

First of all, it is perfectly safe to use someone else's private key, at least in a standalone sense. Suppose the private key is *P* and the public address is *A*, and suppose you want to spend their money. Then you scan the blockchain for transactions outputs that are addressed to *A*. When you see one, you create a new transaction to some desired output address *B* (whether you're paying yourself or paying someone else), and sign it with the private key *P*. No problems here.

The problem starts when we're talking about wallet software. If you "import" a private key *P* into your wallet, then it gets added to your personal pool of private keys (and their associated public addresses). Whenever you make an outgoing transaction, some amount will almost always be sent back to yourself as change. If the change goes to address *A* (with associated private key *P*), then other people who know the private key *P* can also spend this money. Ultimately this means that if you import someone else's private key, you might lose control of your own money in some circumstances.

As other people have mentioned, the safe way to handle this situation is to "sweep" the coins associated with address *A* (using private key *P*) into addresses that you have exclusive control over. In other words, use that private key to pay yourself, but never use the address as an output for change.

---

As an analogy: Suppose you're in a hall with numbered lockers. It's always possible to deposit money into any locker (only need the address, not the private key). Locker #0 can be opened by both your friend and yourself. Locker #1 and #2 are only openable by you.

If you have cash in lockers #1 and #2, this belongs to you and you alone. Now when you make a transaction, you take cash out of one or both of these lockers, then return some as change. You can also take cash out of locker #0, no problem. But if you *return* some change into locker #0, then you lose your exclusive control over that cash. So you must only return change to your own lockers #1 and #2, not the shared locker #0.


---

### Answer by username_1 on 2015-09-11. Score: 5

If Eve gives you a private key that contains Bitcoins in exchange for a pile of gold coins, she still has a copy of the private key, and can take the Bitcoins back, leaving her with both the gold coins and the Bitcoins.

Instead, tell Eve to send Bitcoins to your address.


---

