Sitecore Error: Unhandled exception: "Keyset does not exist"
A few days back, I changed the certificate on the Content Management server, after that, I was not able to login into the Content Management Server. It was throwing the below error:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Unhandled exception: "Keyset does not exist" | |
Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: Keyset does not exist | |
at Internal.NativeCrypto.CapiHelper.CreateProvHandle(CspParameters parameters, Boolean randomKeyContainer) | |
at System.Security.Cryptography.RSACryptoServiceProvider.get_SafeProvHandle() | |
at System.Security.Cryptography.RSACryptoServiceProvider.get_SafeKeyHandle() | |
at System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 keySize, CspParameters parameters, Boolean useDefaultKeySize) | |
at System.Security.Cryptography.RSACryptoServiceProvider..ctor(CspParameters parameters) | |
at Internal.Cryptography.Pal.CertificatePal.<>c.<GetRSAPrivateKey>b__61_0(CspParameters csp) | |
at Internal.Cryptography.Pal.CertificatePal.GetPrivateKey[T](Func`2 createCsp, Func`2 createCng) | |
at Internal.Cryptography.Pal.CertificatePal.GetRSAPrivateKey() | |
at Internal.Cryptography.Pal.CertificateExtensionsCommon.GetPrivateKey[T](X509Certificate2 certificate, Predicate`1 matchesConstraints) | |
at Microsoft.IdentityModel.Tokens.X509SecurityKey.get_PrivateKey() | |
at Microsoft.IdentityModel.Tokens.X509SecurityKey.get_PrivateKeyStatus() | |
at Microsoft.IdentityModel.Tokens.AsymmetricSignatureProvider..ctor(SecurityKey key, String algorithm, Boolean willCreateSignatures) | |
at Microsoft.IdentityModel.Tokens.CryptoProviderFactory.CreateSignatureProvider(SecurityKey key, String algorithm, Boolean willCreateSignatures) | |
at Microsoft.IdentityModel.JsonWebTokens.JwtTokenUtilities.CreateEncodedSignature(String input, SigningCredentials signingCredentials) | |
at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.WriteToken(SecurityToken token) | |
at IdentityServer4.Services.DefaultTokenCreationService.CreateJwtAsync(JwtSecurityToken jwt) | |
at IdentityServer4.Services.DefaultTokenCreationService.CreateTokenAsync(Token token) | |
at IdentityServer4.Services.DefaultTokenService.CreateSecurityTokenAsync(Token token) | |
at IdentityServer4.ResponseHandling.AuthorizeResponseGenerator.CreateImplicitFlowResponseAsync(ValidatedAuthorizeRequest request, String authorizationCode) | |
at IdentityServer4.ResponseHandling.AuthorizeResponseGenerator.CreateHybridFlowResponseAsync(ValidatedAuthorizeRequest request) | |
at IdentityServer4.ResponseHandling.AuthorizeResponseGenerator.CreateResponseAsync(ValidatedAuthorizeRequest request) | |
at IdentityServer4.Endpoints.AuthorizeEndpointBase.ProcessAuthorizeRequestAsync(NameValueCollection parameters, ClaimsPrincipal user, ConsentResponse consent) | |
at IdentityServer4.Endpoints.AuthorizeCallbackEndpoint.ProcessAsync(HttpContext context) | |
at IdentityServer4.Endpoints.AuthorizeCallbackEndpoint.ProcessAsync(HttpContext context) | |
at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events) | |
2022-06-05T04:06:13.0854066-04:00 [ERR] (Sitecore Identity/HNCSCORE02) Connection id ""0HMI6P8T77DP6"", Request id ""0HMI6P8T77DP6:00000006"": An unhandled exception was thrown by the application. | |
Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: Keyset does not exist | |
at Internal.NativeCrypto.CapiHelper.CreateProvHandle(CspParameters parameters, Boolean randomKeyContainer) | |
at System.Security.Cryptography.RSACryptoServiceProvider.get_SafeProvHandle() | |
at System.Security.Cryptography.RSACryptoServiceProvider.get_SafeKeyHandle() | |
at System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 keySize, CspParameters parameters, Boolean useDefaultKeySize) | |
at System.Security.Cryptography.RSACryptoServiceProvider..ctor(CspParameters parameters) | |
at Internal.Cryptography.Pal.CertificatePal.<>c.<GetRSAPrivateKey>b__61_0(CspParameters csp) | |
at Internal.Cryptography.Pal.CertificatePal.GetPrivateKey[T](Func`2 createCsp, Func`2 createCng) | |
at Internal.Cryptography.Pal.CertificatePal.GetRSAPrivateKey() | |
at Internal.Cryptography.Pal.CertificateExtensionsCommon.GetPrivateKey[T](X509Certificate2 certificate, Predicate`1 matchesConstraints) | |
at Microsoft.IdentityModel.Tokens.X509SecurityKey.get_PrivateKey() | |
at Microsoft.IdentityModel.Tokens.X509SecurityKey.get_PrivateKeyStatus() | |
at Microsoft.IdentityModel.Tokens.AsymmetricSignatureProvider..ctor(SecurityKey key, String algorithm, Boolean willCreateSignatures) | |
at Microsoft.IdentityModel.Tokens.CryptoProviderFactory.CreateSignatureProvider(SecurityKey key, String algorithm, Boolean willCreateSignatures) | |
at Microsoft.IdentityModel.JsonWebTokens.JwtTokenUtilities.CreateEncodedSignature(String input, SigningCredentials signingCredentials) | |
at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.WriteToken(SecurityToken token) | |
at IdentityServer4.Services.DefaultTokenCreationService.CreateJwtAsync(JwtSecurityToken jwt) | |
at IdentityServer4.Services.DefaultTokenCreationService.CreateTokenAsync(Token token) | |
at IdentityServer4.Services.DefaultTokenService.CreateSecurityTokenAsync(Token token) | |
at IdentityServer4.ResponseHandling.AuthorizeResponseGenerator.CreateImplicitFlowResponseAsync(ValidatedAuthorizeRequest request, String authorizationCode) | |
at IdentityServer4.ResponseHandling.AuthorizeResponseGenerator.CreateHybridFlowResponseAsync(ValidatedAuthorizeRequest request) | |
at IdentityServer4.ResponseHandling.AuthorizeResponseGenerator.CreateResponseAsync(ValidatedAuthorizeRequest request) | |
at IdentityServer4.Endpoints.AuthorizeEndpointBase.ProcessAuthorizeRequestAsync(NameValueCollection parameters, ClaimsPrincipal user, ConsentResponse consent) | |
at IdentityServer4.Endpoints.AuthorizeCallbackEndpoint.ProcessAsync(HttpContext context) | |
at IdentityServer4.Endpoints.AuthorizeCallbackEndpoint.ProcessAsync(HttpContext context) | |
at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events) | |
at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events) | |
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) | |
at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.Invoke(HttpContext context) | |
at IdentityServer4.Hosting.BaseUrlMiddleware.Invoke(HttpContext context) | |
at Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware.Invoke(HttpContext httpContext) | |
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application) |
Solution:
After some investigation I found that my new certificate which I was using for the Identity server, does not have the permission of the Identity App Pool so I followed the below steps:
- Enter "mmc" in the run command window.
- Click on Add/Remove Snap-ins option inside the File menu.
- Select Certificates and click on Add button, then select Computer account and click on Next->Finish->Ok
- Go to the Personal-> Certificates.
- Now right-click on the Identity server certificate, then click All Tasks-> Manage Private Keys.
- Click on Add button and add IIS App Pool\Identity.XXX permission.
- Click on Check Name, and give read access.
I hope it will work for you. Happy coding :)
Comments