Private-Key

如何從原始私鑰生成密鑰庫(UTC)文件?

  • January 8, 2017

如果我有明文私鑰,如何geth使用 Node.js 生成兼容的密鑰庫文件?

我想我需要scrypt通過提供密碼使用算法對其進行加密,但我不知道該怎麼做。任何 - 最好是可瀏覽的 - 範例都將受到高度讚賞。

謝謝,

可以使用ethereumjs-wallet庫在 Node 中創建與 geth 兼容的密鑰庫文件:

> var Wallet = require('ethereumjs-wallet');
> var key = Buffer.from('efca4cdd31923b50f4214af5d2ae10e7ac45a5019e9431cc195482d707485378', 'hex');
> var wallet = Wallet.fromPrivateKey(key);
> wallet.toV3String('password');
'{"version":3,"id":"467233bf-45ec-423b-9548-bdc4a42aa099","address":"b14ab53e38da1c172f877dbc6d65e4a1b0474c3c","crypto":{"ciphertext":"17886b7ff355219dd20900543b9592fcd4dc6fe7d8f776f1a4d1c63993112181","cipherparams":{"iv":"434e4e71d2013a2d84e86a6e89efbb0b"},"cipher":"aes-128-ctr","kdf":"scrypt","kdfparams":{"dklen":32,"salt":"7a785ab75fa906734788d85ff43a2c8e704af41881dd50a2d52abe08092f07ec","n":262144,"r":8,"p":1},"mac":"98d9a76960dcef22a5fd28a6bf47e5c68a71b30bcf353eccbf5a6555abec78a1"}}'

您還可以指定其他選項來控制 kdf、密碼和其他錢包參數。見這裡

引用自:https://ethereum.stackexchange.com/questions/11166