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
+10.5k Golang : Select region of interest with mouse click and crop from image
+12.4k Golang : Extract part of string with regular expression
+17.2k Golang : When to use init() function?
+15.8k Golang : How to login and logout with JWT example
+16.5k Golang : Execute terminal command to remote machine example
+19.2k Golang : Check if directory exist and create if does not exist
+6k Golang : How to verify input is rune?
+8.8k Golang : Executing and evaluating nested loop in html template
+35.9k Golang : Integer is between a range
+14.3k Golang : How to shuffle elements in array or slice?
+15.2k Golang : Save(pipe) HTTP response into a file
+8.9k Golang : What is the default port number for connecting to MySQL/MariaDB database ?