MD5 Hash of StringList

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

MD5 Hash of StringList

Zaaphod
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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: MD5 Hash of StringList

Bo Berglund
On Thu, 4 Jul 2019 11:33:02 -0400, "James Richters"
<[hidden email]> 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

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: MD5 Hash of StringList

Zaaphod
Thanks you!

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

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

James

-----Original Message-----
From: fpc-pascal <[hidden email]> On Behalf Of Bo Berglund
Sent: Thursday, July 4, 2019 11:49 AM
To: [hidden email]
Subject: Re: [fpc-pascal] MD5 Hash of StringList

On Thu, 4 Jul 2019 11:33:02 -0400, "James Richters"
<[hidden email]> 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

_______________________________________________
fpc-pascal maillist  -  [hidden email] https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: MD5 Hash of StringList

José Mejuto
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.

--

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: MD5 Hash of StringList

Bo Berglund
On Thu, 4 Jul 2019 18:13:44 +0200, José Mejuto
<[hidden email]> 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?


--
Bo Berglund
Developer in Sweden

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: MD5 Hash of StringList

Tony Whyman
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.

On 04/07/2019 23:58, Bo Berglund wrote:

> On Thu, 4 Jul 2019 18:13:44 +0200, José Mejuto
> <[hidden email]> 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?
>
>
_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal