Skip to content

Instantly share code, notes, and snippets.

@accerqueira
Last active December 3, 2022 07:13
Show Gist options
  • Save accerqueira/c4e1fd15791ef6f5b29543eb16e9d893 to your computer and use it in GitHub Desktop.
Save accerqueira/c4e1fd15791ef6f5b29543eb16e9d893 to your computer and use it in GitHub Desktop.
Export private keys from bitcoin-wallet (de.schildbach.wallet)
#!/usr/bin/env bash
WALLET=${1}
sudo apt-get install maven openjfx >/dev/null
WALLET_DEC=$(mktemp)
cleanup() {
err=$?
rm -f ${WALLET_DEC}
cd $(dirs -l -0) && dirs -c > /dev/null
trap '' EXIT INT TERM
exit $err
}
sig_cleanup() {
trap '' EXIT # some shells will call EXIT after the INT handler
false # sets $?
cleanup
}
trap cleanup EXIT
trap sig_cleanup INT QUIT TERM
openssl enc -d -aes-256-cbc -md md5 -a -in ${WALLET} > ${WALLET_DEC}
git clone --depth 1 -b v0.14.4 https://github.com/bitcoinj/bitcoinj.git >/dev/null 2>&1
pushd bitcoinj/tools > /dev/null
./wallet-tool dump --wallet ${WALLET_DEC} --dump-privkeys | grep -o -P '(?<=priv WIF=)\w*'
#!/usr/bin/env bash
CLI=${1:-bitcoin-cli}
while read -r KEY || [[ -n "${KEY}" ]]; do
${CLI} importprivkey '"'${KEY}'"' '""' 'false'
done
echo "Done!"
echo "Now you need to restart bitcoind -rescan"
@hsachdevah
Copy link

Bitcoin wallet dump is only giving me public keys and not the private key

@crmarques
Copy link

@accerqueira, it seems like tnat wallet backups generated with recent Bitcoin wallet' updates require an additional openssl parameter (-md md5) to decrypt the wallet:

openssl enc -d -aes-256-cbc -md md5 -a -in ${WALLET} > ${WALLET_DEC}

@accerqueira
Copy link
Author

Thanks, @crmarques!
@hsachdevah, does @crmarques fix works for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment