<p>A wallet.dat file contains much more than just addresses. In fact, it mostly does not contain addresses at all. There will be some addresses because they are added to the address book, but the wallet mostly deals with keys, with addresses being computed from the keys as needed.</p>
<p>There are also two wallet types - legacy wallets and descriptor wallets. Legacy wallets will store keys explicitly, while descriptor wallets generally do not. But descriptor wallets also use SQLite rather than BDB, so you are dealing with a legacy wallet.</p>
<p>For both types of wallet, each record in the wallet database will begin with a length prefixed string indicating what kind of data is stored there. If you want addresses from the address book, the  string will be <code>name</code>. This will then be followed by a length prefixed string for the address. The value of the record will be a length prefix string for the label to apply to that address. It may be empty (0 length).</p>
<p>To get all of the addresses for a legacy wallet, you will need to find all of the keys and compute addresses for each key. Keys are stored in <code>key</code> records. The public key follows the string <code>key</code>, and the private key will be the value of the record serialized using DER. See section C.4 of the <a href="https://www.secg.org/sec1-v2.pdf" rel="nofollow noreferrer">secp paper</a> for details on that.</p>
<p>For descriptor wallets, you can get the descriptor record and derive addresses from there. Individual keys and addresses are not stored for descriptor wallets.</p>

CC BY-SA 4.0
2021-11-16T02:10:21.660Z
2021-11-16T02:10:21.660Z
Ava Chow
<p>I have searched all threads, but still couldn't find an answer.
I am trying to read from a wallet that is not encrypted, but I am not able to proceed on retrieving the address values, they are byte[] but I can't convert them to the respective addresses.</p>
<pre><code>        {
            BTreeDatabase bdb = OpenBTDB(srcWalletFileName);
            Cursor c1 = bdb.Cursor();
            var currValue = c1.First().Value;

            string NoEnc = currValue.ToString();
            string defaultEnc = Encoding.Default.GetString(currValue.Data);
            string utf8Enc = Encoding.UTF8.GetString(currValue.Data);
            string asciiEnc = Encoding.ASCII.GetString(currValue.Data);
            string utf16Enc = Encoding.BigEndianUnicode.GetString(currValue.Data);
            string utf32Enc = Encoding.UTF32.GetString(currValue.Data);
            string utf7Enc = Encoding.UTF7.GetString(currValue.Data);
            string isoEnc = Encoding.GetEncoding(&quot;ISO-8859-1&quot;).GetString(currValue.Data);
            string b64Enc = Convert.ToBase64String(currValue.Data);
            string bitEnc = BitConverter.ToString(currValue.Data);
            string streamR;
            using (MemoryStream stream = new MemoryStream(currValue.Data))
            {
                using (StreamReader streamReader = new StreamReader(stream))
                {
                    streamR = streamReader.ReadToEnd();
                }
            }

            bdb.Close();
        }```

All of the above give me strange characters for the Data and also for the Key.
Am I missing the correct encoding?
Can any one help?
</code></pre>

<wallet.dat><c#>
Read Wallet addresses with C# and Berkeley
John Lopez
# Read Wallet addresses with C# and Berkeley

(Asked by: username_0 on 2021-11-16)

I have searched all threads, but still couldn't find an answer.
I am trying to read from a wallet that is not encrypted, but I am not able to proceed on retrieving the address values, they are byte[] but I can't convert them to the respective addresses.

```
        {
            BTreeDatabase bdb = OpenBTDB(srcWalletFileName);
            Cursor c1 = bdb.Cursor();
            var currValue = c1.First().Value;

            string NoEnc = currValue.ToString();
            string defaultEnc = Encoding.Default.GetString(currValue.Data);
            string utf8Enc = Encoding.UTF8.GetString(currValue.Data);
            string asciiEnc = Encoding.ASCII.GetString(currValue.Data);
            string utf16Enc = Encoding.BigEndianUnicode.GetString(currValue.Data);
            string utf32Enc = Encoding.UTF32.GetString(currValue.Data);
            string utf7Enc = Encoding.UTF7.GetString(currValue.Data);
            string isoEnc = Encoding.GetEncoding("ISO-8859-1").GetString(currValue.Data);
            string b64Enc = Convert.ToBase64String(currValue.Data);
            string bitEnc = BitConverter.ToString(currValue.Data);
            string streamR;
            using (MemoryStream stream = new MemoryStream(currValue.Data))
            {
                using (StreamReader streamReader = new StreamReader(stream))
                {
                    streamR = streamReader.ReadToEnd();
                }
            }

            bdb.Close();
        }```

All of the above give me strange characters for the Data and also for the Key.
Am I missing the correct encoding?
Can any one help?

```

**Tags:** wallet.dat, c#


---

## 1 answers

### Answer by username_1 on 2021-11-16. Score: 1

A wallet.dat file contains much more than just addresses. In fact, it mostly does not contain addresses at all. There will be some addresses because they are added to the address book, but the wallet mostly deals with keys, with addresses being computed from the keys as needed.

There are also two wallet types - legacy wallets and descriptor wallets. Legacy wallets will store keys explicitly, while descriptor wallets generally do not. But descriptor wallets also use SQLite rather than BDB, so you are dealing with a legacy wallet.

For both types of wallet, each record in the wallet database will begin with a length prefixed string indicating what kind of data is stored there. If you want addresses from the address book, the string will be `name`. This will then be followed by a length prefixed string for the address. The value of the record will be a length prefix string for the label to apply to that address. It may be empty (0 length).

To get all of the addresses for a legacy wallet, you will need to find all of the keys and compute addresses for each key. Keys are stored in `key` records. The public key follows the string `key`, and the private key will be the value of the record serialized using DER. See section C.4 of the [secp paper](https://www.secg.org/sec1-v2.pdf) for details on that.

For descriptor wallets, you can get the descriptor record and derive addresses from there. Individual keys and addresses are not stored for descriptor wallets.


---

