System.Security.Cryptography.CryptographicException: 'The requested operation is not supported

0

Following the example of creating an identity server from the identityserver4 documents, I received the following exception on the line AddDeveloperSigningCredentials()

  System.Security.Cryptography.CryptographicException
  HResult=0x80090029
  Message=The requested operation is not supported.
  Source=System.Core
  StackTrace:
   at System.Security.Cryptography.NCryptNative.ExportKey(SafeNCryptKeyHandle 
   key, String format)
   at System.Security.Cryptography.CngKey.Export(CngKeyBlobFormat format)
   at System.Security.Cryptography.RSACng.ExportParameters(Boolean includePrivateParameters)
   at Microsoft.Extensions.DependencyInjection.IdentityServerBuilderExtensionsCrypto.CreateRsaSecurityKey()
   at Microsoft.Extensions.DependencyInjection.IdentityServerBuilderExtensionsCrypto.AddDeveloperSigningCredential(IIdentityServerBuilder builder, Boolean persistKey, String filename)
   at WH_Identity.Startup.ConfigureServices(IServiceCollection services) in C:\Stage\WH_Identity\WH_Identity\Startup.cs:line 18

More info:

The above is thrown when using identityserver4 in web project targeting .net framework 4.6.1

When the same is done using .NET core 2, it works and creates a tempkey.rsa file in the root.

Anyone have any idea on how to resolve this or any work around?

-----------------Edit 1/11/2018--------------------

Alright, so I went into the identityserver4 source and obtained the following code and ran it in Linqpad with same results. Google search doesn't give much information on this. Hoping someone knows what I am doing wrong.

void Main()
{
    var key = CreateRsaSecurityKey();

    RSAParameters parameters;

    if (key.Rsa != null)
        parameters = key.Rsa.ExportParameters(includePrivateParameters: true);
    else
        parameters = key.Parameters;

    parameters.Dump();
    key.Dump();

}

public static RsaSecurityKey CreateRsaSecurityKey()
{
    var rsa = RSA.Create();
    RsaSecurityKey key;

        if (rsa is RSACryptoServiceProvider)
        {
            rsa.Dispose();
            var cng = new RSACng(2048);

            var parameters = cng.ExportParameters(includePrivateParameters: true);
            key = new RsaSecurityKey(parameters);
        }
        else
        {
            rsa.KeySize = 2048;
            key = new RsaSecurityKey(rsa);
        }


    key.KeyId = CryptoRandom.CreateUniqueId(16);
    return key;
}

The error is on the line var parameters = cng.ExportParameters(includePrivateParameters: true); Is it OS version or something related to framework?

identityserver4
asked on Stack Overflow Jan 10, 2018 by vikramka • edited Jan 11, 2018 by vikramka

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0