Guest User

Untitled

a guest
Nov 24th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "crypto/rsa"
  6. "encoding/pem"
  7. "crypto/x509"
  8. "crypto/rand"
  9. "bytes"
  10. "golang.org/x/crypto/ssh"
  11. )
  12.  
  13. func main() {
  14. key, _ := rsa.GenerateKey(rand.Reader, 2048)
  15. privatePem := new(bytes.Buffer)
  16. privateKey := &pem.Block{
  17. Type: "RSA PRIVATE KEY",
  18. Bytes: x509.MarshalPKCS1PrivateKey(key),
  19. }
  20. pem.Encode(privatePem, privateKey)
  21. fmt.Println(privatePem.String())
  22.  
  23. pub, _ := ssh.NewPublicKey(&key.PublicKey)
  24. fmt.Println(string(ssh.MarshalAuthorizedKey(pub)[:]))
  25. }
Add Comment
Please, Sign In to add comment