Cryptography Management and TempBlob

FrancescoLanzaFrancescoLanza Member Posts: 1
edited 2022-11-18 in General Chat
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+++++++++++++++++++++++++++

SalesInvoiceHeader2.get('22-XXXXX'); //example No.
if REPORT.SaveAs(gRecSelection."Report ID", '', ReportFormat::Pdf, OutStream, RecRef) then begin
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++++++++++++++++++++++++++++++
report.SaveAsPdf(gRecSelection."Report ID", 'C:\temp\' + format(SalesInvoiceHeader2."No.") + '.pdf', SalesInvoiceHeader2);
Pdffile.Open('C:\temp\' + format(SalesInvoiceHeader."No.") + '.pdf');
HashValue := CU_CryptographyMgmt.GenerateHash(PdfInstream, Algorithm::SHA256);

(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.

Sign In or Register to comment.