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
+11k Golang : Generate random elements without repetition or duplicate
+7.1k Golang : Squaring elements in array
+27.4k Golang : Convert CSV data to JSON format and save to file
+6.6k Golang : How to determine if request or crawl is from Google robots
+6.9k Golang : Normalize email to prevent multiple signups example
+37.7k Golang : Comparing date or timestamp
+16.9k Golang : Read integer from file into array
+7.5k Golang : Create zip/ePub file without compression(use Store algorithm)
+16.3k Golang : Find out mime type from bytes in buffer
+13.8k Golang : unknown escape sequence error
+16.5k Golang : Get IP addresses of a domain name
+17.5k Golang : Linked list example