【发布时间】:2020-02-10 22:00:39
【问题描述】:
我有一个用 .NET Framework 2.0 编译的程序集(是的,很老的东西),它使用证书的公钥执行加密。代码极其简单:
X509Certificate2 objCert = new X509Certificate2(path);
RSACryptoServiceProvider rsa = (RSACryptoServiceProvider)objCert.PublicKey.Key;
byte [] EncrRes = rsa.Encrypt(data, false);
这将继续适用于所有最新版本的 .NET Framework,但拒绝在 .NET Core 下运行。我收到了两条不同但相似的错误消息。
Windows 10: 无法将“System.Security.Cryptography.RSACng”类型的对象转换为“System.Security.Cryptography.RSACryptoServiceProvider”类型。
Linux: 无法将“System.Security.Cryptography.RSAOpenSsl”类型的对象转换为“System.Security.Cryptography.RSACryptoServiceProvider”类型。
有没有办法对这个简单的操作进行编码,以便它可以在 .NET Framework 2.0+ 和 .NET core 上运行?
提前致谢。
【问题讨论】:
标签: .net .net-core x509certificate2