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

(0) ShareShare
ReportReport
Posted on by 8
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;
 
 
 
 
 

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,401 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans