<p>Piuk has just made a patch to MultiBit that enables blockchain.info 'json' and 'aes.json' files to be imported. </p>

<p>This patch was included in MultiBit 0.3.4. 
Here is the how-to:</p>

<p>Export wallet from blockchain.info -> Import to MultiBit</p>

<p>1) Do a wallet export from blockchain.info</p>

<p>2) Import into MultiBit using the 'Import private keys' screen.</p>

<p>2.1) In the file chooser you choose the blockchain.info file suffix of ".json" or ".aes.json".</p>

<p>2.2) Choose the blockchain.info export file you want to import.</p>

<p>2.3) Add in either the single password or both passwords if it is double encrypted.</p>

<p>2.4) Press "Import private keys".</p>

<p>Because there are no private key creation dates in the blockchain.info exports I unfortunately have to replay the blocks from the genesis block (this takes a couple of hours) so it is more a "get out of jail" option than something you would use day to day.</p>

CC BY-SA 3.0
2012-04-20T23:19:53.707Z
2012-04-26T17:35:16.363Z
2012-04-26T17:35:16.363Z
jim618
<p>I took the code <a href="https://blockchain.info/DecryptWallet.html" rel="nofollow">from Blockchain.info</a> and converted it into a <a href="https://gist.github.com/ripper234/5016653" rel="nofollow">standalone javascript file</a> that you can run with node.js.</p>

<p>There were some issues as the original code didn't handle wrong passwords, and my code now has a single function <code>check_password(encrypted_json, password)</code> that returns true if it can decrypt it, and false if not.</p>

<p>Now, my goal is to take the above and use it to recover a friend's password. I'll generate a list of all combinations he might have chosen, and test it with this script.</p>

CC BY-SA 3.0
2013-02-22T21:26:03.493Z
2013-02-22T21:26:03.493Z
ripper234
<p>Here's another wrapper also done in node.js, similar to the response above by ripper234.  This one works with stdin so you can use an external tool to pass in values: <a href="https://github.com/salibhai1/bitcoin-bruteforce-decrypt" rel="nofollow">https://github.com/salibhai1/bitcoin-bruteforce-decrypt</a></p>

CC BY-SA 3.0
2016-04-09T18:23:29.667Z
2016-04-09T18:23:29.667Z
Sameer Alibhai
<p>I wrote a small Python script which can be used to decrypt your encrypted MyWallet.  It does the same as the <a href="https://blockchain.info/DecryptWallet.html">MyWallet JavaScript</a>, only in Python.</p>

<p>Edit: the code below seems to be outdated, here's a <a href="https://gist.github.com/2757171">working version</a> as of May 2012.</p>

<p>Copy the following into a file, make it executable, then run it:</p>

<pre><code>#!/usr/bin/env python
import base64, hashlib, hmac, json, sys, getpass
from Crypto.Cipher import AES
from Crypto.Hash import RIPEMD, SHA256

base58_chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'

def prompt(p):
    return getpass.getpass(p + ": ")

def decrypt(encrypted, password):
    encrypted = base64.b64decode(encrypted)
    iv, encrypted = encrypted[:16], encrypted[16:]
    length = len(encrypted)
    encrypted += ' ' * (15 - (length-1)%16)
    hash = (hmac.new(password, iv + "\x00\x00\x00\x01", hashlib.sha1).digest() +
            hmac.new(password, iv + "\x00\x00\x00\x02", hashlib.sha1).digest())[:32]
    clear = AES.new(hash, AES.MODE_OFB, iv).decrypt(encrypted)[:length]
    return clear

def base58_decode(v):
  value = 0; ret = ''
  for c in v: value = value*58 + base58_chars.find(c)
  for i in range(32):
      ret = "%c"%(value%256) + ret; value /= 256
  return ret

def base58_encode(v):
    value = 0; ret = ''
    for c in v: value = value*256 + ord(c)
    while value &gt; 0:
        ret = base58_chars[value%58] + ret; value /= 58
    return ret

def to_sipa(s):
    version = 128 # or 239 for testnet
    key = chr(version) + base58_decode(s)
    return base58_encode(key + SHA256.new(SHA256.new(key).digest()).digest()[:4])

clear = decrypt(prompt("encrypted wallet"), prompt("password"))
obj = json.loads(clear)

if (obj.has_key('double_encryption')):
    print("wallet uses double encryption")
    password = obj['sharedKey'].encode('ascii') + prompt("2nd password")
    for key in obj['keys']: key['priv'] = decrypt(key['priv'], password)
for key in obj['keys']: key['priv_sipa'] = to_sipa(key['priv'])
print(json.dumps(obj, indent=4, sort_keys = True))
</code></pre>

<p>It will prompt for the wallet backup and one or two passwords, depending on whether the wallet is single or double encrypted.  Paste the wallet backup in rather than saving it to a file.</p>

<p>You'll probably need Python 2.x.  I've been unable to find a package of the pycrypto stuff for Python 3.  Apparently it will be available in the upcoming <a href="http://packages.ubuntu.com/precise/python3-crypto">'precise' Ubuntu release</a>.</p>

<p>Edit: It seems the backup format has been changed and so this script doesn't work on recent backups.</p>

CC BY-SA 3.0
2012-02-29T19:07:32.957Z
Note that my script doesn't convert the private key into 'sipa' format, which is what the official bitcoin client will need (v0.6 onwards) to import a private key.  The private keys in the decrypted wallet are in base58 format, but not the 'sipa' format, which includes a checksum.  I intend to fix my script to convert private keys to 'sipa' format.
Chris Moore
CC BY-SA 3.0
2012-02-29T20:11:24.913Z
Now it shows the key in 'sipa' format too.
Chris Moore
CC BY-SA 3.0
2012-03-27T11:05:15.780Z
Both valid answers now, accepting this one both for the effort and because of python.
o0'.
CC BY-SA 3.0
2012-04-30T14:05:34.503Z
I added wallet input from file, and I took the liberty to create a project on bitbucket for that: https://bitbucket.org/lohoris/mywallet-restore
o0'.
CC BY-SA 3.0
2012-04-30T15:55:57.573Z
What, code development in stackexchange comments not good enough for ya?  ;)

Nice work.
Chris Moore
CC BY-SA 3.0
2012-05-09T06:21:17.913Z
When I try this on my backed up wallet, I get "ValueError: No JSON object could be decoded". I'm new to working with this crypto library, how would you suggest I go about trouble shooting?
Andrey Fedorov
CC BY-SA 3.0
2012-05-10T09:07:06.617Z
I get the same now.  It looks like the backup format has changed.  A quick glance at the source of https://blockchain.info/DecryptWallet.html shows that it now tries 4 different encryption modes, each with 0 through 19 iterations of AES encryption, which I don't think it used to do.
Chris Moore
CC BY-SA 3.0
2012-05-20T07:15:10.397Z
That code is crap. The mode currently used is CBC. The way he's passing in iterations is also confusing (and not in the original ezcrypto code AFAICT), as that option actually specifies the number of rounds run on PBKDF2 when deriving a key from the password (and it's 10 rounds, always).

Here's a working version for the latest format: https://gist.github.com/2757146
Andrey Fedorov
CC BY-SA 3.0
2012-05-20T15:33:52.353Z
@AndreyFedorov "The Gist you were looking for has been deleted. Sorry about that!"
Chris Moore
CC BY-SA 3.0
2012-05-20T21:04:24.017Z
So https://gist.github.com/2757171 is the fixed version.
Chris Moore
CC BY-SA 3.0
2012-06-22T00:27:03.230Z
Yup, sorry 'bout that.
Andrey Fedorov
CC BY-SA 3.0
2013-02-19T12:55:44.447Z
How can I easily verify the result of decrypt() is correct?

A friend of mine lost his wallet password, I would like to iterate on a lots of potential passwords he might have chosen until I find the right one.
ripper234
CC BY-SA 3.0
2013-02-22T16:12:37.497Z
It seems the python script requires `Crypto:Cypher`, as a python noob it's a bit difficult to install it on Windows. I'm working at it, just a fair warning to newcomers.
ripper234
CC BY-SA 3.0
2012-02-29T10:04:09.807Z
2012-05-20T18:00:53.150Z
2012-05-20T18:00:53.150Z
Chris Moore
<p>The website blockchain.info has an online wallet system <a href="http://blockchain.info/wallet">MyWallet</a> which creates backups with a .aes.json extension. While I understand it's a json file encrypted with AES using my passphrase, I'm still confused about what am I supposed to do to decrypt it and load it into a local client.</p>

<p>I have OSX 10.6, but for portability sake let's just talk about command line, hoping at least that one stays the same on multiple platforms.</p>

<wallet><backup><blockchain.info><wallet-recovery>
How to restore locally a MyWallet backup?
o0'.
# How to restore locally a MyWallet backup?

(Asked by: username_0 on 2012-02-28)

The website blockchain.info has an online wallet system [MyWallet](http://blockchain.info/wallet) which creates backups with a .aes.json extension. While I understand it's a json file encrypted with AES using my passphrase, I'm still confused about what am I supposed to do to decrypt it and load it into a local client.

I have OSX 10.6, but for portability sake let's just talk about command line, hoping at least that one stays the same on multiple platforms.

**Tags:** wallet, backup, blockchain.info, wallet-recovery


---

## 4 answers

### Answer by username_4 on 2012-02-29. Score: 7 | Accepted answer

I wrote a small Python script which can be used to decrypt your encrypted MyWallet.  It does the same as the MyWallet JavaScript, only in Python.
Edit: the code below seems to be outdated, here's a working version as of May 2012.
Copy the following into a file, make it executable, then run it:
#!/usr/bin/env python
import base64, hashlib, hmac, json, sys, getpass
from Crypto.Cipher import AES
from Crypto.Hash import RIPEMD, SHA256

base58_chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'

def prompt(p):
    return getpass.getpass(p + ": ")

def decrypt(encrypted, password):
    encrypted = base64.b64decode(encrypted)
    iv, encrypted = encrypted[:16], encrypted[16:]
    length = len(encrypted)
    encrypted += ' ' * (15 - (length-1)%16)
    hash = (hmac.new(password, iv + "\x00\x00\x00\x01", hashlib.sha1).digest() +
            hmac.new(password, iv + "\x00\x00\x00\x02", hashlib.sha1).digest())[:32]
    clear = AES.new(hash, AES.MODE_OFB, iv).decrypt(encrypted)[:length]
    return clear

def base58_decode(v):
  value = 0; ret = ''
  for c in v: value = value*58 + base58_chars.find(c)
  for i in range(32):
      ret = "%c"%(value%256) + ret; value /= 256
  return ret

def base58_encode(v):
    value = 0; ret = ''
    for c in v: value = value*256 + ord(c)
    while value > 0:
        ret = base58_chars[value%58] + ret; value /= 58
    return ret

def to_sipa(s):
    version = 128 # or 239 for testnet
    key = chr(version) + base58_decode(s)
    return base58_encode(key + SHA256.new(SHA256.new(key).digest()).digest()[:4])

clear = decrypt(prompt("encrypted wallet"), prompt("password"))
obj = json.loads(clear)

if (obj.has_key('double_encryption')):
    print("wallet uses double encryption")
    password = obj['sharedKey'].encode('ascii') + prompt("2nd password")
    for key in obj['keys']: key['priv'] = decrypt(key['priv'], password)
for key in obj['keys']: key['priv_sipa'] = to_sipa(key['priv'])
print(json.dumps(obj, indent=4, sort_keys = True))

It will prompt for the wallet backup and one or two passwords, depending on whether the wallet is single or double encrypted.  Paste the wallet backup in rather than saving it to a file.
You'll probably need Python 2.x.  I've been unable to find a package of the pycrypto stuff for Python 3.  Apparently it will be available in the upcoming 'precise' Ubuntu release.
Edit: It seems the backup format has been changed and so this script doesn't work on recent backups.

> **Comments:**
> **username_4**: Note that my script doesn't convert the private key into 'sipa' format, which is what the official bitcoin client will need (v0.6 onwards) to import a private key.  The private keys in the decrypted wallet are in base58 format, but not the 'sipa' format, which includes a checksum.  I intend to fix my script to convert private keys to 'sipa' format.  
> **username_4**: Now it shows the key in 'sipa' format too.  
> **username_0**: Both valid answers now, accepting this one both for the effort and because of python.  
> **username_0**: I added wallet input from file, and I took the liberty to create a project on bitbucket for that: https://bitbucket.org/lohoris/mywallet-restore  
> **username_4**: What, code development in stackexchange comments not good enough for ya?  ;)  Nice work.  
> **username_5**: When I try this on my backed up wallet, I get "ValueError: No JSON object could be decoded". I'm new to working with this crypto library, how would you suggest I go about trouble shooting?  
> **username_4**: I get the same now.  It looks like the backup format has changed.  A quick glance at the source of https://blockchain.info/DecryptWallet.html shows that it now tries 4 different encryption modes, each with 0 through 19 iterations of AES encryption, which I don't think it used to do.  
> **username_5**: That code is crap. The mode currently used is CBC. The way he's passing in iterations is also confusing (and not in the original ezcrypto code AFAICT), as that option actually specifies the number of rounds run on PBKDF2 when deriving a key from the password (and it's 10 rounds, always).  Here's a working version for the latest format: https://gist.github.com/2757146  
> **username_4**: @AndreyFedorov "The Gist you were looking for has been deleted. Sorry about that!"  
> **username_4**: So https://gist.github.com/2757171 is the fixed version.  
> **username_5**: Yup, sorry 'bout that.  
> **username_2**: How can I easily verify the result of decrypt() is correct?  A friend of mine lost his wallet password, I would like to iterate on a lots of potential passwords he might have chosen until I find the right one.  
> **username_2**: It seems the python script requires `Crypto:Cypher`, as a python noob it's a bit difficult to install it on Windows. I'm working at it, just a fair warning to newcomers.  

---

### Answer by username_1 on 2012-04-20. Score: 3

Piuk has just made a patch to MultiBit that enables blockchain.info 'json' and 'aes.json' files to be imported.

This patch was included in MultiBit 0.3.4.
Here is the how-to:

Export wallet from blockchain.info -> Import to MultiBit

1) Do a wallet export from blockchain.info

2) Import into MultiBit using the 'Import private keys' screen.

2.1) In the file chooser you choose the blockchain.info file suffix of ".json" or ".aes.json".

2.2) Choose the blockchain.info export file you want to import.

2.3) Add in either the single password or both passwords if it is double encrypted.

2.4) Press "Import private keys".

Because there are no private key creation dates in the blockchain.info exports I unfortunately have to replay the blocks from the genesis block (this takes a couple of hours) so it is more a "get out of jail" option than something you would use day to day.


---

### Answer by username_2 on 2013-02-22. Score: 2

I took the code [from Blockchain.info](https://blockchain.info/DecryptWallet.html) and converted it into a [standalone javascript file](https://gist.github.com/username_2/5016653) that you can run with node.js.

There were some issues as the original code didn't handle wrong passwords, and my code now has a single function `check_password(encrypted_json, password)` that returns true if it can decrypt it, and false if not.

Now, my goal is to take the above and use it to recover a friend's password. I'll generate a list of all combinations he might have chosen, and test it with this script.


---

### Answer by username_3 on 2016-04-09. Score: 0

Here's another wrapper also done in node.js, similar to the response above by username_2. This one works with stdin so you can use an external tool to pass in values: <https://github.com/salibhai1/bitcoin-bruteforce-decrypt>


---

