Page 1 of 1

How to Calculate the Hash of a PDF File

Posted: Fri Mar 26, 2021 4:19 am
by PedroAlex
Hello!

How to Calculate the Hash of a PDF File
Does anyone know how to calculate the hash of a pdf or jpg file using Xbase ++?

Something like that:

' VB.NET
Dim Imagem = "imagem.jpg"
Dim HashImagem = CalcularHash(Imagem)
Dim HashImagemString = BitConverter.ToString(HashImagem).Replace("-", "").ToLower()
Console.WriteLine(HashImagemString)

' VB.NET
Private Function CalcularHash(Arquivo As String) As Byte()
Using Md5 = System.Security.Cryptography.MD5.Create()
Using Stream = System.IO.File.OpenRead(Arquivo)
Return Md5.ComputeHash(Stream)
End Using
End Using
End Function

Re: How to Calculate the Hash of a PDF File

Posted: Fri Mar 26, 2021 4:49 am
by Tom
Use

Code: Select all

Char2Hash(<cStream>)
and set

Code: Select all

SET HASH TO MD5
before.

Re: How to Calculate the Hash of a PDF File

Posted: Fri Mar 26, 2021 4:56 am
by PedroAlex
Tom.
Many thanks !

How get the "csTream" ?

cStream := Memoread('File.Pdf') !?

Re: How to Calculate the Hash of a PDF File

Posted: Fri Mar 26, 2021 6:09 am
by rdonnay
Wow. I have been using a 3rd party library for doing MD5 hash for a long time.

How long has this been in Xbase++?

Re: How to Calculate the Hash of a PDF File

Posted: Fri Mar 26, 2021 7:12 am
by Tom
@Pedro: I prefer FileStr(), but, yeah, this is the way to get the binary string to create the hash from.

@Roger: I think since two, three years, but, nowadays, time seems to go by faster in reality than in my memory.
Edit: Introduced in 2.00.1271, whenever that was.

Re: How to Calculate the Hash of a PDF File

Posted: Fri Mar 26, 2021 8:01 am
by PedroAlex
Tom,
Many thanks !

Roger,
The MD5 Hash Algorithm only became available in 2020

the Char2Hash() "MD5" parameter was only available on Build 1271 - 29-06-2020.