Faisal
Faisal

Reputation: 82

ClientCertificateCredential authentication failed: Keyset does not exist

I am facing issue of ClientCertificateCredential authentication failed: Keyset does not exist while using the Azure KeyVault. In debug mode the program works flawlessly but when in released mode, the Azure ClientCertificateCredentials function of package Microsoft Azure trigger error: ClientCertificateCredential authentication failed: Keyset does not exist

I have tried by changing the app pools and debugging alot but nothing happens. (Only works if app pool identity set to Local System otherwise the code is not working when hosted on iis or in debug mode only)

            var keyVaultName = configSection["KeyVault"];
            var keyVaultUri = "https://" + keyVaultName + ".vault.azure.net";
            var KVKeyName = configSection["KVKeyName"];
            var ADCertThumbprint = configSection["ADCertThumbprint"];
            using var store = new X509Store(StoreLocation.LocalMachine);
            store.Open(OpenFlags.ReadOnly);
            var cert = store.Certificates.Find(X509FindType.FindByThumbprint, ADCertThumbprint, false).OfType<X509Certificate2>().Single();
            store.Close();
            var ADApplicationId = configSection["ADApplicationId"];
            //var ADDirectoryId = configSection["ADDirectoryId"];
            var Certificate = new ClientCertificateCredential(ADDirectoryId, ADApplicationId, cert);

            var client = new KeyClient(new Uri(keyVaultUri), Certificate);
            KeyVaultKey key = client.GetKey(KVKeyName);
            var cryptoClient = new CryptographyClient(key.Id, Certificate);
            var data = cryptoClient.Sign(SignatureAlgorithm.RS256, SHA256Hash(body));
            return Convert.ToBase64String(data.Signature);

Upvotes: 0

Views: 500

Answers (1)

Faisal
Faisal

Reputation: 82

I have changed the Identity pool to local system and it worked flawlessly.

Upvotes: 0

Related Questions