内容简介:如果你用 geth 创建过账号「geth –datadir /path/to/data account new」,那么多半知道 keystore 文件,它通过一个 password 加密保存着账号的私钥:如果我想拿到加密前的私钥怎么办?最容易想到的办法是在 MetaMask 中导入账号的时候选择通过 JSON 文件导入的方式,然后再导出私钥。不过这个方法不方便,也无法实现自动化,下面看看如何通过 golang 解密 keystore 文件:代码极其简单,就不用多做解释了,收工!
如果你用 geth 创建过账号「geth –datadir /path/to/data account new」,那么多半知道 keystore 文件,它通过一个 password 加密保存着账号的私钥:
keystore
如果我想拿到加密前的私钥怎么办?最容易想到的办法是在 MetaMask 中导入账号的时候选择通过 JSON 文件导入的方式,然后再导出私钥。不过这个方法不方便,也无法实现自动化,下面看看如何通过 golang 解密 keystore 文件:
package main import ( "encoding/hex" "flag" "fmt" "io/ioutil" "os" "github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/crypto" ) var ( file = flag.String("file", "", "file") password = flag.String("password", "", "password") ) func init() { flag.Parse() } func main() { if _, err := os.Stat(*file); os.IsNotExist(err) { flag.Usage() os.Exit(1) } keyjson, err := ioutil.ReadFile(*file) if err != nil { panic(err) } key, err := keystore.DecryptKey(keyjson, *password) if err != nil { panic(err) } address := key.Address.Hex() privateKey := hex.EncodeToString(crypto.FromECDSA(key.PrivateKey)) fmt.Printf("Address:\t%s\nPrivateKey:\t%s\n", address, privateKey, ) }
代码极其简单,就不用多做解释了,收工!
以上所述就是小编给大家介绍的《如何解密keystore文件》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- 探索文件加解密
- lucky 勒索病毒分析与文件解密
- 如何解密Windows 10中的EFS加密文件和文件夹
- Unity3d资源文件解密
- APICloud解密本地资源到逆向APP算法到通用资源解密
- NodeJS加密解密,node-rsa加密解密用法
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Writing Windows VxDs and Device Drivers, Second Edition
Karen Hazzah / CMP / 1996-01-12 / USD 54.95
Software developer and author Karen Hazzah expands her original treatise on device drivers in the second edition of "Writing Windows VxDs and Device Drivers." The book and companion disk include the a......一起来看看 《Writing Windows VxDs and Device Drivers, Second Edition》 这本书的介绍吧!