繁体   English   中英

C#从公共证书密钥(字符串)创建RSACryptoServiceProvider

[英]C# Create RSACryptoServiceProvider from public certificate key which is string

是否可以从字符串的公共证书密钥生成RSACryptoServiceProvider。

我尝试像:

RSACryptoServiceProvider provider = new RSACryptoServiceProvider();
var publicKey = PublicKey.GetPublicKey();
provider.FromXmlString("<RSAKeyValue><Modulus>" + publicKey + "</Modulus></RSAKeyValue>");

但我得到无效的base64例外

  at Caused by: md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable: System.Security.Cryptography.CryptographicException: Couldn't decode XML ---> System.FormatException: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.

我能做什么?

两件事情。

第一:您的结束标记是向后的...

</RSAKeyValue></Modulus>

应该读

</Modulus></RSAKeyValue>

第二:您缺少指数参数。

请参阅以下工作代码:

RSACryptoServiceProvider provider = new RSACryptoServiceProvider();
//var publicKey = PublicKey.GetPublicKey();
provider.FromXmlString(
    "<RSAKeyValue>"+
        "<Modulus>CmZ5HcaYgWjeerd0Gbt/sMABxicQJwB1FClC4ZqNjFHQU7PjeCod5dxa9OvplGgXARSh3+Z83Jqa9V1lViC7qw==</Modulus>"+
        "<Exponent>AQAB</Exponent>"+
    "</RSAKeyValue>");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM