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
+14.4k Golang : On enumeration
+13.8k Golang : Convert spaces to tabs and back to spaces example
+25.8k Golang : Daemonizing a simple web server process example
+4.7k Adding Skype actions such as call and chat into web page examples
+21.2k Golang : Clean up null characters from input data
+16.4k Golang : Test floating point numbers not-a-number and infinite example
+9.9k Golang : ffmpeg with os/exec.Command() returns non-zero status
+5k Golang : Calculate a pip value and distance to target profit example
+13.2k Golang : Convert(cast) int to int64
+13.9k Golang : How to determine if a year is leap year?
+16.6k Golang : Generate QR codes for Google Authenticator App and fix "Cannot interpret QR code" error
+17.8k Golang : Defer function inside init()