If I have the plaintext private key, -how- can I generate a geth-compatible keystore file using Node.js?

I think I need to encrypt it using the scrypt algorithm by supplying a password, but I don't know how to do this. Any -preferrably browserifiable- examples would be highly appreciated.


  • 3
    Simplest is to import the key to Geth otherwise see ethereum.stackexchange.com/questions/1825/…
    – eth
    Jan 6 '17 at 2:12
  • @eth Thanks! But I forgot to mention I want to do this in Node.js, without Geth. Updated the question accordingly.
    – jeff
    Jan 6 '17 at 2:47
  • I thought that was the case that's why I commented instead of answering :) Yes, it's a good idea to make questions more specific. From the anatomy link you have the Web3 Secret Storage Definition and that might be enough to keep you going for a bit. (I'd answer if I knew more.)
    – eth
    Jan 6 '17 at 2:57
  • 2
    There's a Python library for what you want to do, if it helps. Jan 6 '17 at 6:31
  • You could also do in the desktop version of MyCrypto.com Sep 30 '18 at 16:42

geth-compatible keystore file can be created in Node using ethereumjs-wallet library:

> var Wallet = require('ethereumjs-wallet');
> var key = Buffer.from('efca4cdd31923b50f4214af5d2ae10e7ac45a5019e9431cc195482d707485378', 'hex');
> var wallet = Wallet.fromPrivateKey(key);
> wallet.toV3String('password');

You can also specify additional options to control kdf, cipher and other wallet params. See here.

  • 4
    Nice. I've used geth account import privatekeyfile to produce the following JSON {"address":"b14ab53e38da1c172f877dbc6d65e4a1b0474c3c","crypto":{"cipher":"aes-128-ctr","ciphertext":"ff22d876d416cb97876dabfee6b6d00645de2d8dd5fca3b46f82112b1a3cffcd","cipherparams":{"iv":"798fcf346ea18c4c3c9e848118c94527"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"bcc9bdc5a24f37ea56269017325b7bda67813199e017d566d7c274722a29d2b6"},"mac":"57efcea80420e75ed4087f20ac0e37481959a3a8a884e4c4a42bcb4331962dfc"},"id":"f162e70f-4b7c-425b-ba84-3041edfc292a","version":3} Jan 9 '17 at 1:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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