Is it possible to read entity details like name/comment and email from a given armored private / public key using golang openpgp package ?
The following code implements a test that generate a new armored key pair, it then tries to get entity details from it.
However the resulting entity does not contain any identity information.
package main
import (
"log"
"testing"
"github.com/jchavannes/go-pgp/pgp"
"golang.org/x/crypto/openpgp"
)
func TestID(t *testing.T) {
keypair, err := pgp.GenerateKeyPair("test", "tst comment", "test@email.com")
if err != nil {
t.Fatalf("failed to generate keypair: %s", err)
}
var entity *openpgp.Entity
entity, err = pgp.GetEntity([]byte(keypair.PublicKey), []byte(keypair.PrivateKey))
if err != nil {
t.Fatalf("failed to read entity: %s", err)
}
log.Printf("%#v
", entity.Identities)
}
outputs
2019/05/19 00:02:54 map[string]*openpgp.Identity{"":(*openpgp.Identity)(0xc00006edc0)}
It was expected that entity.Identities
contains test (tst comment) <test@email.com>
.