Last active
December 1, 2016 10:17
-
-
Save henryaj/460a985b0920ecd1d8d489bed48cd85c to your computer and use it in GitHub Desktop.
ASCII-armored RSA key generation in Golang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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