I'm trying to generate a hash from a PDF. This hash should be SHA256 and Base64. I'm using a simple PDF with one line with the content: Hello World.
With the C# code below I've got the result: Gv5AR2YOxUVOjx+QFakM56Wj7CSqeZWiaVqczra/iBk=
string digest;
using (SHA256Managed sha = new SHA256Managed())
{
byte[] hash = sha.ComputeHash(pdf);
digest = Convert.ToBase64String(hash);
}
Then, using Delphi, with the code below, I've got this: wPUoG1guk2hQ5TxS5lUmaMLk83E=
// uses IdCoderMIME, IdHashSHA, IdGlobal;
var
oHash: TIdHashSHA1;
oFileStream: TFileStream;
begin
oHash := TIdHashSHA1.Create;
oFileStream := TFileStream.Create(edtPDFPath.Text, fmOpenRead);
try
result := TIdEncoderMIME.EncodeBytes(oHash.HashStream(oFileStream, 0, oFileStream.Size));
finally
Freeandnil(oFileStream);
oHash.Free
end;
I need to hash this file with Delphi but I don't know if my result is right or not.
Someone knows another way to get as a result a SHA256 Base64 hash?