Golang crypto/x509.ParseECPrivateKey() function example
package crypto/x509
ParseECPrivateKey parses an ASN.1 Elliptic Curve Private Key Structure.
Golang crypto/x509.ParseECPrivateKey() function usage example
package main
import (
"crypto/x509"
"os"
"fmt"
"encoding/pem"
)
func main() {
var pemBytes = `-----BEGIN EC PRIVATE KEY-----
MHcCAQEEIKGOgzn9u8RCSwwJj0sGOog6QGpDNkCuBRNsv76bRXLYoAoGCCqGSM49
AwEHoUQDQgAEPAYLQF6I4NQ1Q0AjeHqJj7fDX/WwJ6xba5aDQ7V9pIQfq8k+JUME
RUBF85MS+jPu5Rn+59AP9aPRSybIQsxZrg==
-----END EC PRIVATE KEY-----`
block, _ := pem.Decode([]byte(pemBytes))
privatekey, err := x509.ParseECPrivateKey(block.Bytes)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Printf("Public Key : : %x\n\n", privatekey.PublicKey)
fmt.Printf("Private Key D : : %x\n\n", privatekey.D)
}
Sample output :
Public Key : : {{c208024600} 3c060b405e88e0d435434023787a898fb7c35ff5b027ac5b6b968343b57da484 1fabc93e254304454045f39312fa33eee519fee7d00ff5a3d14b26c842cc59ae}
Private Key D : : a18e8339fdbbc4424b0c098f4b063a883a406a433640ae05136cbfbe9b4572d8
Reference :
Advertisement
Something interesting
Tutorials
+6k Golang : How to verify input is rune?
+19.2k Golang : Populate dropdown with html/template example
+9.8k Golang : Format strings to SEO friendly URL example
+6.1k nginx : force all pages to be SSL
+32.2k Golang : Convert []string to []byte examples
+11.5k Golang : Change date format to yyyy-mm-dd
+13.7k Golang : Image to ASCII art example
+5.4k Golang : What is StructTag and how to get StructTag's value?
+25.7k Golang : How to write CSV data to file
+16.7k Golang : Gzip file example
+7.4k Golang : How to detect if a sentence ends with a punctuation?