How to import a private key to an encrypted wallet (on standard client) 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).
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" : ""
  }