Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.Security.Cryptography.Csp on Ubuntu 16.04

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?

like image 360
Slip Avatar asked Feb 26 '26 17:02

Slip


1 Answers

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).

like image 111
Kévin Chalet Avatar answered Mar 02 '26 00:03

Kévin Chalet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!