52 lines
888 B
Go
52 lines
888 B
Go
package kgc
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"os"
|
|
pb "schain/proto"
|
|
"schain/proto/util"
|
|
)
|
|
|
|
func readTxtFile(filePath string) ([]byte, error) {
|
|
// 打开文件
|
|
file, err := os.Open(filePath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer file.Close()
|
|
|
|
// 读取文件内容
|
|
content, err := ioutil.ReadAll(file)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return content, nil
|
|
}
|
|
|
|
func LoadPriKey(file string) []byte {
|
|
content, err := readTxtFile(file)
|
|
if err != nil {
|
|
fmt.Println("load privatekey error")
|
|
}
|
|
return content
|
|
}
|
|
|
|
func LoadPubKey(file string) []byte {
|
|
content, err := readTxtFile(file)
|
|
if err != nil {
|
|
fmt.Println("load publickey error")
|
|
}
|
|
return content
|
|
}
|
|
|
|
func InitIdentity(IdentityPath string, mspID string) ([]byte, error) {
|
|
pubkey, _ := readTxtFile(IdentityPath)
|
|
sId := &pb.Creator{
|
|
Mspid: mspID,
|
|
IdBytes: pubkey,
|
|
}
|
|
return util.MarshalOrPanic(sId), nil
|
|
}
|