首页 > 解决方案 > 单声道:不能再使用 settor 设置 X509Certificate2 私钥

问题描述

在最近的某个时候,Mono 取消了对在 X509Certificate2 上设置私钥的支持。版本 6.8.0.96 导致Platform Not Supported异常。

我需要这样做,因为我已经获得了一对 pem 证书和 rsa 密钥文件,我将它们读取并重新组合成 X509Certificate2。这在过去有效。

所以我读到为 .NET Framework 和 .NET Core 设置私钥的建议方法是使用这个扩展“CopyWithPrivateKey”。https://github.com/mono/mono/issues/14152#issuecomment-499524798

https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.x509certificates.rsacertificateextensions.copywithprivatekey?view=netframework-4.7.2#System_Security_Cryptography_X509Certificates_RSACertificateExtensions_CopyWithPrivateKey_System_Security_Cryptography_X509Certificates_X509Certificate2_System_Security_Cryptography_RSA

项目是 .NET 框架 4.7.2,据说提供了这个扩展。它在 4.7.1 中不可用。

修改代码以在X509Certificate2 中使用 CopyWithPrivateKey 结果不包含“CopyWithPrivateKey”的定义

包括指定的命名空间 (System.Security.Cryptography.X509Certificates)。然而没有骰子。Visual Studio 没有明确建议为任何特定程序集添加引用。它看起来不像一个 nuget 包。

这是怎么回事?这是否支持?为什么以这种方式将它从 Mono 代码库中剥离出来?是否不担心向后兼容性?

有没有人必须为此找出解决方法?

标签: c#.netmonox509certificate2

解决方案


推荐阅读