It hard to describe this issue, maybe show golang code for explain is more clear.
// MarshalECPrivateKey converts an EC private key to SEC 1, ASN.1 DER form.
//
// This kind of key is commonly encoded in PEM blocks of type "EC PRIVATE KEY".
// For a more flexible key format which is not EC specific, use
// MarshalPKCS8PrivateKey.
func MarshalECPrivateKey(key *ecdsa.PrivateKey) ([]byte, error) {
oid, ok := oidFromNamedCurve(key.Curve)
if !ok {
return nil, errors.New("x509: unknown elliptic curve")
}
return marshalECPrivateKeyWithOID(key, oid)
}
// code start from here
keyData, err := x509.MarshalECPrivateKey(privKey)
if err != nil {
return
}
buf := &bytes.Buffer{}
// Encode writes the PEM encoding of pem.Block to buf.
err = pem.Encode(buf, &pem.Block{
Type: "ECDSA Private Key",
Bytes: keyData,
})
return buf
Both of x509.MarshalECPrivateKey and pem.Encode come from go standard library.
the input privKey
was generated like this ecdsa.GenerateKey(elliptic.P256(), bytes.NewBuffer(seed))
use standard library too.
the output should be a string like following:
ā-----BEGIN ECDSA Private Key-----\nMHcCAQEEIEnwfSZLjxS1LbO2EszEgtz75i2dhu63Fr0ZRIFzMSB8oAoGCCqGSM49\nAwEHoUQDQgAE3hQPJEBL/7wSqDeuAdSJYYK2U65AqcZl7z/xEk5SYB0DjnnA0b98\n/igatsDrN75hfsnXdGxsASeFnY3uyBq/Bg==\n-----END ECDSA Private Key-----\nā
I spent hours for search shards works like this on crystalshards.org
and shards.info
, but no luck.
Thank you.