我的代码:
using System.Security.Cryptography;
public class Test
{
public static void Main()
{
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
System.Console.WriteLine(RSA.ToXMLString(false));
}
}
当我运行它时,我得到以下内容:
test.cs(10,38): error CS1061: 'RSACryptoServiceProvider' does not contain a definition for 'ToXMLString' and no extension method 'ToXMLString' accepting a first argument of type 'RSACryptoServiceProvider' could be found (are you missing a using directive or an assembly reference?)
我所期待的更像是这样:
<?xml version="1.0" encoding="utf-16"?>
<RSAParameters xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Exponent>AQAB</Exponent>
<Modulus>sMFsHSyxAP5N85yvx/XDs9acJa30qwBjoOdDKvNOHJUYBpspwatkdtErCqM2W6tXH9rbvhIn8/nqW4OqAdLinlgkEJoQ/qnzKjYJhHl4YzKFL6Wp+iFRH6ar6ZWOE87LeNQ0nHwlXKoWkJQKV8NB38XRw6aLvNTj8Po2yaFDbQFztsJ+ILkumRh7Leu77IV+124Swc6JqLRt5z2FnDX869dRi2fqcnFa1EHEBsPEndVd2HSeJUncTQiWJ9SNRU+WLltVVewYiGheqr1ABab++3XM5qrB6fWn/RN9Fcg5nM8fachAFSX2YRrEsg7mcbNALRes6OEdpI0LBdX8Wdw6oQ==</Modulus>
</RSAParameters>
有什么想法吗?
答案 0 :(得分:1)
使用以下代码
https://msdn.microsoft.com/en-us/library/zseyf239(v=vs.110).aspx
https://www.code4copy.com/csharp/how-to-generate-publicprivate-key-using-rsa/
using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(2048))
{
System.Console.WriteLine(RSA.ToXmlString(false));
}