C# 中的 RSA 加密:哪一部分定义了公钥?
我生成了一个新的公钥/私钥对并将其导出为 XML 字符串:
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(2048);
string publicPrivateKey = RSA.ToXmlString(true);
publicPrivateKey 中的 XML 字符串如下所示(为了便于阅读,缩短了字符串):
<RSAKeyValue>
<Modulus>t6tLd1Wi7PEkwPfx9KGP1Ps/5F2saXnOsCE2U....</Modulus>
<Exponent>AQAB</Exponent>
<P>3LJ5y4Vla7cS3XgmbIH5dQgppUHa+aSWavEOCbDRS/M....</P>
<Q>1QyGIAnjv4YLcRVdwXtxWkijc+aZ496qIBZnCAUUD/E....</Q>
<DP>0821dc0f+LBKOqIEvj4+2kJrNV5ueQesFBYkEsjPFM....</DP>
<DQ>ugSzX2oDJwjdGKG1OOiVcmUWAm6IU4PpOxcUYtY8TC....</DQ>
<InverseQ>LDQIQu+LSB6CSZBrGxNQthWi9mkuPGVZyDDr....</InverseQ>
<D>qZm2bXKH8WwbsJ8ZlT3S1TbgUifppLrqSRkb8XqEcMv....</D>
</RSAKeyValue>
生成的公钥应该在其他应用程序中使用(PHP / JavaScript / JAVA)来加密数据。上述 XML 的哪一部分定义了公钥/我必须将哪一部分发送给其他应用程序的开发人员?
另一方面:什么定义了私钥/我必须存储哪些部分才能解密由我的公钥加密的数据?
I've generated a new public/private key pair and exported it as an XML string:
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(2048);
string publicPrivateKey = RSA.ToXmlString(true);
The XML string in publicPrivateKey looks like this (strings are shortened for readability):
<RSAKeyValue>
<Modulus>t6tLd1Wi7PEkwPfx9KGP1Ps/5F2saXnOsCE2U....</Modulus>
<Exponent>AQAB</Exponent>
<P>3LJ5y4Vla7cS3XgmbIH5dQgppUHa+aSWavEOCbDRS/M....</P>
<Q>1QyGIAnjv4YLcRVdwXtxWkijc+aZ496qIBZnCAUUD/E....</Q>
<DP>0821dc0f+LBKOqIEvj4+2kJrNV5ueQesFBYkEsjPFM....</DP>
<DQ>ugSzX2oDJwjdGKG1OOiVcmUWAm6IU4PpOxcUYtY8TC....</DQ>
<InverseQ>LDQIQu+LSB6CSZBrGxNQthWi9mkuPGVZyDDr....</InverseQ>
<D>qZm2bXKH8WwbsJ8ZlT3S1TbgUifppLrqSRkb8XqEcMv....</D>
</RSAKeyValue>
The generated public key should be used in other apps (PHP / JavaScript / JAVA) to encrypt data. What part of the above XML defines the public key / what part do I have to send to the developers of the other apps?
And on the opposite side: What defines the private key / which part/parts do I have to store to be able to decrypt the data encrypted by my public key?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
指数和模数定义公钥。
如果您使用
RSA.ToXmlString
的唯一参数
includePrivateParameters
设置为false
,您只会看到格式输出。
Exponent and modulus define the public key.
If you use
RSA.ToXmlString
with its sole parameterincludePrivateParameters
set tofalse
, you will only see the formatoutput.
在 .NET 中生成其他方的 RSA 密钥很复杂。如果您向他们发送此 XML,则并非所有合作伙伴都能够使用它。公钥的一般格式如下:
您提供的 xml 是私钥。要生成公钥,您应该使用
结果如下:
您可能希望使用其他方来获取其他格式的密钥:
http://www.codeproject.com/KB/security/RSACryptoPad.aspx
要将 Java 密钥移植为 .NET 格式,您可以使用此项目:
http://www.codeproject.com/KB/security/porting_java_public_key.aspx
RSA keys for other parties are complicated to generate in .NET. If you send them this XML, not all your partners will be able to use it. General format for the public key is something like that:
The xml you've proived is a private key. To generate public key you should use the
Result will be like that:
You may want to use other parties to get key in other format:
http://www.codeproject.com/KB/security/RSACryptoPad.aspx
To port Java key to .NET format you can use this project:
http://www.codeproject.com/KB/security/porting_java_public_key.aspx