Skip to content

Instantly share code, notes, and snippets.

@henryaj
Last active December 1, 2016 10:17
Show Gist options
  • Save henryaj/460a985b0920ecd1d8d489bed48cd85c to your computer and use it in GitHub Desktop.
Save henryaj/460a985b0920ecd1d8d489bed48cd85c to your computer and use it in GitHub Desktop.
ASCII-armored RSA key generation in Golang
package main
import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"encoding/pem"
"fmt"
)
var privateKey string
var keySize int = 4096 // reduce this if running in the Go playground
func main() {
key, _ := rsa.GenerateKey(rand.Reader, keySize)
privateKeyBytes := pem.EncodeToMemory(
&pem.Block{
Type: "RSA PRIVATE KEY",
Bytes: x509.MarshalPKCS1PrivateKey(key),
},
)
privateKey = string(privateKeyBytes)
fmt.Println(privateKey)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment