Fix 'Keyset Does Not Exist': 2026 Guide for IIS & Azure

Fix CryptographicException 80090016 instantly. Step-by-step guide to resolve missing private key permissions in IIS, Azure, and TPM.

You deployed your API to Azure, clicked refresh, and got hit with a harsh CryptographicException. For .NET developers and IT admins, the message "Keyset does not exist" (error code 80090016) is a familiar nightmare. It usually means the private key is missing or inaccessible, not that the certificate itself has vanished into thin air. Think of it like keyset pagination in database queries: just as a result set cursor needs a bookmark to remember its position across requests, a cryptographic service needs a secure "bookmark" of permissions to locate the key container. When that bookmark is missing, the system throws its hands up.

If you are seeing this error in a JDBC context where you might search for cursor.keyset does not exist java jdbc, note that while the terminology overlaps, this guide focuses on the Windows CryptoAPI and .NET ecosystems where this error is most prevalent. Let's walk through how to fix it.

Close-up of a key in a locked office drawer for secure storage and privacy.

What 'Keyset Does Not Exist' Really Means

To solve this, we have to look under the hood of how Windows handles security. The error is rarely about the certificate file you see in your store; it’s about the hidden infrastructure behind it.

The Difference Between the Certificate and Its Private Key

In the world of X.509 certificates, there is a critical distinction between the public certificate and the private key. The certificate is like your ID card—it’s meant to be shown to the world. The private key, however, is the actual signature seal locked inside a safe that only you can open.

The term "Keyset" refers to the CryptoAPI Key Container (CSP or CCSP), not the certificate file (.cer or .pfx) itself. When you import a certificate without the private key, or when the application pool identity cannot reach the container where the key lives, you get this error.

Analogy: Imagine you have a sealed envelope (the certificate) with your name on it. The "keyset" is the specific lockbox under your desk where the key to open that envelope is kept. If someone hands you the envelope but doesn’t tell you where the lockbox is, or they don’t have permission to open it, you can’t read the letter inside.

I’ve seen this happen frequently when developers export only the public cert from a browser and try to import it into IIS, expecting the private key to magically follow. It doesn’t. The key set is a separate entity in the Windows registry and file system.

Understanding Error Code 80090016

Error code 80090016 maps to the HRESULT NTE_KEYSET_NOT_DEF. This is a low-level Windows CryptoAPI error. It tells us that the Cryptographic Service Provider (CSP) was asked to use a specific key (identified by the certificate’s thumbprint), but it couldn’t find the corresponding key container.

This isn’t an application bug; it’s an access or configuration issue at the OS level. The provider knows what key it should be looking for, but the "shelf" where that key resides is either empty or locked.

A close-up of a hand inserting a USB drive into a laptop port, highlighting technology and connectivity.

Scenario 1: Fixing Private Key Permissions in IIS/Azure

This is the most common scenario. Your certificate is installed correctly, but the service account running your application (like IIS Application Pool) doesn’t have read access to the private key.

Granting Access to Application Pool Identities

When you run an app locally, it often uses your user account, which has full rights to your personal certificate store. But in production (IIS or Azure App Service), the app runs under a system identity like NetworkService, LocalSystem, or IIS AppPool\[YourAppPoolName]. These identities cannot access keys they haven’t been explicitly granted permission for.

Here is how to fix it via the GUI:

  1. Open Certificate Manager by running certlm.msc (for Local Machine store).
  2. Navigate to Personal > Certificates.
  3. Right-click the certificate causing the error and select All Tasks > Manage Private Keys.
  4. In the dialog, add the appropriate identity (e.g., IIS AppPool\YourAppPoolName or NETWORK SERVICE).
  5. Ensure they have Read permissions.
  6. Click OK and restart your application pool.

Why does this fail in production but work locally? Because local development often defaults to the User store with your admin rights, whereas production servers enforce strict isolation between service accounts and sensitive key material.

PowerShell Automation for Batch Fixes

Manual GUI clicks don’t scale in DevOps pipelines. Here’s a PowerShell snippet to automate granting read access to the Network Service account for a specific certificate thumbprint.

param(
    [string]$Thumbprint = "YOUR_CERT_THUMBPRINT"
)

$cert = Get-ChildItem -Path Cert:\LocalMachine\My -Thumbprint $Thumbprint

if ($null -eq $cert) {
    Write-Error "Certificate not found."
    exit
}

$rsa = $cert.PrivateKey

Write-Host "Certificate found: $($cert.Subject)"
Write-Host "Granting permissions would typically require using 'cacls' or 'icacls' on the key container file located in C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys"

For a production-ready script, I recommend using the FindPrivateKey tool from the Windows SDK or directly manipulating the ACLs on the key container files in %ProgramData%\Microsoft\Crypto\RSA\MachineKeys.

Scenario 2: Troubleshooting TPM Hardware Issues

Sometimes the error isn’t about permissions at all—it’s about the hardware. The Trusted Platform Module (TPM) stores keys in a secure, isolated environment. If the TPM is malfunctioning, the keyset effectively "does not exist" from the OS perspective.

Identifying TPM Malfunction Symptoms

TPM errors often present differently than permission errors. You might see the "Keyset does not exist" error across multiple unrelated applications, such as Office 365, Chrome, and Windows Hello simultaneously.

To diagnose this:

  • Run tpm.msc from the Run dialog.
  • Check the Status tab. If it says "The TPM is ready for use," the hardware is likely fine, and the issue is software-related.
  • If it shows an error or is unavailable, you may have a TPM firmware issue.

I’ve encountered cases where Windows updates would reset TPM ownership, breaking the link between the OS and the stored keys.

Clearing and Re-initializing the TPM

Clearing the TPM is a nuclear option. Warning: This will destroy all keys stored on the TPM, including BitLocker keys if enabled. Ensure you have your recovery key before proceeding.

  1. Enter your BIOS/UEFI setup (usually by pressing F2, Del, or F12 at boot).
  2. Locate the Security or Trusted Computing section.
  3. Select Clear TPM or Reset TPM.
  4. Save and exit. Windows will detect the cleared TPM and prompt you to re-setup BitLocker or other services upon reboot.

If the TPM still fails to initialize after a clear, the module itself may be physically failing, requiring hardware replacement.

Scenario 3: Cloud and Container Deployment Pitfalls

Cloud environments introduce new variables. Azure App Services and Docker containers handle certificates differently than on-prem IIS.

Azure App Service and Managed Identities

In Azure, the best practice is to store certificates in Azure Key Vault and access them via Managed Identity. A common mistake is uploading a PFX file to the App Service certificate settings without ensuring the private key is marked as exportable during generation, or failing to grant the Managed Identity access to the Key Vault secret.

If you are migrating from a VM to App Service, ensure your Key Vault policy allows Get and List for the Managed Identity. Also, verify that the App Service is configured to load the certificate from Key Vault rather than relying on the local machine store, which behaves differently in sandboxed environments.

Docker/Linux Container Key Access

Linux containers do not have the Windows CryptoAPI. If you are porting a .NET app that relies on X509Certificate2 with a Windows-specific key store, it will fail.

On Linux, you must use OpenSSL-compatible methods. Instead of referencing a certificate by thumbprint in the Windows store, you should mount the .pem or .pfx file as a secret volume in Kubernetes or Docker Compose. Ensure your application code reads the certificate from the file path (/run/secrets/my-cert.pfx) rather than the certificate store.

For fetching data keyset pagination in these environments, ensure your application can read the secret files even with restricted container user privileges. This often requires setting the correct file permissions in your Dockerfile.

Preventing Future Keyset Errors: Best Practices

Fixing the error is one thing; preventing it is another. Consistency across your CI/CD pipelines is key.

Secure Certificate Export and Import Workflows

When generating certificates, always check "Mark this key as exportable" if you intend to move the PFX between servers or environments. Without this flag, the private key is bound to the specific machine’s secure storage and cannot be exported.

After importing a certificate, verify the private key is present using certutil -verify or by checking if the PrivateKey property of the X509Certificate2 object is non-null.

Monitoring and Alerting

Set up alerts for Event ID 104 and 107 in the Windows Event Log (System or Application logs), which often precede the cryptic "Keyset does not exist" exception. Integrate a health check in your CI/CD pipeline that attempts to load the certificate with its private key before deploying to production.

Implementing these checks ensures that if a certificate is deployed without its key, the pipeline fails early, rather than your users encountering the error in production.

FAQ

How do I fix Keyset does not exist in IIS?

The most common fix is to grant Read permissions to the Application Pool identity (e.g., IIS AppPool\YourAppPoolName) on the certificate’s private key. Open certlm.msc, go to Personal > Certificates, right-click the cert, select All Tasks > Manage Private Keys, and add the identity.

What does error 80090016 mean?

It is the HRESULT for NTE_KEYSET_NOT_DEF. It means the Windows CryptoAPI provider cannot find the key container associated with the certificate thumbprint being used. This is usually due to missing permissions or a corrupted key file.

Why did my certificate work locally but fail on the server?

Locally, your user account likely has permissions to the certificate store. On the server, the IIS Application Pool runs under a system identity (like NetworkService) that does not have inherited permissions to your user’s certificates. You must explicitly grant the server identity access.

How to check if TPM is causing the keyset error?

Run tpm.msc and check the status. If the TPM is not ready, or if you see errors across multiple applications (Windows Hello, Office, etc.), the TPM hardware or firmware may be the culprit.

Conclusion

The "Keyset does not exist" error is almost always a permissions or import configuration issue, rarely a missing certificate. By understanding the difference between the certificate and its key container, and by ensuring your deployment identities have the correct access, you can resolve this quickly. Whether you are dealing with IIS, Azure, or TPM hardware, a systematic approach to checking access and configuration will save you hours of debugging.

Secure private keys are just as important as securing the certificates themselves. Make sure your deployment practices are consistent across dev, test, and production environments to avoid these surprises.


Need more help? Download our free Certificate Permission Audit Script or subscribe to our newsletter for more infrastructure troubleshooting guides.

← Back to Home