/
makeprivkey.go
executable file
·50 lines (46 loc) · 964 Bytes
/
makeprivkey.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
45
46
47
48
49
50
package main
import (
"bytes"
"code.google.com/p/go.crypto/openpgp"
"code.google.com/p/go.crypto/openpgp/armor"
"fmt"
)
func main() {
ent, err := openpgp.NewEntity("bob", "Bob's key", "bob@example.net", nil)
if err != nil {
panic(err)
}
pkbuf := bytes.NewBuffer(nil)
err = ent.SerializePrivate(pkbuf, nil)
if err != nil {
panic(err)
}
buf := bytes.NewBuffer(nil)
ewrbuf, err := armor.Encode(buf, "PGP PRIVATE KEY BLOCK", nil)
if err != nil {
panic(err)
}
_, err = ewrbuf.Write(pkbuf.Bytes())
if err != nil {
panic(err)
}
ewrbuf.Close()
fmt.Printf("%s\n", buf.Bytes())
// serialize the public key
pkbuf = bytes.NewBuffer(nil)
err = ent.Serialize(pkbuf)
if err != nil {
panic(err)
}
buf = bytes.NewBuffer(nil)
ewrbuf, err = armor.Encode(buf, openpgp.PublicKeyType, nil)
if err != nil {
panic(err)
}
_, err = ewrbuf.Write(pkbuf.Bytes())
if err != nil {
panic(err)
}
ewrbuf.Close()
fmt.Printf("%s\n", buf.Bytes())
}