Golang crypto/elliptic.GenerateKey() function example
package crypto/elliptic
GenerateKey returns a public/private key pair. The private key is generated using the given reader, which must return random data.
Golang crypto/elliptic.GenerateKey() function usage example
package main
import (
"crypto/elliptic"
"crypto/rand"
"crypto"
"fmt"
"math/big"
)
type ellipticPublicKey struct {
elliptic.Curve
X, Y *big.Int
}
type ellipticPrivateKey struct {
privk []byte
}
func main() {
var privatekey crypto.PrivateKey
var publickey crypto.PublicKey
var err error
var priv []byte
var x, y *big.Int
priv, x, y, err = elliptic.GenerateKey(elliptic.P224(), rand.Reader) //P224 for this example
if err != nil {
fmt.Println(err)
}
privatekey = &ellipticPrivateKey {
privk : priv,
}
publickey = &ellipticPublicKey {
Curve : elliptic.P224(), // this is just for example, change to suit your need
X : x,
Y : y,
}
fmt.Printf("Private key : %x \n", privatekey)
fmt.Printf("Public key : %x \n", publickey)
}
Sample output :
go run elliptic.go
Private key : &{a24435364e9885bf0c0f675b1fc413e95988765117c6f23a35285aa1}
Public key : &{{2082142d0 [15c1d21 3280d61 2112234 ....}
Reference :
Advertisement
Something interesting
Tutorials
+20.6k Golang : Secure(TLS) connection between server and client
+8.9k Golang : What is the default port number for connecting to MySQL/MariaDB database ?
+7.5k Golang : Process json data with Jason package
+15.6k Golang : Validate hostname
+15.2k Golang : Get timezone offset from date or timestamp
+13.7k Golang : Tutorial on loading GOB and PEM files
+5.9k Facebook : How to force facebook to scrape latest URL link data?
+6.1k Fix ERROR 2003 (HY000): Can't connect to MySQL server on 'IP address' (111)
+6k PageSpeed : Clear or flush cache on web server
+22.8k Golang : untar or extract tar ball archive example
+12.3k Golang : Validate email address
+5.8k Unix/Linux : How to test user agents blocked successfully ?