CryptographicException:Azure上已存在使用Asp.net Core的对象

时间:2016-05-17 13:56:32

标签: c# asp.net azure dnx

我正在使用azure上的asp.net 5网站,并且在尝试创建RSACryptoServiceProvider的实例时遇到了folloqing错误,我将使用该实例生成基本身份验证令牌。它在我之前发布的我的web项目中对我来说是天然的服务器,但它在发布后开始抛出错误。没有与此相关的代码被更改。

CryptographicException: Object already exists.

我打电话的代码如下:

 var handler = new JwtSecurityTokenHandler();

        var claimsIdentity = new ClaimsIdentity(identity, new Claim[0], "BearerToken", "", "");
        // Use the KeyContainerParams from our token options, this ensures that we retrieve
        // the same keys both here and in the token validator configured in Startup.
        using (var rsaCsp = new System.Security.Cryptography.RSACryptoServiceProvider(2048, _tokenOptions.KeyContainerParams))
        {
            // Create signing credentials from the current RSA key provided by the 
            // crypto service provider.
            var signingCreds = new SigningCredentials(
                new RsaSecurityKey(rsaCsp.ExportParameters(true)),
                SecurityAlgorithms.RsaSha256Signature);

            // Generate the token using these signing credentials.
            var securityToken = handler.CreateToken(
                issuer: _tokenOptions.Issuer,
                audience: _tokenOptions.Audience,
                signingCredentials: signingCreds,
                subject: claimsIdentity,
                expires: expires.DateTime
            );

            // Write the token as a json string.
            var token = handler.WriteToken(securityToken);
            _logger.LogVerbose("Generated token {0} with RSA", token);
            return token;
        }

可能是什么原因?自初始实施以来,此代码未发生变化。

0 个答案:

没有答案