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
+9.8k Golang : Get current, epoch time and display by year, month and day
+30k Golang : Get time.Duration in year, month, week or day
+9.7k Golang : Find correlation coefficient example
+7.8k Golang : Lock executable to a specific machine with unique hash of the machine
+18.5k Golang : Set, Get and List environment variables
+31.7k Golang : How to convert(cast) string to IP address?
+15.6k Golang : Validate hostname
+7.1k Javascript : How to get JSON data from another website with JQuery or Ajax ?
+15.4k Golang : invalid character ',' looking for beginning of value
+9.4k Golang : Find the length of big.Int variable example
+7.4k Golang : Individual and total number of words counter example
+10.2k Golang : How to profile or log time spend on execution?