How to Calculate the Hash of a PDF File

Xbase++ 2.0 Build 554 or later
Post Reply
Message
Author
User avatar
PedroAlex
Posts: 234
Joined: Tue Feb 09, 2010 3:06 am

How to Calculate the Hash of a PDF File

#1 Post 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
Pedro Alexandre

User avatar
Tom
Posts: 1205
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: How to Calculate the Hash of a PDF File

#2 Post by Tom »

Use

Code: Select all

Char2Hash(<cStream>)
and set

Code: Select all

SET HASH TO MD5
before.
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

User avatar
PedroAlex
Posts: 234
Joined: Tue Feb 09, 2010 3:06 am

Re: How to Calculate the Hash of a PDF File

#3 Post by PedroAlex »

Tom.
Many thanks !

How get the "csTream" ?

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

User avatar
rdonnay
Site Admin
Posts: 4775
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: How to Calculate the Hash of a PDF File

#4 Post 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++?
The eXpress train is coming - and it has more cars.

User avatar
Tom
Posts: 1205
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: How to Calculate the Hash of a PDF File

#5 Post 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.
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

User avatar
PedroAlex
Posts: 234
Joined: Tue Feb 09, 2010 3:06 am

Re: How to Calculate the Hash of a PDF File

#6 Post 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.
Pedro Alexandre

Post Reply