Reputation: 29
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
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