Matt
Matt

Reputation: 29

Need help reading/writing ECDSA Keys in GoLang

Currently, I have:

// generate keys
priv, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
// get public key
pub := priv.Public()

I, however, need help on getting the raw byte data and using the correct encoding to read/write these public and private keys to files.

Upvotes: 1

Views: 717

Answers (1)

Luke Joshua Park
Luke Joshua Park

Reputation: 9806

Just marshal them to a []byte using x509.MarshalECPrivateKey. You can just read and write the binary to a file.

You might find in future you want to store the keys in PEM format, as is common. You can do that with the encoding/pem package.

Upvotes: 2

Related Questions