github.com/bigzoro/my_simplechain@v0.0.0-20240315012955-8ad0a2a29bb9/cmd/dummytx/common/common.go (about) 1 package common 2 3 import ( 4 "github.com/bigzoro/my_simplechain/accounts/keystore" 5 "io/ioutil" 6 "strings" 7 ) 8 9 func GetKey(filename, auth string) (*keystore.Key, error) { 10 // Load the key from the keystore and decrypt its contents 11 passwdByte, err := ioutil.ReadFile(auth) 12 if err != nil { 13 return nil, err 14 } 15 keyjson, err := ioutil.ReadFile(filename) 16 if err != nil { 17 return nil, err 18 } 19 passwd := strings.Trim(string(passwdByte), "\n") 20 passwd = strings.Trim(passwd, "\t") 21 passwd = strings.Trim(passwd, "\r") 22 passwd = strings.Trim(passwd, " ") 23 key, err := keystore.DecryptKey(keyjson, passwd) 24 if err != nil { 25 return nil, err 26 } 27 return key, nil 28 }