package main import ( "bytes" "code.google.com/p/go.crypto/openpgp" "crypto/rand" "log" "time" ) func main() { // Create new entities entity1, err := openpgp.NewEntity(rand.Reader, time.Now(), "Test user 1", "test1", "test1@localhost") if err != nil { log.Fatal("Cannot create new PGP entity", err) } println("Entity can sign? ", entity1.PrimaryKey.CanSign()) entity2, err := openpgp.NewEntity(rand.Reader, time.Now(), "Test user 2", "test2", "test2@localhost") if err != nil { log.Fatal("Cannot create new PGP entity", err) } // The buffer that holds the encrypted message encrypted := new(bytes.Buffer) // The message to encrypt content := "The quick brown fox" // Setup encryption enc, err := openpgp.Encrypt(encrypted, []*openpgp.Entity{entity2}, entity1, nil) if err != nil { log.Fatal("Encryption setup: ", err) } // Encrypt _, err = enc.Write([]byte(content)) if err != nil { log.Fatal("Encryption: ", err) } // Indicate that this is the end of the message enc.Close() println(encrypted.String()) }