8

Recent changes to Andreas Schildbach's Bitcoin client for Android have removed the option to export private keys. This has been replaced by an option to back up the entire wallet. Unfortunately, the wallet data of the Schildbach client is stored in an arcane format called protobuf (short presumably for Protocol Buffers). The Schildbach client can restore a protobuf wallet from its AES-encoded backup file. But the protobuf wallet cannot be imported into a different Bitcoin client such as the Bitcoin Core (QT) client.

For emphasis, I'm aware of the command line method of decoding the back-ups created by Schildbach's client, which in the past allowed the private keys to be saved in AES encrypted format to /sdcard/Download. The following command worked in the past to produce a human readable copy of my Bitcoin private keys:

openssl enc -d -aes-256-cbc -a -in encrypted-wallet-keys -out decrypted-wallet-keys

This no longer works. The following command instead produces a non-AES-encrypted protobuf wallet.

openssl enc -d -aes-256-cbc -a -in bitcoin-wallet-backup-2014-07-19 -out bitcoin-wallet-backup-2014-07-19-decrypted

The -out file is not an ASCII copy of my private keys but a copy of the protobuf wallet used internally by the Schildbach Bitcoin client (found at /data/data/de.schildbach.wallet/files/wallet-protobuf).

6

Since "when you're a developer it's easy" is probably not sufficient for most people, here is the full step-by-step from a Android Bitcoin Wallet to importing the private keys in Electrum which (finally...) worked for me. This solution uses bitcoinj. The approach using the .proto definition file and opening the wallet in Python was also tested, but seems more error-prone.

Requirements:

  • Android Bitcoin Wallet in a new version (to my knowledge, some older versions do not allow a backup).
  • Bash shell: tested with the Windows Bash, but should work on native Linux or OS X. Basic knowledge (cd etc.) helps.
  • On my system, maven and openjfx were required. Install them with sudo apt-get install maven, sudo apt-get install openjfx
  • Electrum (current: 2.9.2)

Step by step:

  1. Backup: save the encrypted wallet (Safety -> Back up wallet) and move the backup file to your computer (e.g. via file transfer, Dropbox, e-mail...).
  2. Decrypt: open the bash, move to your data directory and use openssl enc -d -aes-256-cbc -a -in bitcoin-wallet-backup > bitcoin_decrypted as stated above, which will ask for the encryption password.
  3. Install bitcoinj:
    • git clone https://github.com/bitcoinj/bitcoinj.git
    • cd bitcoinj
    • git fetch --all
    • git checkout v0.14.4
    • mvn install (fails at GroupTest in Windows bash, but works anyway)
    • cd tools
    • ./wallet-tool
  4. load the decrypted wallet and dump the private keys:

./wallet-tool dump --wallet=/mnt/d/path/to/wallet/bitcoin_decrypted --dump-privkeys > /mnt/d/path/to/wallet/bitcoin_decrypted_dump.

Please note that this saves the unencrypted private keys in the file "bitcoin_decrypted_dump". Move this file to a save location (e.g. TrueCrypt/VeraCrypt container) or delete it after use.

  1. Create a new wallet with the private keys in Electrum: File - New/Restore - filename - 'Standard wallet' - 'Use public or private keys', then list the 'priv WIF' keys from the dump file.

On handling the BTC/BCH question with Electrum and Electron Cash, please read the notes on the Electrum webpage.

If there are any questions, feel free to ask. Good luck!

Sources:

  • When installint bitcoinj, I get: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compile (default-compile) on project wallettemplate: Compilation failure: Compilation failure: [ERROR] ~/wallettemplate/src/main/java/wallettemplate/utils/easing/EasingInterpolator.java:[27,24] package javafx.animation does not exist And many similar errors after that (javax.something does not exist). Any ideas? – Sergei Tikhomirov Sep 14 '17 at 23:08
  • This helped. – Sergei Tikhomirov Sep 15 '17 at 12:55
  • My file bitcoin_decrypted_dump contained errors, see this pastebin what should I do now? I don't understand error messages but I can execute/understand terminal commands. – jacob Nov 5 '17 at 8:58
  • @jacob: the error message states that the Java Development Kit (jdk) is missing. You can install it with "sudo apt-get install openjdk-8-jre". Please confirm if this solves the problem, then I will update the instructions. – Colluphid Nov 6 '17 at 21:15
  • @Colluphid I got a guy to help me with this to install java and set PATH variable. However, the output file does not contain my private key. It's a large file and it looks like I can see the block that contain the transactions that I my wallet did. – jacob Nov 11 '17 at 12:30
2

I tried to dump private keys but i couldn't. Using wallet-tool, I obtain a text file with public keys, addresses, some other information, and the words: "Seed is encripted".

So I use this phyton script to obtain seed, and it apparentely worked.

Then I use this standalone page: https://raw.githubusercontent.com/iancoleman/bip39/master/bip39-standalone.html to obtain private keys to import in a BCH wallet.

I "found" only 85% of BCH that I expected (BTC pre fork). How could be possible ? I tried to import a lot of keys beyond the key associated to the last used address....


Update: I figured out. I had to use as derivative path m/0'/1 on the standalone page linked above (with derivation path BIP32). Some BTC were on addresses of this kind.

1

I don't know if you are a developer, because you could dump the private keys with very little effort. The app relies on bitcoinj and the protobuf format you mention is bitcoinj serialization format for the wallet. Export the wallet file to your desktop and write a simple Java app that uses bitcoinj to access the wallet, then use the DumpedKey class to output the private keys in the widely used WIF encoding.

1

Protocol Buffer is an open source serialization library from Google.

If you can code, it should not take you too long to create a script (for instance in Python) to get out the content of the field you are interested in. In this case the field containing the private key.

Here is the doc for the Python protocol buffer library: https://developers.google.com/protocol-buffers/docs/reference/python-generated

The protocol buffer library use a .proto file to describe the possible fields in the serialized format. I presume that you do not have access to it. This will have the disadvantage that you will not have the name of the fields when you will deserialize the wallet.

That should however not prevent you from deserializing. You will then need to guess which value is the private key.

1

To work with bitcoinj wallets (and backups of wallets) you can use wallet-tool. It's part of bitcoinj and allows you to dump all your deterministically derived private keys.

1

I had a load of trouble, but I got there in the end. I decided to write it up; see https://recoverbch.azurewebsites.net for an in-depth guide. Hope this helps!

0

Would any of you have an easier way to get at these keys from the protobuf format? I'm trying to help someone get these keys out of the app on their phone (to control their Bitcoin Cash) and we've made it this far in decrypting the backup wallet, but without having any programming knowledge we are stuck here.

  • I just posted an answer. I had the same problem. – Juan Leni Sep 27 '17 at 15:43
0

This script seems to do the work

https://github.com/jleni/wallet-decrypt

You just need to create a backup and it will give you back a mnemonic that you can use in electrum or electrum cash.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.