diff options
Diffstat (limited to 'crypto/crypto.go')
-rw-r--r-- | crypto/crypto.go | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/crypto/crypto.go b/crypto/crypto.go index c3d47b629..442942c6c 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -9,6 +9,7 @@ import ( "crypto/sha256" "fmt" "io" + "io/ioutil" "os" "encoding/hex" @@ -139,6 +140,12 @@ func LoadECDSA(file string) (*ecdsa.PrivateKey, error) { return ToECDSA(buf), nil } +// SaveECDSA saves a secp256k1 private key to the given file with restrictive +// permissions +func SaveECDSA(file string, key *ecdsa.PrivateKey) error { + return ioutil.WriteFile(file, FromECDSA(key), 0600) +} + func GenerateKey() (*ecdsa.PrivateKey, error) { return ecdsa.GenerateKey(S256(), rand.Reader) } |