从PGP公钥中提取模数和指数

时间:2021-11-16 18:25:04

I am working on an application that implements PGP encryption. I am faced with a issue where we need to extract the Modulus and Exponent from the PGP public keys. I am using Bouncy castle PGP library. Please help.

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

1 个解决方案

#1


1  

Try the the code after selecting the public Key

选择公钥后尝试代码

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

#1


1  

Try the the code after selecting the public Key

选择公钥后尝试代码

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