Core: System.PlatformNotSupportedException","Message":"'CspParameters' requires Windows Cryptographic API (CAPI), which is not available on this platform.

Created on 11 Jul 2019  Â·  4Comments  Â·  Source: dotnet/core

Issue Title

System.PlatformNotSupportedException","Message":"'CspParameters' requires Windows Cryptographic API (CAPI), which is not available on this platform.

Enviroment

Centos 7,Docker ,.Net Core 2.1

General

cause the error code is :" RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(bitLen, CspParameters);".

The Code is :

                CspParameters CspParameters = new CspParameters();
                CspParameters.Flags = CspProviderFlags.UseMachineKeyStore;

                int bitLen = 1024;
                if ("RSA2".Equals(signType))
                {
                    bitLen = 2048;
                }

                RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(bitLen, CspParameters);
                RSAParameters RSAparams = new RSAParameters();
                RSAparams.Modulus = MODULUS;
                RSAparams.Exponent = E;
                RSAparams.D = D;
                RSAparams.P = P;
                RSAparams.Q = Q;
                RSAparams.DP = DP;
                RSAparams.DQ = DQ;
                RSAparams.InverseQ = IQ;
                RSA.ImportParameters(RSAparams);

Most helpful comment

If you're not naming your keys to persist them there's no point in using the CspParameters key creation. Your code could just be

```C#
RSA rsa = RSA.Create();
RSAParameters RSAParams = new RSAParameters();
...
rsa.ImportParameters(RSAparams);

`CspParameters` is about directly interacting with the Windows crypto libraries, which are only available on Windows.

If you're strongly typed as RSACryptoServiceProvider (which is generally a bad idea, it's the most limited of the RSA types) you can just eliminate the use of the CspParameters parameter... ImportParameters (when the key isn't named) makes a new ephemeral key and imports into that.  And the original key size data is ignored when using ImportParameters.  So, that would leave

```C#
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
RSAParameters RSAParams = new RSAParameters();
...
RSA.ImportParameters(RSAParams);

All 4 comments

I find a similar issue ,so close this.

Oh,It's not a question.

If you're not naming your keys to persist them there's no point in using the CspParameters key creation. Your code could just be

```C#
RSA rsa = RSA.Create();
RSAParameters RSAParams = new RSAParameters();
...
rsa.ImportParameters(RSAparams);

`CspParameters` is about directly interacting with the Windows crypto libraries, which are only available on Windows.

If you're strongly typed as RSACryptoServiceProvider (which is generally a bad idea, it's the most limited of the RSA types) you can just eliminate the use of the CspParameters parameter... ImportParameters (when the key isn't named) makes a new ephemeral key and imports into that.  And the original key size data is ignored when using ImportParameters.  So, that would leave

```C#
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
RSAParameters RSAParams = new RSAParameters();
...
RSA.ImportParameters(RSAParams);

@bartonjs Thank you very much !

Was this page helpful?
0 / 5 - 0 ratings