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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Unanswered

http request body is not decrypted

(1) ShareShare
ReportReport
Posted on by 12
Dear Team,
 
I am trying to send encrypted request in navision 2016 to third part but im getting below error .I am using AES encryption .Below is my code .can anyone suggest .When i try using postman then below response i'm getting .
Error during decryption. Request could be invalid/
 
Microsoft Dynamics NAV
---------------------------
A call to System.Net.HttpWebRequest.GetResponse failed with this message: The remote server returned an error: (500) Internal Server Error.
---------------------------
OK
---------------------------
 

HttpWebRequest:=HttpWebRequest.Create(url);
HttpWebRequest.Method:='POST';
HttpWebRequest.ContentType:='application/json';
ServicePointManager.SecurityProtocol := SecurityProtocolType.Tls12;
X509Certificate2:=X509Certificate2.X509Certificate2;
X509Certificate2:=X509Certificate2.X509Certificate2('C://Program Files//OpenSSL-Win64//OpenSSL-Win64//bin//abc.p12','abc@123');
//HttpWebRequest.GetRequestStream();
HttpWebRequest.Headers.Add('X-IBM-Client-Id',GLsetup./X-IBM-Client-Id/);
HttpWebRequest.Headers.Add('X-IBM-Client-Secret',GLsetup./X-IBM-Client-Secret/);
HttpWebRequest.ClientCertificates.Add(X509Certificate2);
CreateJson1(JsonObject,Rec);
JsonString:=JsonObject.ToString;
IF ISNULL(aes) THEN
aes:=aes.Create;
aes.Key:=Encoding.UTF8.GetBytes('YDJHBDKEQBSENBEFELJK');
aes.IV:=Encoding.UTF8.GetBytes('0123456789abcdef');
aes.GenerateIV;
aes.Mode:=CipherMode.CBC;
aes.Padding:=Padding.PKCS7;
aes.FeedbackSize:=128;
Encryptor:=aes.CreateEncryptor();
msEncrypt:=msEncrypt.MemoryStream;
csEncrypt:=csEncrypt.CryptoStream(msEncrypt,Encryptor,CryptoStreamMode.Write);
cs1:=csEncrypt.ToString;
swEncrypt:=swEncrypt.StreamWriter(csEncrypt,Encoding.UTF8);
swEncrypt.Write(JsonString);
Encoded:=Convert.ToBase64String(msEncrypt.ToArray);
//--
CreateJson(JsonObject1,Rec,Encoded);
JsonString1:=JsonObject1.ToString;
MESSAGE(JsonString1);
//--
RequestStr := HttpWebRequest.GetRequestStream;
StreamWriter := StreamWriter.StreamWriter(RequestStr,Encoding.UTF8);
//StreamWriter := StreamWriter.StreamWriter(RequestStr);
StreamWriter.Write(JsonString1);
StreamWriter.Flush;
StreamWriter.Close;
StreamWriter.Dispose;
HttpWebResponse:=HttpWebRequest.GetResponse;
IF FORMAT(HttpWebResponse.StatusCode)='OK' THEN BEGIN
 StreamReader:=StreamReader.StreamReader(HttpWebResponse.GetResponseStream);
JsonString2:=StreamReader.ReadToEnd;
  END;
 
 
 
 
 
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

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 > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,238

#2
YUN ZHU Profile Picture

YUN ZHU 773 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 630

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans