
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