Skip to content

Instantly share code, notes, and snippets.

@chackett
Created March 19, 2019 10:40
Show Gist options
  • Save chackett/86123a6b3936e4debad37f184a582300 to your computer and use it in GitHub Desktop.
Save chackett/86123a6b3936e4debad37f184a582300 to your computer and use it in GitHub Desktop.
Create RSA Public Private Keys in PEM format.
privateKey, err := rsa.GenerateKey(rand.Reader,2048)
privKey := pem.EncodeToMemory(&pem.Block{
Type: "RSA PRIVATE KEY",
Bytes: x509.MarshalPKCS1PrivateKey(privateKey),
})
pubKey := pem.EncodeToMemory(&pem.Block{
Type: "RSA PUBLIC KEY",
Bytes: x509.MarshalPKCS1PublicKey(&privateKey.PublicKey),
})
fmt.Println("------------------------")
fmt.Println(string(privKey))
fmt.Println("------------------------")
fmt.Println(string(pubKey))
fmt.Println("------------------------")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment