LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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
 
Thread Tools
Old 08-24-2006, 04:23 AM   #1
baikonur
Member
 
Registered: Oct 2005
Location: germany
Distribution: debian
Posts: 245
Blog Entries: 5
Thanked: 0
md5() function in php gives different result than md5sum on linux


[Log in to get rid of this advertisement]
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!
baikonur is offline     Reply With Quote
Old 08-24-2006, 05:15 AM   #2
Flesym
Member
 
Registered: Aug 2005
Location: Germany
Distribution: Ubuntu, Debian
Posts: 189
Thanked: 0
"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
Flesym is offline     Reply With Quote
Old 08-24-2006, 05:41 AM   #3
baikonur
Member
 
Registered: Oct 2005
Location: germany
Distribution: debian
Posts: 245
Blog Entries: 5
Thanked: 0

Original Poster
Thanks!

Michael
baikonur is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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


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


All times are GMT -5. The time now is 11:02 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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration