Skip to content

Instantly share code, notes, and snippets.

@ymgve
Created November 22, 2020 03:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ymgve/f66fb29f32380f79e68bbed997bac60f to your computer and use it in GitHub Desktop.
Save ymgve/f66fb29f32380f79e68bbed997bac60f to your computer and use it in GitHub Desktop.
import hashlib, json, os, sys
# requires packages requests and pycryptodome
# run with
# python blockchaincom_decrypt.py [GUID] password
import requests
from Crypto.Cipher import AES
guid = sys.argv[1]
password = sys.argv[2]
cachename = guid + ".json"
if not os.path.isfile(cachename):
res = requests.get("https://blockchain.info/wallet/%s?api_code=1770d5d9-bcea-4d28-ad21-6cbd5be018a8&format=json" % guid)
res.raise_for_status()
open(cachename, "wb").write(res.content)
content = open(cachename, "rb").read()
j = json.loads(content)
j = json.loads(j["payload"])
if j["version"] != 3:
raise Exception("Unsupported version %d" % j["version"])
pbkdf2_iterations = j["pbkdf2_iterations"]
payload = j["payload"].decode("base64")
key = hashlib.pbkdf2_hmac("sha1", password, payload[0:16], iterations=pbkdf2_iterations, dklen=256 / 8)
res = AES.new(key, AES.MODE_CBC, payload[0:16]).decrypt(payload[16:])
pad = ord(res[-1])
res = res[:-pad]
j = json.loads(res)
print json.dumps(j, indent=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment