Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: Crypto_FM91 on March 05, 2019, 12:18:51 PM



Title: How to decode an encrypted WIF key ?
Post by: Crypto_FM91 on March 05, 2019, 12:18:51 PM
H,

Please can you tell me how to get "Private key (WIF key)" from an "AES-256 Encrypted WIF key" ?
I have created a BTG adress on coinb.in, I have the AES-256 Encrypted WIF key and my password but I do not know how to decode it.

Thank you.


Title: Re: How to decode an encrypted WIF key ?
Post by: mocacinno on March 05, 2019, 12:26:37 PM
I don't really have time for a complete explanation (late for a meeting), but if you download the sourcecode of https://www.bitaddress.org/ from github, disconnect your pc from the internet, open the main page, go to wallet details and enter WIF + pass, you should get all other formats as output


Title: Re: How to decode an encrypted WIF key ?
Post by: nc50lc on March 05, 2019, 12:48:06 PM
Let me add the details:

  • 1. Go to bitaddress' Github page: https://github.com/pointbiz/bitaddress.org (https://github.com/pointbiz/bitaddress.org) and download the source (zip).
  • 2. Turn off your internet connection, Extract and open it (drag&drop bitaddress.org.html) to your browser.
  • 3. Move your mouse until the 1st address reach 100%, then click "Wallet Details".
  • 4. Check "BIP38 Encrypt?", enter your encrypted key and passphrase, hit "Encrypt BIP38" (sometimes, it changes to "Decrypt" after clicking).
  • 5. After loading, your WIF private key should show up.

Image: (Random key from the internet: please don't import)
https://i.imgur.com/YY6vFZZ.jpg


Title: Re: How to decode an encrypted WIF key ?
Post by: Crypto_FM91 on March 05, 2019, 07:42:38 PM
Hi,
Many thanks for your help. I tryed both but my encrypted WIF key is not recognised. I got the message bellow
" The text you entered is not a valid Private Key! Would you like to use the entered text as a passphrase and create a Private Key using a SHA256 hash of the passphrase?"

The encrypted WIF key I am talking about is for Bitcoin Gold. It has 108 characters.

Here is an example of an encrypted wif key and it's corresponding wif key and password that i have generated here (https://coinb.in/#newAddress) for testing purpose
WIF key : "KyYEjVKDcbUrgfrpdpzaZBm1szWbzTmrBvxsQzDWgCAAZnd6uw8S"
AES-256 Encrypted WIF key : "U2FsdGVkX187FiUTQ0lMNeO5AkYQS9xU874h0g4AWch3ZfLuKEiUndejRQ0uRGw03sY5tOlTiVyiLf4 oax+6IGF7hJUAjOMEomCGOxd8jvg="
Password : "123"


Title: Re: How to decode an encrypted WIF key ?
Post by: BitMaxz on March 05, 2019, 09:19:39 PM
I think you need OpenSSL for this to decrypt your AES-256 Encrypted WIF key.

Anyway, Let me test if I can decrypt your encrypted WIF key.

Edit:
It seems OpenSSL doesn't work to me or there is something wrong with my command.

I used this command

Code:
enc -d -aes-256-cbc -p -md md5 -a -in plain1.txt -out plaind1.txt
The encrypted wif key I just paste it inside the plain1.txt

But the result is an "error reading input file".

I think we need to know if what cipher type that coinb.in used?


Title: Re: How to decode an encrypted WIF key ?
Post by: Abdussamad on March 05, 2019, 10:25:34 PM
Edit: Actually you can use your browser's developer tools to decrypt the priv key. For example on firefox ctrl+shift+k should bring up the js console. There you can decrypt the priv key with the following code:

Code:
var mencrypted = "enter encrypted priv key here";
var mpassword = "enter password here";
var decrypted = CryptoJS.AES.decrypt(mencrypted, mpassword);
alert(decrypted.toString(CryptoJS.enc.Utf8));

Source (https://code.google.com/archive/p/crypto-js/)


Title: Re: How to decode an encrypted WIF key ?
Post by: BitMaxz on March 05, 2019, 11:15:22 PM
Edit: Actually you can use your browser's developer tools to decrypt the priv key. For example on firefox ctrl+shift+k should bring up the js console. There you can decrypt the priv key with the following code:

Code:
var mencrypted = "enter encrypted priv key here";
var mpassword = "enter password here";
var decrypted = CryptoJS.AES.decrypt(mencrypted, mpassword);
alert(decrypted.toString(CryptoJS.enc.Utf8));

Source (https://code.google.com/archive/p/crypto-js/)
I tried as your suggestion it doesn't work in firefox it always shows "ReferenceError: CryptoJS is not defined"

Look at the reference below.
https://i.imgur.com/Bc1dyNF.png


Title: Re: How to decode an encrypted WIF key ?
Post by: HCP on March 05, 2019, 11:29:26 PM
Edit: Actually you can use your browser's developer tools to decrypt the priv key.
Took some messing around to make this work on Chrome (Press F12 to get console)... It doesn't seem to have the CryptoJS stuff auto imported? ???

I had to first of all copy/paste this code snippet into the console to get access to the CryptoJS library... the source code for which is no longer available on code.google.com :-\ So, I'm using some random link I found while googling for it :P
Code:
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/aes.js';
document.head.appendChild(script);

Then, I could copy/paste the following code into the console and it would pop up the alert showing the private key.
Code:
var mencrypted = "enter encrypted priv key here";
var mpassword = "enter password here";
var decrypted = CryptoJS.AES.decrypt(mencrypted, mpassword);
alert(decrypted.toString(CryptoJS.enc.Utf8));


If you try and copy/paste the whole lot in one go... it'll complain that CryptoJS doesn't exist:
Quote
Uncaught ReferenceError: CryptoJS is not defined
    at <anonymous>:8:17
But, if you just copy/paste it again, it'll work...


What is interesting, is that I attempted to use the OPs example:
Code:
Here is an example of an encrypted wif key and it's corresponding wif key and password that i have generated here (https://coinb.in/#newAddress) for testing purpose
WIF key : "KyYEjVKDcbUrgfrpdpzaZBm1szWbzTmrBvxsQzDWgCAAZnd6uw8S"
AES-256 Encrypted WIF key : "U2FsdGVkX187FiUTQ0lMNeO5AkYQS9xU874h0g4AWch3ZfLuKEiUndejRQ0uRGw03sY5tOlTiVyiLf4oax+6IGF7hJUAjOMEomCGOxd8jvg="
Password : "123"
And I just get a blank alert... but when I use a randomly generated one from coinb.in... it works!

Code:
WIF Key : "L3pLNp7KgZAT2LSuue4RPkum6XGCgeZFE2Dk37xPvxnN8TAEtQX1"
AES-256 Encrypted WIF key : "U2FsdGVkX1/fN3CAnYeGfVPhdq8G/MM+u8U4K7nR1xm3iHwXQwOojQmzyF3Zp/e4N5l8T+iNFSw8OGxC5P67+Jil8HR/Tb64QJfX0qUDxSg="
Password : "123"

I'm guessing the OPs example is broken? bad AES encrypted key or bad password? ???




EDIT:

I tried as your suggestion it doesn't work in firefox it always shows "ReferenceError: CryptoJS is not defined"
I was getting the same... I think maybe Abdussamad already had the CryptoJS stuff loaded (browser extension maybe?)... try running my little code snippet to load the aes.js script and see if that helps! ;)


Title: Re: How to decode an encrypted WIF key ?
Post by: pooya87 on March 06, 2019, 05:01:40 AM
I tried as your suggestion it doesn't work in firefox it always shows "ReferenceError: CryptoJS is not defined"
I was getting the same... I think maybe Abdussamad already had the CryptoJS stuff loaded (browser extension maybe?)... try running my little code snippet to load the aes.js script and see if that helps! ;)

open https://coinb.in/ website first and then bring up the browser's inspect window (developers tool or whatever else it is called in other browsers) and then type those commands in. when you open the site, CryptoJS is already loaded that way you don't have to go through the trouble of manually loading anything.


Title: Re: How to decode an encrypted WIF key ?
Post by: BitMaxz on March 06, 2019, 05:05:22 PM
Both of them works @HCP method you just need to use this code first .

Code:
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/aes.js';
document.head.appendChild(script);

Before we insert Abdussamad code.

And now it works fine it shows the wif key on the screen.

For the pooya87 suggestion, it also works.

Just we need to send the Abdussamad code while you are in coinb.in website page.

What I did lately is I just send the code from Abdussamad to a new tab that is why I see bad result "ReferenceError: CryptoJS is not defined"


Title: Re: How to decode an encrypted WIF key ?
Post by: Abdussamad on March 06, 2019, 05:07:45 PM
Yeah sorry I didn't mention that the site had to be loaded first. Kinda forgot :P


Title: Re: How to decode an encrypted WIF key ?
Post by: Crypto_FM91 on March 06, 2019, 06:08:43 PM
Hi,

THANK YOU VERY MUCH, IT WORKS !!! I have successfully unlocked my BTG's .