9

A while back, I installed the Bitcoin Android app and moved 5 BTC on it. Fast forward to now, new phone, new ROM, and the app seems completely unwilling to update its blockchain, meaning I have no way to move my BTCs elsewhere.

Looking at the source, it's built on an early version of BitcoinJ, where the wallet file is essentially a serialized Wallet class.

A look at the wallet file itself isn't too friendly, although I'm sure the private key is somewhere in there in a relatively straightforward form.

So, that leaves me with the following possibilities:

  • write a little Java app that links against the same version of BitcoinJ, load the Wallet file, grab the private key and print it.

  • write a really dumb script that extracts every 32 bytes sequence from the wallet file, treat it as a private key, map it to a public key, check blockexplorer.com for any activity associated with it. Or just import every one of those sequences into a bitcoin client and let it suffer.

Before I embark on my Quest For Five Bitcoins, is there already something out there that can parse BitcoinJ wallet files and export keys from them?

  • (1) updating the blockchain is not a prerequisite for being able to send away the coins already there, (2) it's slightly unclear what you did: you backupped that application and its data, and re-installed it in the new phone? – o0'. Mar 21 '12 at 10:08
  • Many clients will not send transactions unless the client knows it has the requisite amount of coins; I suspect that is the case here. – BinaryMage Mar 21 '12 at 17:54
  • @Lohoris I didn't realize that. Both coin sending and blockchain updating are failing, and I drew a causation link where none existed, both likely failing instead due to a third factor. – Metal Mar 23 '12 at 21:39
  • Note that the link to this app (in the question above) is broken. If someone could fix it, that would be great. – Highly Irregular Feb 12 '13 at 1:07
2

I wrote up a detailed answer to this some ago. Essentially, you will need to root your phone and extract the wallet file with apd.

After you've got that you can decode it by looking within the serialized wallet with a Java debugger attached looking for an ECKey reference. Then, once you have the private key you can simply hand it over to MtGox who will do the decode for you and then you can transfer the bitcoins wherever you like.

Also, the BitCoinJ project contains several useful example tools in the source tree. Perhaps using one of those will help you with the deserialization.

  • 2
    WARNING: rooting the phone without using exploits wipes its memory. So, unless he's running an already rooted phone, or an exploitable android version, he can't do that. – o0'. Mar 21 '12 at 10:05
  • @Lohoris Quite so. However, the OP does seem to indicate that the phone is an older ROM, possibly running 2.1, 2.2 which are exploitable. The linked article does provide a tested rooting approach that did not erase the internal memory. – Gary Rowe Mar 21 '12 at 10:37
  • 2
    Thanks, this is probably the closest we are to a ready-made recovery solution. (my phones are rooted, so getting/backing up the wallet is not an issue.) – Metal Mar 23 '12 at 21:17
  • 1
    DumpWallet did the trick. I just had to remove "00" from my priv: key field to get Mt.Gox to like my private key. Thanks again! – Metal Mar 24 '12 at 0:31
  • @Metal No worries - glad to have helped – Gary Rowe Mar 24 '12 at 18:29
4

I would try option 1 first, if you can find the right version of the library. I'd be willing to try making a general purpose tool to do it, but don't have an Android phone. Is there any way you can make a new, empty wallet and put a copy online somewhere along with a corresponding bitcoin address or two?

If you're attempting option 2, you probably know at least one of the addresses in the wallet, and so wouldn't need to hit blockexplorer for every guess. You would expect the private keys to be evenly spread through the wallet, so once you've found a few you can make smarter guesses about where the rest are.

  • Yes.. option 1 is the least crazy of the 2. At this point, I've probably spent more time hoping something already exists than I would have spent doing it myself, so I guess I'll just stop being lazy. :) – Metal Mar 23 '12 at 22:00
4

[Obsolete answer, see below]

As an update: current versions of the Bitcoin app have a "Back up Keys" feature. This writes a backup of all the keys in the wallet to a file named bitcoin-wallet-keys-YYYY-MM-DD (using the current date) in the phone's storage, which you can then copy or transfer wherever you want. The file is encrypted with a password you supply; it can be decrypted manually using OpenSSL, by running

openssl enc -d -aes-256-cbc -a -in bitcoin-wallet-keys-YYYY-MM-DD

After decryption, the file is just a list of private keys, one per line, in the standard base 58 compressed format (starting with K). You can import those keys into some other wallet. In bitcoin-qt, you'd use the importprivkey console command.

Further Update: As of Bitcoin Wallet 3.53, the "Back Up Keys" feature described above apparently no longer exists.

  • 1
    This worked great for me with some oldish Litecoin and Dogecoin wallets backed up from Android. The Bitcoin backup created around the same time does decrypt (output starts with a 0x0A 0x16 header followed by a plaintext org.bitcoin.production) but the remainder is binary. – Lloeki Apr 5 '16 at 9:56
  • Also, in Bitcoin Wallet 4.49, backup is done via Safety menu entry. – Lloeki Apr 5 '16 at 9:57
  • what openssl outputs now is in protobuff format. See bitcoin.stackexchange.com/questions/29518/… – Ovidiu Buligan Aug 11 '17 at 15:32
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.