dustinxie / ecc

Golang native implementation of the secp256k1 elliptic curve
MIT License
29 stars 7 forks source link

How do we write the keys generated into PEM files? #1

Open eastdevil opened 2 years ago

eastdevil commented 2 years ago

Would love to be able to output the keys into PEM files.

volodymyrprokopyuk commented 2 months ago

Hi,

The below code

  prv, err := ecdsa.GenerateKey(ecc.P256k1(), rand.Reader)
  if err != nil {
    return err
  }
  prvX509, err := x509.MarshalECPrivateKey(prv)
  if err != nil {
    return err
  }
  prvPem := pem.EncodeToMemory(&pem.Block{Type: "EC PRIVATE KEY", Bytes: prvX509})
  fmt.Println(string(prvPem))

gives the x509: unknown elliptic curve error.

How the P256k1 keys can be written to and read from PEM files in the X509 encoding format?

Thank you!