从 .NET 10 开始,macOS 不再支持 OpenSSL 支持的加密基元。 System.Security.Cryptography.AesCcm以及特定于 OpenSSL 的类,例如System.Security.Cryptography.RSAOpenSsl,现在会在 macOS 上抛出PlatformNotSupportedException。
引入的版本
.NET 10
以前的行为
以前,特定于 OpenSSL 的类(例如 System.Security.Cryptography.RSAOpenSsl,如果 OpenSSL 可用),则适用于 macOS。
System.Security.Cryptography.AesCcm 如果 OpenSSL 可用,则适用于 macOS。
新行为
从 .NET 10 开始,特定于 OpenSSL 的类(例如 RSAOpenSsl,即使 OpenSSL 可用)也不适用于 macOS,并且 PlatformNotSupportedException 引发异常。
AesCcm 引发 PlatformNotSupportedException 异常。
破坏性变更的类型
这是行为 变化。
更改原因
对 OpenSSL 支持的基元的支持源自 .NET Core 1.0,其中 macOS 上的加密通过 OpenSSL 实现。 这并不理想,因为最新版本的 OpenSSL 不在 macOS 上,在 macOS 上获取和配置 OpenSSL 很麻烦。 在 .NET Core 2.0 期间,加密功能已转移到 Apple 的内置功能中,因此加密可以正常运作,无需另外获取任何组件。
被后缀为OpenSsl的类型仍由OpenSSL实现,而AesCcm在Apple的加密库中没有实现。
在 macOS 上支持这些 OpenSSL 支持的基元变得更加困难,因为 Apple 使得从某些路径加载库变得更加困难,并且使在 macOS 上分发软件变得复杂化。
建议的措施
如果你使用的是 OpenSSL 支持的基元,但没有任何使用 OpenSSL 的特定意图,建议使用提供 macOS 实现的工厂:
-
new DSAOpenSsl(...)->DSA.Create(...) -
new ECDiffieHellmanOpenSsl(...)->ECDiffieHellman.Create(...) -
new ECDsaOpenSsl(...)->ECDsa.Create(...) -
new RSAOpenSsl(...)->RSA.Create(...)
System.Security.Cryptography.AesCcm 在 macOS 上没有同等的功能替代品。 请考虑改用其他加密基元,例如 System.Security.Cryptography.AesGcm。
受影响的 API
- System.Security.Cryptography.AesCcm(所有构造函数)
- System.Security.Cryptography.DSAOpenSsl(所有构造函数)
- System.Security.Cryptography.ECDiffieHellmanOpenSsl(所有构造函数)
- System.Security.Cryptography.ECDsaOpenSsl(所有构造函数)
- System.Security.Cryptography.RSAOpenSsl(所有构造函数)
- System.Security.Cryptography.SafeEvpPKeyHandle(整个类)