blob: bb39c4dbc493659a2235df22049ff2539ab08945 [file] [log] [blame]
Giorgi Lekveishvili23ef7f82023-05-26 11:57:48 +04001package installer
2
3import (
4 "crypto/ed25519"
5 "crypto/rand"
6 "crypto/x509"
7 "encoding/pem"
8
9 "golang.org/x/crypto/ssh"
10)
11
12func GenerateSSHKeys() (string, string, error) {
13 pub, priv, err := ed25519.GenerateKey(rand.Reader)
14 if err != nil {
15 return "", "", err
16 }
17 privEnc, err := x509.MarshalPKCS8PrivateKey(priv)
18 if err != nil {
19 return "", "", err
20 }
21 privPem := pem.EncodeToMemory(
22 &pem.Block{
23 Type: "PRIVATE KEY",
24 Bytes: privEnc,
25 },
26 )
27 pubKey, err := ssh.NewPublicKey(pub)
28 if err != nil {
29 return "", "", err
30 }
31 return string(ssh.MarshalAuthorizedKey(pubKey)), string(privPem), nil
32}