0

This question already has an answer here:

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.

marked as duplicate by Ismael, Achala Dissanayake, Richard Horrocks, Eli Drion, flygoing May 1 '18 at 12:09

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.