web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

RSA Encryption Failure in D365FO Prod – KeyNotFoundException

(1) ShareShare
ReportReport
Posted on by 275

  public static str encryptWithPublicKey(str jsonPayload, str publicKeyXml)
  {
    System.Exception     netException;
    System.Security.Cryptography.RSACryptoServiceProvider rsa;
    System.Text.Encoding encoding;
    System.Byte[]        payloadBytes;
    System.Byte[]        encryptedBytes;
    str                  base64Encrypted;
        
    try
    {
     
      rsa = new System.Security.Cryptography.RSACryptoServiceProvider();
            
     
      rsa.FromXmlString(publicKeyXml);
            
     
      encoding = System.Text.Encoding::get_UTF8();
            
     
      payloadBytes = encoding.GetBytes(jsonPayload);
            
     
      encryptedBytes = rsa.Encrypt(payloadBytes, false);
     
      base64Encrypted = System.Convert::ToBase64String(encryptedBytes);
    }
    catch(netException)
    {
      error(strFmt("Encryption failed: %1", netException.ToString()));
      return "";
    }
        
    return base64Encrypted;
  }

Hello,

I am implementing RSA encryption of JSON data in D365FO using a public key extracted from a .pem file.

The solution works correctly in UAT and Performance, but fails in Production with the following error during batch execution:

Unable to find manual secret value
The given key was not present in the dictionary
Batch task failed: KeyNotFoundException

Initially, the public key was read from Azure Key Vault. To rule this out, I moved the key to a table memo field, but the same error occurs in Production only.

Since the code and configuration are identical across environments, I suspect a production-specific issue related to encryption handling, batch execution context or security (not aware if their is )

Any guidance on resolving this would be appreciated.

Regards,
Ayushaman


 
 
 
I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 679 Super User 2025 Season 2

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 421 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 282 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans