md5 vs sha1 in php
Table of Contents
md5 vs sha1:
Cryptographic technics needs to be implemented in all the areas of web developments mainly user details,
payment gateway pages etc. to make our system more secure. we have lot of cryptographic technics and today we are going to see md5 and sha1, because these both technics plays more role to make the systems secure.
md5 and sha1’s are really encryption technics ?
No. md5 and sha1’s are really not a encryption technics, which means md5 hash value of any string will not have the original string message in the converted md5 hash value and also all these technics does not have the decryption’s.
These technics are one way converted hash values, meaning we can not retrieve the original string from the converted md5 or sha1 hash values.
md5 vs sha1 in php:
md5($str) is the function to convert the string to md5 hash value in php.
sha1($str) is the function to convert the string to sha1 hash value in php.
md5:
String : javadomain
md5 hash value : 8f073ae245bb59ebca66a50bee739a84
Bit : 128 bit
Byte : 16 byte
PHP : md5($inputString);
Digit : 32 digit [md5 hash value digit]
sha1:
String : javadomain
sha1 hash value : b95e71d3d08f56001649122c62f78c291b447620
Bit : 160 bit
Byte : 20 byte
PHP : sha1($inputString);
Digit : 40 digit [sha1 hash value digit]
md5 vs sha1 – recommended ?:
As the md5 number of digits is more than sha1 number of digits, sha1 is recommended algorithm.
md5 and sha1 in PHP source code:
[php highlight=”7,15″]
<?php
header(‘Content-type: text/plain’);
$srcValue = "ngdeveloper.com";
// string to md5 convert
$md5_value = md5($srcValue);
echo "md5 hash value : ".$md5_value;
echo "\n";
// string to sha1 convert
$sha1_value = sha1($srcValue);
echo "sha1 hash value : ".$sha1_value;
?>
[/php]
Output:
[plain]</pre>
<pre>md5 hash value : 5d6790c8c8ddebc1821ceb030feec14b
sha1 hash value : 625b408544bbb31dc6d439b9bf0b0e4bc7d1efca</pre>
<pre>
[/plain]
PHP Recommended Books:
Feed free to post your comments/suggestions in the below comment section..