Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2019-07

MD5 Hash of StringList

6 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

James Richters

I'm trying to figure out how to make an MD5 Hash from an entire StringList. I am referencing the documentation here:
https://wiki.freepascal.org/hash

and I see how to make an MD5 Hash from a File, or from a single string, but I do not see how to make an MD5 Hash from something like a String List. It mentions: 'There are routines to calculate hashes from some buffer, or a hash from an entire file.' So how does one make an MD5 Hash from 'some buffer' ?

Is there a simple way I can create an MD5 Hash from my entire stringlist, or do I have to add the strings into some sort of buffer myself and then get the hash from that?

Any advice is greatly appreciated

James

Reply by email

Bo Berglund
to James Richters
"James Richters" wrote 9 lines
I'm trying to figure out how to make an MD5 Hash from an entire StringList. I am referencing the documentation here: https://wiki.freepascal.org/hash and I see how to make an MD5 Hash from a File, or from a single string, but I do not see how to make an MD5 Hash from something like a String List. It mentions: 'There are routines to calculate hashes from some buffer, or a hash from an entire file.' So how does one make an MD5 Hash from 'some buffer' ? Is there a simple way I can create an MD5 Hash from my entire stringlist, or do I have to add the strings into some sort of buffer myself and then get the hash from that? Any advice is greatly appreciated

Maybe:

 hash := Md5Hash(MyStringlist.Text);

I don't know the call to the MD5hash creator, but the content of the stringlist is available as property Text...

Bo Berglund Developer in Sweden

Reply by email

James Richters
to Bo Berglund

Thanks you!

That got me on the right path.
Here's the working sample:

Hash  := Md5Print(MD5String(MyStringlist.Text));

James

Earlier message 30 lines
-----Original Message----- From: fpc-pascal On Behalf Of Bo Berglund Sent: Thursday, July 4, 2019 11:49 AM To: Subject: Re: [fpc-pascal] MD5 Hash of StringList On Thu, 4 Jul 2019 11:33:02 -0400, "James Richters" wrote: >I'm trying to figure out how to make an MD5 Hash from an entire StringList. > I am referencing the documentation here: >https://wiki.freepascal.org/hash > >and I see how to make an MD5 Hash from a File, or from a single string, but I do not see how to make an MD5 Hash from something like a String List. It mentions: 'There are routines to calculate hashes from some buffer, or a hash from an entire file.' So how does one make an MD5 Hash from 'some buffer' ? > >Is there a simple way I can create an MD5 Hash from my entire stringlist, or do I have to add the strings into some sort of buffer myself and then get the hash from that? > >Any advice is greatly appreciated Maybe: hash := Md5Hash(MyStringlist.Text); I don't know the call to the MD5hash creator, but the content of the stringlist is available as property Text... -- Bo Berglund Developer in Sweden

Reply by email

José Mejuto
to James Richters
James Richters wrote 7 lines
Thanks you! That got me on the right path. Here's the working sample: Hash := Md5Print(MD5String(MyStringlist.Text));

Warning! That's platform dependent code due the new line sequences.

Reply by email

Bo Berglund
to José Mejuto
José Mejuto wrote 10 lines
El 04/07/2019 a las 18:13, James Richters escribió: > Thanks you! > > That got me on the right path. > Here's the working sample: > > Hash := Md5Print(MD5String(MyStringlist.Text)); > Warning! That's platform dependent code due the new line sequences.

Maybe:

MyStringList.LineBreak := #10;
Hash  := Md5Print(MD5String(MyStringlist.Text));

Then the new line issue may be solved?

Bo Berglund Developer in Sweden

Reply by email

Tony Whyman
to Bo Berglund

Be careful, the code below is codepage dependent. TStrings.GetTextStr does not inspect the codepage of each string and simply moves the characters into a common buffer. Fast, but the question is: are you using the hash to compare two string lists that are binary equivalent or two string lists that contain the same unicode characters. The code below only guarantees to answer the first question.

Bo Berglund wrote 20 lines
On Thu, 4 Jul 2019 18:13:44 +0200, José Mejuto wrote: > El 04/07/2019 a las 18:13, James Richters escribió: >> Thanks you! >> >> That got me on the right path. >> Here's the working sample: >> >> Hash := Md5Print(MD5String(MyStringlist.Text)); >> > Warning! That's platform dependent code due the new line sequences. Maybe: MyStringList.LineBreak := #10; Hash := Md5Print(MD5String(MyStringlist.Text)); Then the new line issue may be solved?

Reply by email