3

I have ASP.Net Core 1.0.0 app using cryptography. I need to decrypt keys using RSACryptoServiceProvider. Visual Studio suggested adding System.Security.Cryptography.Csp version 4.0.0 to my dependencies. I accept, and on Windows it all works just fine. But when I deployed it on Ubuntu 16.04 RSACryptoServiceProvider's methods started to throw PlatformNotSupportedException exception. Am I using the wrong assembly? I found https://github.com/dotnet/corefx/tree/v1.0.0/src/System.Security.Cryptography.Csp and there is 1.0.0 version. Is that what I need? How can I add it to my project?

Slip
  • 593
  • 1
  • 7
  • 21

1 Answers1

6

RSACryptoServiceProvider is based on CryptoAPI, a Windows-specific unmanaged API. Since it's not available on Linux, a PlatformNotSupportedException exception is thrown at runtime.

Instead, consider referencing System.Security.Cryptography.Algorithms and using RSA.Create() to get an implementation compatible with your environment (on Linux, you'll get a RSAOpenSsl instance).

Kévin Chalet
  • 39,509
  • 7
  • 121
  • 131
  • 1
    Thank you! `RSA` works fine. But still I don't get the point of including Windows-specific tools in Net Standart packages... – Slip Aug 22 '16 at 14:08
  • Not everyone needs or wants cross-platform support in .NET Core. Using implementation-specific packages allows using `RSACryptoServiceProvider`, `RSACng` or `RSAOpenSsl` directly, which enables advanced scenarios (e.g you can use a `CngKey` that relies on a specific key storage provider when using `RSACng`) – Kévin Chalet Aug 22 '16 at 14:12