区块链轻钱包nodejs生成本地keystore

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jiang_xinxing/article/details/80617584

以下函数接受用户输入密码和传入keystore的存储路径,返回私钥

    var fs = require("fs");
    var keythereum = require("keythereum");

    function CreateAccount(passwd, path){
        var params = { keyBytes: 32, ivBytes: 16 };
        var dk = keythereum.create(params);
        var options = {
            kdf: "pbkdf2",
            cipher: "aes-128-ctr",
            kdfparams: {
                c: 262144,
                dklen: 32,
                prf: "hmac-sha256"
            }
        };
        var keyObject = keythereum.dump(passwd, dk.privateKey, dk.salt, dk.iv, options);
        keythereum.exportToFile(keyObject, path);
        return dk.privateKey.toString("hex");

猜你喜欢

转载自blog.csdn.net/jiang_xinxing/article/details/80617584