forked from dhartunian/1brcgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencrypt.go
31 lines (24 loc) · 794 Bytes
/
encrypt.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
package main
import (
"flag"
"fmt"
"os/exec"
)
func main() {
flag.Parse()
fileName := flag.Arg(0)
// Create a symmetric key.
execCmd("openssl", "rand", "-out", "key.sym", "-base64", "32")
defer execCmd("rm", "key.sym")
// Encrypt fileName with the symmetric key.
execCmd("openssl", "aes-256-cbc", "-a", "-pbkdf2", "-salt", "-in", fileName, "-out", fileName+".enc", "-kfile", "key.sym")
// Encrypt the symmetric key with the public key.
execCmd("openssl", "rsautl", "-encrypt", "-pubin", "-inkey", "public_key.pem", "-in", "key.sym", "-out", fileName+".key")
fmt.Printf("Created %s.enc and %s.key. Please send both.\n", fileName, fileName)
}
func execCmd(name string, args ...string) {
cmd := exec.Command(name, args...)
if err := cmd.Run(); err != nil {
panic(err)
}
}