从Bouncy Castle PGP键读取电子邮件地址

时间:2012-11-14 18:33:31

标签: c# bouncycastle pgp

在与图书馆争夺一段时间后,我对如何从PgpPublicKey对象获取这一简单数据感到茫然。我尝试过最明显的路由GetUserAttributes(),但它返回一个空列表。 GetUserIds()返回简单string个对象的列表,但格式为"Your Name (comment)"

如何检索密钥ID的电子邮件地址?

1 个答案:

答案 0 :(得分:2)

public static void Test_ReadPublicKeys(PgpPublicKeyRingBundle publicKeyRingBundle)
{
    foreach (PgpPublicKeyRing publicKeyRing in publicKeyRingBundle.GetKeyRings())
    {
        foreach (PgpPublicKey publicKey in publicKeyRing.GetPublicKeys())
        {
            foreach (object userId in publicKey.GetUserIds())
            {
                //Prints "My_Key_Name (Notes) <my_email@gmail.com>"
                Console.WriteLine(userId); 
            }
        }
    }
}