go-libp2p-daemon/identity.go

26 lines
442 B
Go
Raw Normal View History

2018-09-23 11:49:00 +00:00
package p2pd
import (
"io/ioutil"
2019-05-26 22:58:53 +00:00
"github.com/libp2p/go-libp2p-core/crypto"
2018-09-23 11:49:00 +00:00
)
func ReadIdentity(path string) (crypto.PrivKey, error) {
bytes, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
return crypto.UnmarshalPrivateKey(bytes)
}
func WriteIdentity(k crypto.PrivKey, path string) error {
bytes, err := crypto.MarshalPrivateKey(k)
if err != nil {
return err
}
return ioutil.WriteFile(path, bytes, 0400)
2018-09-23 11:49:00 +00:00
}