note 50169 added to function.sha1

From: Date: Sun, 20 Feb 2005 13:26:58 +0000
Subject: note 50169 added to function.sha1
Groups: php.notes 
Request: Send a blank email to php-notes+get-85282@lists.php.net to get a copy of this message
Wanna use SHA-2 algorithm? Try this: Download Tar-Ball from http://www.adg.us/computers/sha.html Compile (may occur some warnings) and test it: cc -O2 -DSHA2_UNROLL_TRANSFORM -Wall -o sha2 sha2prog.c sha2.c ./sha2test.pl Copy it to /usr/local/bin/ (don't forget to check permissions) Here are two functions that could be used with: function sha2($bits, $string){ $sha2bin="/usr/local/bin/sha2"; $echocmd="echo"; if(!in_array($bits, array(256, 384, 512)))return(false); $r=exec($echocmd." ".escapeshellarg($string)."|".$sha2bin." -q -".$bits, $sha2); return($sha2[0]); } function sha2_file($bits, $filename){ $sha2bin="/usr/local/bin/sha2"; if(!in_array($bits, array(256, 384, 512)))return(false); if(!file_exists($filename)||!is_readable($filename))return(false); $r=exec($sha2bin." -q -".$bits." ".escapeshellarg($filename), $sha2); return($sha2[0]); } and use it like below: <?php $str = 'apple'; if (sha2(256, $str) === '303980bcb9e9e6cdec515230791af8b0ab1aaa244b58a8d99152673aa22197d0') { echo "Would you like a green or red apple?"; exit; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.sha1.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+50169 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50169&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50169&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50169&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50169&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50169&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+50169&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#85282) next »