Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)[:]))
- }
Add Comment
Please, Sign In to add comment