<p>If you are using an encrypted wallet, private keys are never written unencrypted to disk.</p>

<p>However, the 0.4.0 release (the first to feature wallet encryption) had a bug where - upon upgrading a wallet from unencrypted to encrypted - parts of the unencrypted where not necessarily overwritten, leaving them accessible for a while.</p>

<p>0.4.1 and 0.5.0 fix this by first rewriting the entire wallet file upon encryption (or the first start afterwards), and invalidating the entire pool of reserve keys that was present before. This means (and has been tested), that if you start with an empty wallet, and immediately encrypt it, it will not ever use any key that was ever written to disk in unencrypted form.</p>

<p>Note that wallet encryption is not a silver bullet, and an attacker may have other ways of extracting the private key, such as keyloggers.</p>

<p>EDIT: only now I read your question correctly. The log files may contain anything that was attempted to be written to the database files themselves, and if you are using (or were using) an unencrypted wallet, that may indeed mean private keys as well. Again, if you start with an encrypted wallet in 0.5.0, no keys will be used that ever touched disk unencrypted.</p>

CC BY-SA 3.0
2011-12-05T01:38:32.167Z
So how does this encrypted wallet work? Is it still a BerkeleyDB file (unencrypted) that contains private keys that are now individually encrypted before BerkeleyDB sees them? Or does the encryption happen below the BerkeleyDB layer?
Thilo
CC BY-SA 3.0
2011-12-05T06:34:41.570Z
What do you mean "start with an encrypted wallet"? If you start with a fresh wallet, it's not encrypted. You can encrypt it immediately, but it generates some keys before being encrypted ... won't be in the log files?
ripper234
CC BY-SA 3.0
2011-12-05T11:37:22.357Z
Yes, those may end up in the log file. However, as soon as you encrypt it, the keypool is flushed, and 100 new reserve keys are generated. Thus, if you start with a new wallet, and encrypt it before doing anything else with it, those 100 new keys will never touch disk in unencrypted form.
Pieter Wuille
CC BY-SA 3.0
2011-12-05T11:37:58.300Z
Thilo: it's a bdb file as before, only the key material itself is encrypted (at the application level).
Pieter Wuille
CC BY-SA 3.0
2011-12-06T00:54:18.307Z
So, since I am not using Bitcoin encryption, but rather place my wallet.dat (only) on an encrypted disk, my private keys may have ended up in the log files. Any way to purge the logs going forward?
Thilo
CC BY-SA 3.0
2011-12-06T01:02:34.507Z
Also, I was also hoping that placing wallet.dat on an encrypted disk would also protect my public keys (plausible denyability of owning them), which I understand are *not* encrypted using Bitcoin wallet encryption. Those also end up in the logs, right? Even with encryption turned on?
Thilo
CC BY-SA 3.0
2011-12-06T10:57:49.830Z
Encryption only protects the private keys, public keys are available without passphrase. And if you do a clean shutdown, you can safely remove the log files and files in the database directory.
Pieter Wuille
CC BY-SA 3.0
2011-12-04T14:55:30.500Z
2011-12-04T23:24:44.670Z
2011-12-04T23:24:44.670Z
Pieter Wuille
<p>I read this <a href="https://github.com/bitcoin/bitcoin/issues/660">little nugget on the bitcoin client bug tracker</a>:</p>

<blockquote>
  <p>the bdb binary log files can also contain sensitive data such as private keys</p>
</blockquote>

<p>Is that true? Does this mean that even with an encrypted wallet.dat, there might be a way that the private keys are written to disk unprotected? If so, what can I do about it?</p>

<security><wallet><encryption>
Does the BerkeleyDB-based wallet.dat implementation leak private key data?
Thilo
# Does the BerkeleyDB-based wallet.dat implementation leak private key data?

(Asked by: username_0 on 2011-12-04)

I read this [little nugget on the bitcoin client bug tracker](https://github.com/bitcoin/bitcoin/issues/660):

> the bdb binary log files can also contain sensitive data such as private keys

Is that true? Does this mean that even with an encrypted wallet.dat, there might be a way that the private keys are written to disk unprotected? If so, what can I do about it?

**Tags:** security, wallet, encryption


---

## 1 answers

### Answer by username_1 on 2011-12-04. Score: 3 | Accepted answer

If you are using an encrypted wallet, private keys are never written unencrypted to disk.

However, the 0.4.0 release (the first to feature wallet encryption) had a bug where - upon upgrading a wallet from unencrypted to encrypted - parts of the unencrypted where not necessarily overwritten, leaving them accessible for a while.

0.4.1 and 0.5.0 fix this by first rewriting the entire wallet file upon encryption (or the first start afterwards), and invalidating the entire pool of reserve keys that was present before. This means (and has been tested), that if you start with an empty wallet, and immediately encrypt it, it will not ever use any key that was ever written to disk in unencrypted form.

Note that wallet encryption is not a silver bullet, and an attacker may have other ways of extracting the private key, such as keyloggers.

EDIT: only now I read your question correctly. The log files may contain anything that was attempted to be written to the database files themselves, and if you are using (or were using) an unencrypted wallet, that may indeed mean private keys as well. Again, if you start with an encrypted wallet in 0.5.0, no keys will be used that ever touched disk unencrypted.

> **Comments:**
> **username_0**: So how does this encrypted wallet work? Is it still a BerkeleyDB file (unencrypted) that contains private keys that are now individually encrypted before BerkeleyDB sees them? Or does the encryption happen below the BerkeleyDB layer?  
> **username_2**: What do you mean "start with an encrypted wallet"? If you start with a fresh wallet, it's not encrypted. You can encrypt it immediately, but it generates some keys before being encrypted ... won't be in the log files?  
> **username_1**: Yes, those may end up in the log file. However, as soon as you encrypt it, the keypool is flushed, and 100 new reserve keys are generated. Thus, if you start with a new wallet, and encrypt it before doing anything else with it, those 100 new keys will never touch disk in unencrypted form.  
> **username_1**: username_0: it's a bdb file as before, only the key material itself is encrypted (at the application level).  
> **username_0**: So, since I am not using Bitcoin encryption, but rather place my wallet.dat (only) on an encrypted disk, my private keys may have ended up in the log files. Any way to purge the logs going forward?  
> **username_0**: Also, I was also hoping that placing wallet.dat on an encrypted disk would also protect my public keys (plausible denyability of owning them), which I understand are *not* encrypted using Bitcoin wallet encryption. Those also end up in the logs, right? Even with encryption turned on?  
> **username_1**: Encryption only protects the private keys, public keys are available without passphrase. And if you do a clean shutdown, you can safely remove the log files and files in the database directory.  

---

