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

Announcements

News and Announcements icon
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


 
 
 
Categories:
I have the same question (0)
  • Anton Venter Profile Picture
    20,694 Super User 2026 Season 1 on at
    @Ayushaman
     
    Your error message is telling you exactly what's wrong ("The given key was not present in the dictionary"). I can only assume that somehow the key was added in UAT and the code seems to be finding it in UAT. But in Prod the key cannot be found.
     
    I have two questions: what are your requirements and why are you using RSA?
     
  • Jonas "Jones" Melgaard Profile Picture
    5,016 Most Valuable Professional on at
    Moved from FastTrack to Finance

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

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

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

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 565 Super User 2026 Season 1

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 487 Super User 2026 Season 1

#3
Subra Profile Picture

Subra 413

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans