Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 私钥错误中的参数不正确_C#_Cryptography_Rsa_Private Key - Fatal编程技术网

C# 私钥错误中的参数不正确

C# 私钥错误中的参数不正确,c#,cryptography,rsa,private-key,C#,Cryptography,Rsa,Private Key,我在单独的文件中有私钥和公钥 在说明中说使用此代码: RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); rsa.FromXmlString(PrivateKey); 但是当代码到达第二行时,我得到了这个错误: mscorlib.dll中发生类型为“System.Security.Cryptography.CryptographyException”的未处理异常 附加信息:参数不正确 有什么问题吗 在我们获得密钥的公司

我在单独的文件中有私钥和公钥

在说明中说使用此代码:

RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();

rsa.FromXmlString(PrivateKey);
但是当代码到达第二行时,我得到了这个错误:

mscorlib.dll中发生类型为“System.Security.Cryptography.CryptographyException”的未处理异常

附加信息:参数不正确

有什么问题吗

在我们获得密钥的公司的示例代码中,它使用示例peivate和公钥,如下所示:

<RSAKeyValue><Modulus>KEY VALUE</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>
键值aqab
即使我将
加入起点和
AQAB


最后,notting工作了

我使用此网站将我的密钥从纯字符串转换为xml:


由于.Net需要xml格式的密钥,最可能的原因是您的私钥没有所有的D、p、Q、DP、DQ、InverseQ值

第二个最有可能的原因是,字节[]形式的D没有模数(字节[]形式)长。同样,P/Q/DP/DQ/InverseQ都需要将字节[]形式作为模长的一半(向上取整)


某些键在XML格式中不是这样。最可靠的方法是自己构建RSAPameters结构并调用
ImportParameters
。原因之一:XML方法在.NET Core中根本不可用,但ImportParameters是可用的。

您能展示一个私钥示例吗?@ArtjomB。是的,我想要任何C#中的代码将我的密钥转换为xml,反之亦然,就像你在回答中链接到的站点上面的站点包含完整的代码一样。如果在该页面上向下滚动,则会有一个指向要点的链接。@ArtjomB。我没注意到。谢谢你的回答