从PGP公钥中提取模和指数

本文关键字:指数 提取 PGP 公钥 | 更新日期: 2023-09-27 17:57:26

我正在开发一个实现PGP加密的应用程序。我面临着一个问题,我们需要从PGP公钥中提取模数和指数。我正在使用Bouncy castle PGP库。请帮忙。

从PGP公钥中提取模和指数

选择公钥后尝试代码

 PgpPublicKey  PublicKey;
 var val = (RsaKeyParameters)PublicKey.GetKey();
 string ModulusVal = Convert.ToBase64String(Encoding.UTF8.GetBytes(val.Modulus.ToString()));
 string ExponentVal = Convert.ToBase64String(Encoding.UTF8.GetBytes(val.Exponent.ToString()));
XDocument X = new XDocument(new XDeclaration("1.0", "UTF-8", "yes"),
                                        new XElement("RSAKeyValue",
                                            new XElement("Modulus", ModulusVal),
                                            new XElement("Exponent", ExponentVal)));
X.Save(XMLFileSavePath, SaveOptions.None);