Skip to content

Commit d622573

Browse files
author
Anand
committed
Adding files which are in testing
1 parent 0a8dead commit d622573

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

test/testpgp.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Test openpgp
2+
3+
package main
4+
5+
import (
6+
"os"
7+
"os/user"
8+
"fmt"
9+
"bytes"
10+
"io/ioutil"
11+
"path/filepath"
12+
"golang.org/x/crypto/openpgp"
13+
)
14+
15+
16+
func main() {
17+
18+
currUser, _ := user.Current()
19+
secretText := "These are the nuclear launch codes - A/B/C/D"
20+
path, err := filepath.Abs(filepath.Join(currUser.HomeDir, ".gnupg/pubring.kbx"))
21+
fmt.Println(path)
22+
23+
fh, _ := os.Open(path)
24+
defer fh.Close()
25+
26+
entityList, err := openpgp.ReadArmoredKeyRing(fh)
27+
if err != nil {
28+
fmt.Println("1")
29+
panic(err)
30+
}
31+
32+
buf := new(bytes.Buffer)
33+
w, err := openpgp.Encrypt(buf, entityList, nil, nil, nil)
34+
35+
_, err = w.Write([]byte(secretText))
36+
if err != nil {
37+
fmt.Println("2")
38+
panic(err)
39+
}
40+
41+
err = w.Close()
42+
if err != nil {
43+
panic(err)
44+
}
45+
46+
data, err := ioutil.ReadAll(buf)
47+
if err != nil {
48+
fmt.Println("3")
49+
panic(err)
50+
}
51+
52+
// encStr := base64.StdEncoding.EncodeToString(bytes)
53+
54+
err = os.WriteFile("test.gpg", data, 0644)
55+
if err != nil {
56+
fmt.Println("4")
57+
panic(err)
58+
}
59+
}

0 commit comments

Comments
 (0)