简体   繁体   English

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

[英]Reading an email address from a Bouncy Castle PGP key

After fighting with the library for some time, I am at a loss for how to get this simple piece of data from a PgpPublicKey object.在与库斗争了一段时间后,我对如何从PgpPublicKey对象中获取这条简单的数据PgpPublicKey I've tried the most obvious route, GetUserAttributes() but it returns an empty list.我尝试了最明显的路线GetUserAttributes()但它返回一个空列表。 GetUserIds() returns a list of simple string objects, but in the format "Your Name (comment)" . GetUserIds()返回一个简单string对象列表,但格式为"Your Name (comment)"

How does one retrieve the email addresses for the key ID's?如何检索密钥 ID 的电子邮件地址?

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); 
            }
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM