I would like to write a piece of code that takes input as UTC key store file and password, and returns decrypted Private Key. I am aware of options like "MyEtherWallet" but I would like to do using my code. Any help/resources that I can use is appreciated.
2
-
In particular this answer ethereum.stackexchange.com/a/36022 – Ismael Apr 29 '18 at 17:49
-
I guess this question is more about decrypting without depending on specific applications like geth or JS packages. If so, this actually is asking the underlying details of the linked answers. I have created a new answer which hopefully has more "hands-on" details ethereum.stackexchange.com/a/47135/20451 – Linmao Song Apr 30 '18 at 15:22
Add a comment
|
You can use the Javascript library ethereumjs-wallet which allows to load a wallet from a private key, seed phrase or UTC JSON file (V1 or V3)
I have generated a UTC JSON file on MyEtherWallet and the sample code below shows how to decrypt it to sign transactions:
const Wallet = require('ethereumjs-wallet'),
fs = require('fs');
const utcFile = "./UTC--2018-04-29T10-08-25.072Z--1f7c98090febf46155496a370002a10af7eb6766"
const password = "password123"
const myWallet = Wallet.fromV3(fs.readFileSync(utcFile).toString(), password, true);
console.log("Private Key: " + myWallet.getPrivateKey().toString('hex'))
console.log("Address: " + myWallet.getAddress().toString('hex'))
Output
$ node index.js
Private Key: 8ecb2c8c4fcf3986e5d3c249bac183b206f41a7a2d9a81e203ef6219be87421b
Address: 1f7c98090febf46155496a370002a10af7eb6766
I pushed some of the code here