-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtestpgp.go
More file actions
58 lines (46 loc) · 966 Bytes
/
testpgp.go
File metadata and controls
58 lines (46 loc) · 966 Bytes
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Test openpgp
package main
import (
"bytes"
"fmt"
"golang.org/x/crypto/openpgp"
"io/ioutil"
"os"
"os/user"
"path/filepath"
)
func main() {
currUser, _ := user.Current()
secretText := "These are the nuclear launch codes - A/B/C/D"
path, err := filepath.Abs(filepath.Join(currUser.HomeDir, ".gnupg/pubring.kbx"))
fmt.Println(path)
fh, _ := os.Open(path)
defer fh.Close()
entityList, err := openpgp.ReadArmoredKeyRing(fh)
if err != nil {
fmt.Println("1")
panic(err)
}
buf := new(bytes.Buffer)
w, err := openpgp.Encrypt(buf, entityList, nil, nil, nil)
_, err = w.Write([]byte(secretText))
if err != nil {
fmt.Println("2")
panic(err)
}
err = w.Close()
if err != nil {
panic(err)
}
data, err := ioutil.ReadAll(buf)
if err != nil {
fmt.Println("3")
panic(err)
}
// encStr := base64.StdEncoding.EncodeToString(bytes)
err = os.WriteFile("test.gpg", data, 0644)
if err != nil {
fmt.Println("4")
panic(err)
}
}