Share via

On Premises Data Gateway - Bad Gateway error - System.Security.Cryptography.CryptographicException: Key not valid for use in specified state

Scott Henderson 0 Reputation points
2026-05-06T01:36:57.3933333+00:00

We are seeing intermittent issues where workflows are failing across many On Premise Data Gateways with the same Bad Gateway Error (502) error. We are also seeing intermittent issues in creating new connections with the same error. The error detail is as follows:

message:Unexpected Exception : System.Security.Cryptography.CryptographicException: Key not valid for use in specified state.\r\n\r\n at System.Security.Cryptography.Utils.CreateProvHandle(CspParameters parameters Boolean randomKeyContainer)\r\n at System.Security.Cryptography.Utils.GetKeyPairHelper(CspAlgorithmType keyType CspParameters parameters Boolean randomKeyContainer Int32 dwKeySize SafeProvHandle& safeProvHandle SafeKeyHandle& safeKeyHandle)\r\n at System.Security.Cryptography.RSACryptoServiceProvider.GetKeyPair()\r\n at System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 dwKeySize CspParameters parameters Boolean useDefaultKeySize)\r\n at System.Security.Cryptography.X509Certificates.X509Certificate2.get_PrivateKey()\r\n at System.Security.

We have systems with On Prem Data Gateways in Australia east and Australia southeast, and it does not appear to be region specific.

Is anyone else experiencing this issue?

Community Center | Not monitored

1 answer

Sort by: Most helpful
  1. Q&A Assist
    2026-05-06T01:37:07.6266667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    The error System.Security.Cryptography.CryptographicException: Key not valid for use in specified state with on-premises data gateways is associated with problems generating or accessing the asymmetric key material the gateway uses. A known cause is antivirus or security software corrupting or deleting the RSA key files that the gateway relies on during setup or runtime.

    For on-premises data gateways, the documented remediation for asymmetric key issues is:

    1. Temporarily disable or reconfigure antivirus
      • Antivirus products such as McAfee Endpoint Defender can interfere with the gateway’s cryptographic files and processes.
      • Configure the antivirus to ignore the gateway process, or temporarily disable it while fixing the issue and testing.
    2. Remove the corrupted RSA key container for the gateway service account
      • Delete the RSA folder under the profile of the gateway service account, for example:
        • C:\Users<GW Service Account User>\AppData\Roaming\Microsoft\Crypto\RSA
      • Note: Depending on whether the gateway is running under a user profile or a service profile, the root path can differ; ensure the correct profile for the gateway service account is used.
    3. Restart the machine and complete gateway setup/sign-in
      • After deleting the RSA folder and adjusting antivirus, restart the gateway machine.
      • Re-run the gateway setup/sign-in so new, valid keys are generated.
    4. Ensure all gateways are on a supported, current version
      • Install the latest on-premises data gateway build on all affected machines. Only the last six releases are actively supported, and many reliability issues are resolved in monthly updates.
      • If using gateway clusters, keep all members on the same version to avoid intermittent failures.
    5. Check for general gateway connectivity issues
      • If 502 errors persist after fixing the cryptographic issue, verify that each gateway can reach required Azure endpoints and ports by running the network ports test and reviewing firewall/proxy configuration.

    If, after these steps, the intermittent 502 and cryptographic errors continue across multiple gateways, open a support ticket for the cloud service using the gateway so logs and environment details can be reviewed.


    References:

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.