2016-08-22 151 views
3

我有使用密码学的ASP.Net Core 1.0.0应用程序。我需要使用RSACryptoServiceProvider解密密钥。 Visual Studio建议将System.Security.Cryptography.Csp版本4.0.0添加到我的依赖项中。我接受,而在Windows上它一切正常。但是当我在Ubuntu上部署它时,16.04 RSACryptoServiceProvider的方法开始抛出PlatformNotSupportedException异常。我使用错误的程序集吗? 我发现https://github.com/dotnet/corefx/tree/v1.0.0/src/System.Security.Cryptography.Csp并且有1.0.0版本。那是我需要的吗?我如何将它添加到我的项目?Ubuntu上的System.Security.Cryptography.Csp 16.04

回答

5

RSACryptoServiceProvider基于CryptoAPI,一个Windows特有的非托管API。由于它在Linux上不可用,因此在运行时会引发PlatformNotSupportedException异常。

相反,请考虑参考System.Security.Cryptography.Algorithms并使用RSA.Create()来获得与您的环境兼容的实现(在Linux上,您将获得一个RSAOpenSsl实例)。

+0

谢谢! 'RSA'工作正常。但是我仍然不明白在Net Standart软件包中包含特定于Windows的工具... – Slip

+0

并非所有人都需要或希望在.NET Core中实现跨平台支持。使用实现特定的包允许直接使用'RSACryptoServiceProvider','RSACng'或'RSAOpenSsl',这可以实现高级场景(例如,当使用'RSACng'时,您可以使用'CngKey'来依赖特定的密钥存储提供者) – Pinpoint