<p>Since 0.6.0, key import/export are available in the client itself, though only through RPC. The commands are called <code>dumpprivkey</code> and <code>importprivkey</code>. For example (on testnet):</p>

<blockquote>
  <p>$ ./bitcoind getnewaddress</p>
  
  <p>n2JjZgLeCUgfubswxDm9zAaBGSLLHSLdNv</p>
  
  <p>$ ./bitcoind dumpprivkey n2JjZgLeCUgfubswxDm9zAaBGSLLHSLdNv</p>
  
  <p>cR4RtpaeAZY8MwrNvTQGX9PZ9pdCgFoLxuo4Pkwqx61broC4Gb4y</p>
</blockquote>

<p>And on another wallet:</p>

<blockquote>
  <p>$ ./bitcoind importprivkey R4RtpaeAZY8MwrNvTQGX9PZ9pdCgFoLxuo4Pkwqx61broC4Gb4y</p>
  
  <p>$ ./bitcoind validateaddress n2JjZgLeCUgfubswxDm9zAaBGSLLHSLdNv</p>
  
  <p>{
      "isvalid" : true,
      "address" : "n2JjZgLeCUgfubswxDm9zAaBGSLLHSLdNv",
      "ismine" : true,
      "pubkey" : "029e3a934cfc9f89d7a1c15f99b98479cabc81964f4972e7b8fa3989a788261695",
      "iscompressed" : true,
      "account" : ""
  }</p>
</blockquote>

CC BY-SA 3.0
2012-04-30T16:35:57.070Z
Oh, apparently bitcoin-qt doesn't provide a server for the command line client to connect to; also looks like bitcoind isn't starting anymore, crashing with an exception a few seconds after it started... (does it support encrypted wallets? in the options I noticed nothing about that...)
o0'.
CC BY-SA 3.0
2012-04-30T16:37:17.133Z
You need to run "bitcoin-qt -server" to get it to provide a server.  And you'll need to have 'rpcuser=x' and 'rpcpassword=y' in your bitcoin.conf file, but I think bitcoin-qt will tell you that if you don't have it.  bitcoind supports encrypted wallets, but make sure you're using the same version as the version of bitcoin-qt you have.
Chris Moore
CC BY-SA 3.0
2012-04-30T16:45:08.463Z
@ChrisMoore mmmh, doing so I only get errors -4"Error adding key to wallet" if I try to add `priv_sipa` or -5"Invalid private key" if I try to add `priv`
o0'.
CC BY-SA 3.0
2012-04-30T17:29:20.983Z
Oh, you need to unencrypt your wallet temporarily so it can add the new key.  I do the following, so my passphrase doesn't end up in my shell history.  It unlocks the wallet for 60 seconds: read x; ./bitcoind walletpassphrase "$x" 60; unset x
Chris Moore
CC BY-SA 3.0
2012-05-02T18:25:03.640Z
I can't do that: if I run the server from command line, it crashes after a while, and the same happens if I run the QT client with the -server option.
o0'.
CC BY-SA 3.0
2012-05-05T12:10:36.897Z
Then that's a bug. Can you report it on github? Nonetheless, this answer is how importing of keys is intended to be done.
Pieter Wuille
CC BY-SA 3.0
2012-04-30T16:23:09.687Z
2012-04-30T16:23:09.687Z
Pieter Wuille
<p>I have a standard client (QT client on OSX) with an encrypted wallet. I've tried to import keys with pywallet, but while it claimed to be importing them, when I ran again the bitcoin client, it said wallet.dat was corrupted (yes the client wasn't running when I did the import).</p>

<p>I guess pywallet doesn't know about encryption and didn't care enough to check everything was ok before importing them.</p>

<p>So, how do I do this import?</p>

<hr>

<p>Trying to run the command line client gets me the following error a few seconds after starting it (with -daemon option of course):</p>

<pre><code>EXCEPTION: NSt8ios_base7failureE       
CDataStream::read() : end of data       
bitcoin in AppInit()       
</code></pre>

<hr>

<p>Running the QT client with the <code>-server</code> option crashes too after a while (apparently it works correctly without that).</p>

CC BY-SA 3.0
2012-05-02T19:24:46.633Z
I managed to import them to MultiBit, however it isn't working anyway: http://bitcoin.stackexchange.com/questions/3549/why-does-multibit-claim-my-balance-is-zero-btc
o0'.
<wallet><backup><encryption><wallet-recovery>
How to import a private key to an encrypted wallet (on standard client)
o0'.
# How to import a private key to an encrypted wallet (on standard client)

(Asked by: username_0 on 2012-04-30)

I have a standard client (QT client on OSX) with an encrypted wallet. I've tried to import keys with pywallet, but while it claimed to be importing them, when I ran again the bitcoin client, it said wallet.dat was corrupted (yes the client wasn't running when I did the import).
I guess pywallet doesn't know about encryption and didn't care enough to check everything was ok before importing them.
So, how do I do this import?

Trying to run the command line client gets me the following error a few seconds after starting it (with -daemon option of course):
EXCEPTION: NSt8ios_base7failureE       
CDataStream::read() : end of data       
bitcoin in AppInit()       


Running the QT client with the -server option crashes too after a while (apparently it works correctly without that).

**Tags:** wallet, backup, encryption, wallet-recovery

> **Comments:**
> **username_0**: I managed to import them to MultiBit, however it isn't working anyway: http://bitcoin.stackexchange.com/questions/3549/why-does-multibit-claim-my-balance-is-zero-btc  

---

## 1 answers

### Answer by username_1 on 2012-04-30. Score: 5

Since 0.6.0, key import/export are available in the client itself, though only through RPC. The commands are called `dumpprivkey` and `importprivkey`. For example (on testnet):

> $ ./bitcoind getnewaddress
>
> n2JjZgLeCUgfubswxDm9zAaBGSLLHSLdNv
>
> $ ./bitcoind dumpprivkey n2JjZgLeCUgfubswxDm9zAaBGSLLHSLdNv
>
> cR4RtpaeAZY8MwrNvTQGX9PZ9pdCgFoLxuo4Pkwqx61broC4Gb4y

And on another wallet:

> $ ./bitcoind importprivkey R4RtpaeAZY8MwrNvTQGX9PZ9pdCgFoLxuo4Pkwqx61broC4Gb4y
>
> $ ./bitcoind validateaddress n2JjZgLeCUgfubswxDm9zAaBGSLLHSLdNv
>
> {
> "isvalid" : true,
> "address" : "n2JjZgLeCUgfubswxDm9zAaBGSLLHSLdNv",
> "ismine" : true,
> "pubkey" : "029e3a934cfc9f89d7a1c15f99b98479cabc81964f4972e7b8fa3989a788261695",
> "iscompressed" : true,
> "account" : ""
> }

> **Comments:**
> **username_0**: Oh, apparently bitcoin-qt doesn't provide a server for the command line client to connect to; also looks like bitcoind isn't starting anymore, crashing with an exception a few seconds after it started... (does it support encrypted wallets? in the options I noticed nothing about that...)  
> **username_2**: You need to run "bitcoin-qt -server" to get it to provide a server.  And you'll need to have 'rpcuser=x' and 'rpcpassword=y' in your bitcoin.conf file, but I think bitcoin-qt will tell you that if you don't have it.  bitcoind supports encrypted wallets, but make sure you're using the same version as the version of bitcoin-qt you have.  
> **username_0**: @ChrisMoore mmmh, doing so I only get errors -4"Error adding key to wallet" if I try to add `priv_sipa` or -5"Invalid private key" if I try to add `priv`  
> **username_2**: Oh, you need to unencrypt your wallet temporarily so it can add the new key.  I do the following, so my passphrase doesn't end up in my shell history.  It unlocks the wallet for 60 seconds: read x; ./bitcoind walletpassphrase "$x" 60; unset x  
> **username_0**: I can't do that: if I run the server from command line, it crashes after a while, and the same happens if I run the QT client with the -server option.  
> **username_1**: Then that's a bug. Can you report it on github? Nonetheless, this answer is how importing of keys is intended to be done.  

---

