Skip to content

Instantly share code, notes, and snippets.

@cadmuxe
Created November 22, 2017 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cadmuxe/b8da9d2596d07b45e7bc6ff908088d98 to your computer and use it in GitHub Desktop.
Save cadmuxe/b8da9d2596d07b45e7bc6ff908088d98 to your computer and use it in GitHub Desktop.
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