Created
November 22, 2017 19:18
-
-
Save cadmuxe/b8da9d2596d07b45e7bc6ff908088d98 to your computer and use it in GitHub Desktop.
This file contains 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 ( | |
"fmt" | |
"crypto/rsa" | |
"encoding/pem" | |
"crypto/x509" | |
"crypto/rand" | |
"bytes" | |
"golang.org/x/crypto/ssh" | |
) | |
func main() { | |
key, _ := rsa.GenerateKey(rand.Reader, 2048) | |
privatePem := new(bytes.Buffer) | |
privateKey := &pem.Block{ | |
Type: "RSA PRIVATE KEY", | |
Bytes: x509.MarshalPKCS1PrivateKey(key), | |
} | |
pem.Encode(privatePem, privateKey) | |
fmt.Println(privatePem.String()) | |
pub, _ := ssh.NewPublicKey(&key.PublicKey) | |
fmt.Println(string(ssh.MarshalAuthorizedKey(pub)[:])) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment