Split - Merge :Shardlet Move using cr.microsoft.com/splitmerge/splitmergeworker:20240812.1, gettingMicrosoft.Azure.SqlDatabase.ElasticScale.SplitMerge.Worker.SplitMergeOperationFailedException: Bad Key while sending the request from UI

Deepak Raj 1 Reputation point
2025-09-30T11:15:33.15+00:00

We are trying move a list shard from one shard to another shard. I have setup both UI & Backend Apps as mentioned in the article : https://free.blessedness.top/en-us/azure/azure-sql/database/elastic-scale-configure-deploy-split-and-merge?view=azuresql

Added the certificates as well, but when I try to move from the web app we are getting the following error :
Status: Failed

"Details: [Error] Failed to process request. Microsoft.Azure.SqlDatabase.ElasticScale.SplitMerge.Worker.SplitMergeOperationFailedException: Bad Key.

---> System.Security.Cryptography.CryptographicException: Bad Key.

at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)

at System.Security.Cryptography.RSACryptoServiceProvider.DecryptKey(SafeKeyHandle pKeyContext, Byte[] pbEncryptedKey, Int32 cbEncryptedKey, Boolean fOAEP, ObjectHandleOnStack ohRetDecryptedKey)

at System.Security.Cryptography.RSACryptoServiceProvider.Decrypt(Byte[] rgb, Boolean fOAEP)

at Microsoft.Azure.SqlDatabase.ElasticScale.RsaEncryptedMessage.DecryptMessage(RSACryptoServiceProvider decryptionKey, Boolean useOaes)

at Microsoft.Azure.SqlDatabase.ElasticScale.HybridEncryptedMessage.DecryptMessage(RSACryptoServiceProvider decryptionKey, Boolean useOaes)

at Microsoft.Azure.SqlDatabase.ElasticScale.RsaAesHybridAlgorithmV1.Decrypt(Stream cypertextStream, Byte[] authenticator)

at Microsoft.Azure.SqlDatabase.ElasticScale.RsaPasswordDecrypter.Decrypt(Stream stream, Byte[] authenticator)

at Microsoft.Azure.SqlDatabase.ElasticScale.RsaPasswordDecrypter.Decrypt(Byte[] encryptedPassword, Byte[] authenticator)

at Microsoft.Azure.SqlDatabase.ElasticScale.RsaPasswordDecrypter.Decrypt(Byte[] encryptedPassword, Guid rowId)

at Microsoft.Azure.SqlDatabase.ElasticScale.SplitMerge.Client.SecurityUtils.GetSqlCredentials(Byte[] encryptedSecurityInfo, Guid operationId, SecurityContext securityContext)

at Microsoft.Azure.SqlDatabase.ElasticScale.SplitMerge.Client.SecurityUtils.GetFullConnectionString(Byte[] encryptedSecurityInfo, Guid operationId, SecurityContext securityContext, String connectionString)

at Microsoft.Azure.SqlDatabase.ElasticScale.SplitMerge.Worker.SplitMergeService.ExecuteOne(SqlMessageFetcher sqlMessageFetcher, Nullable`1 operationId, Boolean waitTillOperationCompletes)

--- End of inner exception stack trace ---

at Microsoft.Azure.SqlDatabase.ElasticScale.SplitMerge.Worker.SplitMergeService.ExecuteOne(SqlMessageFetcher sqlMessageFetcher, Nullable`1 operationId, Boolean waitTillOperationCompletes)

at Microsoft.Azure.SqlDatabase.ElasticScale.SplitMerge.Worker.SplitMergeService.TryExecuteOne(SqlMessageFetcher sqlMessageFetcher, MessageDeletionStrategy messageDeletionStrategy, Nullable`1 operationId)

MessageOperationId: db47ade5-012a-4025-b8fa-91bac4c01d44

ErrorCode: Internal

Status: Queued

Details: [Informational] Operation has been queued.

Split-Merge request created with OperationId: [db47ade5-012a-4025-b8fa-91bac4c01d44]
"

Checked the certificates, the are exportable and has a private key. But it looks like the certificate is not getting installed in the App Service. in the Kudo PowerShell console, I cant see the certificate installed in the Current user.

Any idea what could be the issue ?

Azure Database for MySQL
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Pratyush Vashistha 4,255 Reputation points Microsoft External Staff Moderator
    2025-10-09T03:08:13.3266667+00:00

    Hello Deepak Raj

    Thank you for asking your question on the Microsoft Q&A portal. I'm happy to help you with this.

    The error CryptographicException: Bad Key almost always points to an issue where the worker application is unable to access or use the private key of the required certificate to decrypt incoming data.

    Based on the error stack trace and your description, the issue is likely with how the certificate is being loaded and accessed by your worker App Service. Please follow these steps to diagnose and resolve the problem.

    1. This is the most common cause of this issue. Azure App Service requires this specific application setting to make an uploaded certificate accessible to your application's code from the certificate store.
      • In the Azure Portal, navigate to your Web App and your Worker App services. Under Settings -> Configuration -> Application settings, ensure you have a setting with the following:
      • Name: WEBSITE_LOAD_CERTIFICATES
      • Value: The thumbprint of the certificate you uploaded for the Split-Merge service. You can set the value to * to load all certificates, but specifying the thumbprint is more secure and recommended.
      • Important: This setting must exist and be correct on both the UI Web App and the Backend Worker App.
    2. You are correct to check this, but certificates loaded via the WEBSITE_LOAD_CERTIFICATES setting are placed in the LocalMachine store, not CurrentUser. -
      1. Open the Kudu console for your worker App Service (https://<your-app-name>.scm.azurewebsites.net/).
      2. Select PowerShell from the Debug console menu.
      3. Run the following command to list certificates in the Local Machine store that are accessible to your app:powershell
               Set-Location Cert:\LocalMachine\My
        
      4. Verify that the certificate thumbprint listed in the output exactly matches the one you uploaded and configured in the app settings.
    3. Check Certificate Consistency: The same certificate, including its private key, must be used by both the UI application (for encryption) and the worker application (for decryption).
      • Action: Confirm that the exact same .pfx file was uploaded to both the UI Web App and the Backend Worker App under Settings -> TLS/SSL settings -> Private Key Certificates (.pfx).
    4. When you export the certificate to a .pfx file, ensure you include the private key and all certificates in the certification path. Action: Re-export the certificate from your source and re-upload it to both App Services to rule out any corruption during the initial export/upload process.

    You can review the official documentation for deploying the Split-Merge service (including certificate requirements and typical troubleshooting for “Bad Key” or certificate errors) at the following fully validated Microsoft Learn link:

    https://free.blessedness.top/en-us/azure/azure-sql/database/elastic-scale-configure-deploy-split-and-merge?view=azuresql

    It states: "If you receive the following error, it's most likely a problem with your Web endpoint's certificate. Try connecting to the Web endpoint with your favorite browser or REST tool. If you see SSL errors, the certificate is either not installed or there are thumbprint issues."

    Additional Resources

    Let me know if the above works for you.

    Please "Accept as Answer" if the answer provided is useful, so that you can help others in the community looking for remediation for similar issues.

    Thanks

    Pratyush


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.