'CspKeyContainerInfo'需要Windows Cryptographic API(CAPI),这在此平台上不可用

Has*_*san 2 rsa jwt asp.net-core identityserver4 asp.net-core-2.2

我已经从v2.1将我的项目升级到asp.net core v2.2,并且所有东西都用得很好.在下面显示的代码中,我试图用IdentityServer4(v2.3.2)初始化RSA密钥试图获取令牌我得到以下错误.

        try
        {
            var rsaProvider = new RSACryptoServiceProvider(2048);

            var rsaParametersPrivate =
                RsaExtensions.RsaParametersFromXmlFile(Configuration.GetSection("JwtSettings:rsaPrivateKeyXml")
                    .Value);
            rsaProvider.ImportParameters(rsaParametersPrivate);
            var securityKey = new RsaSecurityKey(rsaProvider);
            _signingCredentials = new SigningCredentials(securityKey, SecurityAlgorithms.RsaSha256);

            _logger.LogInformation("InitializeRsaKey() successfully executed.");
        }
        catch (Exception ex)
        {
            var exception = new Exception("Identity Server RSA Key initialization failed. " + ex);
            _logger.LogError(exception, "InitializeRsaKey() method failed.");
            throw exception;
        }
Run Code Online (Sandbox Code Playgroud)

'CspKeyContainerInfo'需要Windows Cryptographic API(CAPI),这在此平台上不可用.错误.

此外,我的项目在CentOS机器上运行,同时我在Windows 10上开发我的项目.因此,我知道在Linux上缺少Windows中存在的东西.为了解决这个问题,我们非常感谢任何帮助和建议.

Has*_*san 7

我挖了一些github问题,发现只有在Windows上才支持RSACryptoServiceProvider()intherits ICspAsymmetricAlgorithm和这个类.详情请点击此处.为了解决这个问题,我已经更换了var rsaProvider = new RSACryptoServiceProvider(2048);一行,var rsaProvider = RSA.Create(2048);它可以在CentOS上运行.NET Core v2.2.希望这可以帮助那些有同样问题的人.