看到开发文档里面提到使用的库 keythereum 就想尝试一下修改Keystore文件密码。基本上抄一下README的代码就搞定,只是读写Keystore文件的目录的操作不太直观
代码如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
var keythereum = require("keythereum");
address= '3d8797a152d95b3f389182e25ceb3672e71b80c5'
var datadir = "."
var keyObject = keythereum.importFromFile(address, datadir); #导入原Keystore
var password = "press1"; #原密码
var privateKey = keythereum.recover(password, keyObject);
console.log(privateKey.toString("hex")); #以十六进制形式输出私钥
var params = { keyBytes: 32, ivBytes: 16 };
var dk = keythereum.create(params);
var password = "123456"; #新密码
var options = {
kdf: "pbkdf2",
cipher: "aes-128-ctr",
kdfparams: {
c: 262144,
dklen: 32,
prf: "hmac-sha256"
}
};
var keyObject = keythereum.dump(password, privateKey, dk.salt, dk.iv, options);
keythereum.exportToFile(keyObject); #保存新的Keystore
|
完整的项目在 https://github.com/blockchain-onlooker/ethereum_key_change_password
PressOne_keystore文件的原密码是 press1
运行之后会在keystore目录下生成一个新文件,把后缀修改成json,就可以用新密码 123456 登录 https://beta.press.one/login