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

Announcements

No record found.

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,629 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,008 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
André Arnaud de Calavon Profile Picture

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

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 349

#3
Diego Mancassola Profile Picture

Diego Mancassola 263

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans