Golang crypto/ecdsa.GenerateKey() function example
package crypto/ecdsa
GenerateKey generates a public and private key pair.
Golang crypto/ecdsa.GenerateKey() function usage example
pubkeyCurve := elliptic.P256() //see http://golang.org/pkg/crypto/elliptic/#P256
privatekey := new(ecdsa.PrivateKey)
privatekey, err := ecdsa.GenerateKey(pubkeyCurve, rand.Reader) // this generates a public & private key pair
if err != nil {
fmt.Println(err)
os.Exit(1)
}
var pubkey ecdsa.PublicKey
pubkey = privatekey.PublicKey
fmt.Println("Private Key :")
fmt.Printf("%x \n", privatekey)
fmt.Println("Public Key :")
fmt.Printf("%x \n",pubkey)
See ECDSA tutorial for full example
Reference :
Advertisement
Something interesting
Tutorials
+12k Golang : Convert a rune to unicode style string \u
+8.2k Golang : Add build version and other information in executables
+19.6k Golang : Close channel after ticker stopped example
+21.1k Golang : Sort and reverse sort a slice of strings
+7.5k Golang : How to handle file size larger than available memory panic issue
+4.7k Golang : How to pass data between controllers with JSON Web Token
+7.5k Golang : Gorrila set route name and get the current route name
+7.5k Golang : Handling Yes No Quit query input
+9.4k Golang : Find the length of big.Int variable example
+8.2k Golang : Routes multiplexer routing example with regular expression control
+13.7k Golang : Image to ASCII art example
+55.3k Golang : Unmarshal JSON from http response