Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package main
import (
"fmt"
"log"
"golang.org/x/crypto/openpgp"
"golang.org/x/crypto/openpgp/packet"
)
func createNewKey(name, comment, email string, keysize int) *openpgp.Entity {
cfg := &packet.Config{RSABits: keysize} // 4096 is slow
newKey, err := openpgp.NewEntity(name, comment, email, cfg)
if err != nil {
log.Fatalf("Cannot create a new key: %s", err)
}
return newKey
}
func main() {
e := createNewKey("John Smith", "Test key, do not use", "john.smith@example.org", 1024)
fmt.Printf("%+v\n", e)
// &{PrimaryKey:0xc420016140 PrivateKey:0xc4200016c0 Identities:map[John Smith (Test key, do not use) <john.smith@example.org>:0xc42024f400] Revocations:[] Subkeys:[{PublicKey:0xc4200163c0 PrivateKey:0xc420001860 Sig:0xc4202b21c0}]}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.