LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 08-24-2006, 03:23 AM   #1
baikonur
Member
 
Registered: Oct 2005
Location: germany
Distribution: debian
Posts: 255
Blog Entries: 5

Rep: Reputation: 30
md5() function in php gives different result than md5sum on linux


when I run this on my command line:
Code:
echo apple | md5sum
I get:
Code:
30c6677b833454ad2df762d3c98d2409
whereas the result of this PHP-Code
Code:
	$md5test=md5('apple');
	echo	$md5test;
is
Code:
1f3870be274f6c49b3e31a0c6728957f
I deliberately took the example of the manual and verified it on my apache-server, the result is the same. Then again, I cross-checked the output of md5sum with a md5-generator on the internet, and got that checksum again. Both functions, the php-function and the command-line program use RFC 1321.

Why are there two outputs for the very same string?

Any hint would be nice!
 
Old 08-24-2006, 04:15 AM   #2
Flesym
Member
 
Registered: Aug 2005
Location: Germany
Distribution: Ubuntu, Debian
Posts: 189

Rep: Reputation: 31
"echo" prints a line of text. I.e. the text itself plus a newline.
Code:
echo apple | md5sum
...pipes the string "apple\n" to md5sum which is different from "apple".

If you don't want that newline at the end, then you can pass -n to echo:
Code:
echo -n apple | md5sum
...will output:
Code:
1f3870be274f6c49b3e31a0c6728957f
 
Old 08-24-2006, 04:41 AM   #3
baikonur
Member
 
Registered: Oct 2005
Location: germany
Distribution: debian
Posts: 255
Blog Entries: 5

Original Poster
Rep: Reputation: 30
Thanks!

Michael
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
select query thru php outputs no result suchi_sood Programming 1 04-11-2006 10:21 AM
md5, SHA and php's mcrypt function rjcrews General 1 12-05-2005 12:54 AM
Passing one php function result as a parameter to another php function davee Programming 13 09-12-2004 12:08 PM
php: output the result of exec( $command ) zovres Programming 6 08-27-2004 06:41 PM
md5sum showing difference result everytime!! ngan_yine Linux - Newbie 9 02-16-2004 05:19 AM


All times are GMT -5. The time now is 09:40 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration