Skip to content

Instantly share code, notes, and snippets.

@johansten

johansten/crypto.js Secret

Created Apr 16, 2018
Embed
What would you like to do?
download all of the files into the same folder
change the contents of main.js:
replace the encrypted seed with yours
replace the password
run
> npm install
and then
> node main.js
const sjcl = require('sjcl');
const encryptSeed = (seed, key, cipherName, modeName) => {
const cipher = new sjcl.cipher[cipherName](key);
const rawIV = sjcl.random.randomWords(3);
const encryptedData = sjcl.mode[modeName].encrypt(
cipher,
sjcl.codec.utf8String.toBits(seed),
rawIV
);
return [
sjcl.codec.base64.fromBits(rawIV),
sjcl.codec.base64.fromBits(encryptedData)
];
};
const encrypt = (seed, password) => {
const saltBits = sjcl.random.randomWords(4); // 128 bits of salt, was 256 bits
const numRounds = 4096;
const key = sjcl.misc.pbkdf2(password, saltBits, numRounds);
const salt = sjcl.codec.base64.fromBits(saltBits);
const cipherName = 'aes';
const modeName = 'gcm';
const blob = encryptSeed(seed, key, cipherName, modeName);
return ['1', salt, blob];
};
const decryptSeed = (blob, key) => {
const cipherName = 'aes';
const modeName = 'gcm';
const cipher = new sjcl.cipher[cipherName](key);
const rawIV = sjcl.codec.base64.toBits(blob[0]);
const rawCipherText = sjcl.codec.base64.toBits(blob[1]);
const decryptedData = sjcl.mode[modeName].decrypt(
cipher,
rawCipherText,
rawIV
);
return sjcl.codec.utf8String.fromBits(decryptedData);
};
const decrypt = (data, password) => {
const saltBits = sjcl.codec.base64.toBits(data[1]);
const numRounds = 4096;
const key = sjcl.misc.pbkdf2(password, saltBits, numRounds);
return decryptSeed(data[2], key);
};
module.exports = {
encrypt: encrypt,
decrypt: decrypt
};
const crypto = require('./crypto.js');
const encryptedSeed = ["1","ZCtl/+vWiLL358Jz+xnP5A==",["GgmFU37DSX4evSMU","CoMGXWHqDmLwxRAgORqjK/MyFEMAkMbqvDEDMjn4veVwpHab9m6Egcwp70qEJsRhjkHjCMWj9zX40tu9UK5QACuB8gD1r9Cu"]];
const password = 'lacoin';
const decryptedSeed = crypto.decrypt(encryptedSeed, password);
console.log(decryptedSeed);
{
"name": "lacoin",
"version": "1.0.0",
"description": "",
"main": "crypto.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"sjcl": "^1.0.7"
}
}
@rathfon

This comment has been minimized.

Copy link

@rathfon rathfon commented Apr 24, 2018

Thank you. This did work for me. Despite me getting my decrypted seed, it shows no balance. I must have backed up the incorrect QR code from StarGazer -_-

EDIT: Nevermind, I somehow overwrote my changes made to main.js with your ORIGINAL code. I was pulling your seed key. THANK YOU SIR, YOU'VE SAVED MY ASS. You're a god.

@Felsin

This comment has been minimized.

Copy link

@Felsin Felsin commented May 27, 2018

Thank you for creating this. I have everything installed correctly and I can get it to run with your key, but it does not work with my password and key.
This is the error I receive when run node main.js:

CORRUPT: gcm: tag doesn't match`

Any help is appreciated.! Thanks again.

UPDATE -
You are a gentleman and a scholar.
It worked and it helped me in my java learning process.

Thanks!

@rickbentley

This comment has been minimized.

Copy link

@rickbentley rickbentley commented May 12, 2020

You are THE MAN! Thanks so much for making this, just saved my old wallet!

Very nice of you to take the time to make this, really super great of you to take the effort to share it with everyone.

@saddybedangdang

This comment has been minimized.

Copy link

@saddybedangdang saddybedangdang commented Jan 29, 2021

Thanks, this ended up working for me!

@sorkantir

This comment has been minimized.

Copy link

@sorkantir sorkantir commented Feb 23, 2021

I just wanted to say many thanks. I first installed stargazer on my macbook pro in 03/2018 and came to my mind to restore yesterday. I only had the qr and the pass. Your script saved me! Anyway I can be of assistance?

@cylack

This comment has been minimized.

Copy link

@cylack cylack commented Feb 26, 2021

Hi,
I am not a programmer so I have no idea how to do this. Would someone be so kind to help me out? I created a password protected wallet using stargrazer app on my mac in 2017 and exported the qr code as a file. Now the app is not accepting the qr code when i try to scan it.

@cylack

This comment has been minimized.

Copy link

@cylack cylack commented Feb 27, 2021

Ok with the help of some people on the stellar sub on reddit (https://www.reddit.com/r/Stellar/comments/ltcbb5/gaining_access_to_stellar_wallet_created_on/) I was able to figure out how to do this on a Mac. I have written the step by step instructions so a complete novice could do it:

  1. Make a screen grab of your QR Code and save it
  2. Go to https://zxing.org/w/decode and upload the saved screengrab
  3. You will get a long string of letters and numbers after the word “key” that starts with 1 parenthesis and ends in two parentheses. Copy this. Here is an example of how the string should look like:

"key":["1","Dt/bcdLAx8TnEd4qF/7+sQ==",["jwFqX+meUt3ioxnG","6woh7nRS1CcEN6qiWEI+knY9VyYdMzqlGxpxX6ZfPfAPVg9wOTYevryOmyGC3ycQ2asgPYx1pIW4Fp9Jj4pDGkKGWuhoZKsW"]]

JUST COPY ONLY THE CHARACTERS FROM ["jwFqX to the ending ]] (this is your encrypted key)

  1. Download the Zip file located at https://gist.github.com/johansten/35f4767e2f1d4d108a4bb21ff8289ec7
  2. Extract the files located in the zip file. Rename this folder to lumens and move the folder to /Users/
  3. Open the file main.js using TextEdit
  4. Replace the string shown below with the string you copied in step 3. above:

["GgmFU37DSX4evSMU","CoMGXWHqDmLwxRAgORqjK/MyFEMAkMbqvDEDMjn4veVwpHab9m6Egcwp70qEJsRhjkHjCMWj9zX40tu9UK5QACuB8gD1r9Cu"]]

  1. Replace the password ‘lacoin’ with your password that you had used to encrypt your wallet. Keep the quotations intact and just replace lacoin with your password.
  2. Save the file and quit TextEdit
  3. Go to the website nodejs.org and download the 14.16.0 LTS package (or the latest if this version isn’t there). Install that .pkg file after it downloads
  4. Launch Terminal app
  5. Type “cd lumens” (without the quotations)
  6. Type npm install
  7. Type node main.js
  8. Terminal should now display your de-crypted private key which consists of 56 characters starting with the letter S
  9. Copy your private key to a document in your text editor of choice (TextEdit, MS Word, etc.) and keep it safe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment