<p>The Bitcoin Core client stores private keys typically  in DER encoded format, at 279 bytes per key, for compatibility with older versions. There is no good reason for that though. For encrypted wallets, which are more modern, keys are stored using just the (encrypted) 32 byte secret plus the full public key. Compression is derived from the length of the corresponding public key, so it doesn't need to be stored separately.</p>

CC BY-SA 3.0
2014-08-29T11:29:10.827Z
2014-08-29T11:29:10.827Z
Pieter Wuille
<p>I'm writing an Android app which will be storing private keys for Bitcoin and a few Altcoins in an SQLite database. To store my private keys, I was initially using the WIF. When I take them out of the database, however, I just Base58 decode them back into the 32 byte private key. Is there any real advantage to using the Base58 format for <strong>storing</strong> the keys in WIF vs basic hex encoding (0x12 to "12")? I know the WIF is useful for human transposition, but I'm specifically wondering about storage here. </p>

<p>So far, what I've come up with is that the Base58 format:
<ol>
<li> Takes slightly less space </li>
<li> Tells me what coin type the address is used for </li>
<li> Has error checking </li>
<li> Tells whether the private key is used for a compressed or decompressed address. </li>
</ol> 
</p>

<p>
Items 2-4, however, are things that I could get from other entries in my SQLite database, so they're not critical. <strong>How does the Bitcoin-QT client store its private keys?</strong> I know when it dumps them to the user it gives them in WIF, but I'm wondering what it does internally to save keys on the machine and if I should do it the same way.
</p>

<wallet-import-format>
WIF Format and Storing Private Keys
morsecoder
# WIF Format and Storing Private Keys

(Asked by: username_0 on 2014-08-29)

I'm writing an Android app which will be storing private keys for Bitcoin and a few Altcoins in an SQLite database. To store my private keys, I was initially using the WIF. When I take them out of the database, however, I just Base58 decode them back into the 32 byte private key. Is there any real advantage to using the Base58 format for **storing** the keys in WIF vs basic hex encoding (0x12 to "12")? I know the WIF is useful for human transposition, but I'm specifically wondering about storage here.

So far, what I've come up with is that the Base58 format:

1. Takes slightly less space
2. Tells me what coin type the address is used for
3. Has error checking
4. Tells whether the private key is used for a compressed or decompressed address.

Items 2-4, however, are things that I could get from other entries in my SQLite database, so they're not critical. **How does the Bitcoin-QT client store its private keys?** I know when it dumps them to the user it gives them in WIF, but I'm wondering what it does internally to save keys on the machine and if I should do it the same way.

**Tags:** wallet-import-format


---

## 1 answers

### Answer by username_1 on 2014-08-29. Score: 2 | Accepted answer

The Bitcoin Core client stores private keys typically in DER encoded format, at 279 bytes per key, for compatibility with older versions. There is no good reason for that though. For encrypted wallets, which are more modern, keys are stored using just the (encrypted) 32 byte secret plus the full public key. Compression is derived from the length of the corresponding public key, so it doesn't need to be stored separately.


---

