Cryptography Management and TempBlob

FrancescoLanza
Member Posts: 1
Hello Everyone,
I'm trying to do something that is harder than expected.
I have to send a file (a pdf report, for example), via httprequest with multipart form-data.
I managed to do that, only working with the tempblob codeunit (it has to be compatible with cloud environment).
The problem is that the provider receiving the file also want the SHA256 hash of the file.
Now, the procedure to get the sha256 hash is preatty simple:
+++++++++++++++++CLOUD code+++++++++++++++++++++++++++
TempBlob.CreateOutStream(OutStream);
SalesInvoiceHeader2.get('22-XXXXX'); //example No.
RecRef.GetTable(SalesInvoiceHeader2);
RecRef.SetRecFilter();
if REPORT.SaveAs(gRecSelection."Report ID", '', ReportFormat::Pdf, OutStream, RecRef) then begin
TempBlob.CreateInStream(InStream);
end;
HashValue := CU_CryptographyMgmt.GenerateHash(Instream, Algorithm::SHA256);
++++++++++++++++++++++++++++++++++++++++++++
I got the hash value according to the system app.
Unfortunately, there is not a reliable hash, and when I send the form to the provider, with the Instream octect-stream and the json with the hash value calculated in that way, I got an error: hash value incorrect.
At first I thought it was an error of the webservice I was consuming, but I tried something else.
First of all, I downloded the stream with a filename, and if I check the hash of the file I got, is the same that the provider wants.
Then I tried to to the same thing, but not for cloud:
+++++++++++++++++++++On prem Code++++++++++++++++++++++++++++++
SalesInvoiceHeader2.get('22-XXXXX');
SalesInvoiceHeader2.SetRecFilter();
report.SaveAsPdf(gRecSelection."Report ID", 'C:\temp\' + format(SalesInvoiceHeader2."No.") + '.pdf', SalesInvoiceHeader2);
Pdffile.Open('C:\temp\' + format(SalesInvoiceHeader."No.") + '.pdf');
Pdffile.CreateInStream(PdfInstream);
HashValue := CU_CryptographyMgmt.GenerateHash(PdfInstream, Algorithm::SHA256);
Pdffile.Close();
+++++++++++++++++++++++++++++++++++++++++++++++++++
(Pdffile is a File type variable, of course)
in THIS way, the hash is perfectly the same the provider wants.
How can I do this to be coud frienly? This must to go in a SaaS environment and at this time I don't see how.
Suggestions?
Cheers
Francesco
I'm trying to do something that is harder than expected.
I have to send a file (a pdf report, for example), via httprequest with multipart form-data.
I managed to do that, only working with the tempblob codeunit (it has to be compatible with cloud environment).
The problem is that the provider receiving the file also want the SHA256 hash of the file.
Now, the procedure to get the sha256 hash is preatty simple:
+++++++++++++++++CLOUD code+++++++++++++++++++++++++++
TempBlob.CreateOutStream(OutStream);
SalesInvoiceHeader2.get('22-XXXXX'); //example No.
RecRef.GetTable(SalesInvoiceHeader2);
RecRef.SetRecFilter();
if REPORT.SaveAs(gRecSelection."Report ID", '', ReportFormat::Pdf, OutStream, RecRef) then begin
TempBlob.CreateInStream(InStream);
end;
HashValue := CU_CryptographyMgmt.GenerateHash(Instream, Algorithm::SHA256);
++++++++++++++++++++++++++++++++++++++++++++
I got the hash value according to the system app.
Unfortunately, there is not a reliable hash, and when I send the form to the provider, with the Instream octect-stream and the json with the hash value calculated in that way, I got an error: hash value incorrect.
At first I thought it was an error of the webservice I was consuming, but I tried something else.
First of all, I downloded the stream with a filename, and if I check the hash of the file I got, is the same that the provider wants.
Then I tried to to the same thing, but not for cloud:
+++++++++++++++++++++On prem Code++++++++++++++++++++++++++++++
SalesInvoiceHeader2.get('22-XXXXX');
SalesInvoiceHeader2.SetRecFilter();
report.SaveAsPdf(gRecSelection."Report ID", 'C:\temp\' + format(SalesInvoiceHeader2."No.") + '.pdf', SalesInvoiceHeader2);
Pdffile.Open('C:\temp\' + format(SalesInvoiceHeader."No.") + '.pdf');
Pdffile.CreateInStream(PdfInstream);
HashValue := CU_CryptographyMgmt.GenerateHash(PdfInstream, Algorithm::SHA256);
Pdffile.Close();
+++++++++++++++++++++++++++++++++++++++++++++++++++
(Pdffile is a File type variable, of course)
in THIS way, the hash is perfectly the same the provider wants.
How can I do this to be coud frienly? This must to go in a SaaS environment and at this time I don't see how.
Suggestions?
Cheers
Francesco
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions