Link to home
Start Free TrialLog in
Avatar of eduardo12fox
eduardo12foxFlag for Brazil

asked on

I need read XML with php and make MD5 result

Hello guys,

I have an xml file. I need to read all the contents of the tags in this xml and make the MD5 result. But I do not know how to do that.

The result of MD5 must be: 25bbb49c00aada5300c0607487eb54df


Help me please!!
TESTE_XML.xml
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

This article shows some of the design.  It's called "message authentication."
https://www.experts-exchange.com/articles/28835/Keeping-Secrets-with-PHP.html

Here's an example.
<?php // demo/temp_eduardo.php
/**
 * https://www.experts-exchange.com/questions/29027519/I-need-read-XML-with-php-and-make-MD5-result.html
 */
error_reporting(E_ALL);

$url = 'https://filedb.experts-exchange.com/incoming/2017/06_w23/1166541/TESTE_XML.xml';
$txt = file_get_contents($url);
$md5 = md5($url);
echo $md5;

Open in new window

Avatar of eduardo12fox

ASKER

You are wrong. The result of your rash is: b2289a42f7e326ac80375f2072dd7f86

the correct is: 25bbb49c00aada5300c0607487eb54df

in xml on tag: <ans:hash>25bbb49c00aada5300c0607487eb54df</ans:hash>

is only show result correct,   if I erase this tag the result with you code not is: 25bbb49c00aada5300c0607487eb54df is other
Apologies, I made a mistake in the first code snippet.  This should make more sense!
<?php // demo/temp_eduardo.php
/**
 * https://www.experts-exchange.com/questions/29027519/I-need-read-XML-with-php-and-make-MD5-result.html
 */
error_reporting(E_ALL);

$url = 'https://filedb.experts-exchange.com/incoming/2017/06_w23/1166541/TESTE_XML.xml';
$txt = file_get_contents($url);
$md5 = md5($txt);
echo $md5;

Open in new window

Now, by way of explanation, let me try to explain why my script may produce a different md5() instead of 25bbb49c00aada5300c0607487eb54df.

The md5() string is idempotent, meaning that every time you call md5() with the same input, you get the same output.  But "same input" is the key.  A variation of even one character in the input string will result in dramatically different md5() results.  This variation extends to every single character in the input string, even including invisible whitespace, end-of-line characters, etc.  You can read a document into a text editor and save it without any apparent changes, and the editor can turn spaces into tabs, etc.  Any change, no matter how small, will cause a different md5() result.

A more common design for message authentication takes the form of something like this (pidgin XML).
<message>Hello World</message>
<md5string>b10a8db164e0754105b7a99be72e3fe5</md5string>

Open in new window

In this kind of design the message and md5() string are packaged together.  When the XML is received, the message is extracted and the md5() string is made from the message.  This is compared against the md5() part of the XML document.  A match means the message arrived intact.

So when we see something like this in the XML document, what we really need to know is "what fields were used as the input to the md5()?"
<ans:hash>25bbb49c00aada5300c0607487eb54df</ans:hash>

Open in new window

I understand but how solution you give me? Because I need get correct md5
What are the input fields used to create the md5()?  Is there any documentation that describes how the publisher of this XML document created the "ans:hash" value?
All fild but the tag <ans:hash></ans:hash> have empty. I put value for you have idea about result. but this tag is empty
if you get all field and make md5 result have: 25bbb49c00aada5300c0607487eb54df

with tag <ans:hash></ans:hash> empty.

This result of MD5 I put after into tag: <ans:hash></ans:hash>  Do you understand?   :D
I think so.  Let me experiment with it a bit.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perfect! Perfect! Solved my problem. Thank you, God bless you.   :D
Thanks for the points -- it's a really great question!