md5 vs sha1 in php

converting string to md5 and sha1 in php (Last Updated On: August 11, 2016)

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.

 

demo

 

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
header('Content-type: text/plain');
$srcValue = "javadomain.in";

// 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;

?>

 

Output:

</pre>
<pre>md5 hash value  :  5d6790c8c8ddebc1821ceb030feec14b
sha1 hash value :  625b408544bbb31dc6d439b9bf0b0e4bc7d1efca</pre>
<pre>

 

md5 vs sha1

 

PHP Recommended Books:

Feed free to post your comments/suggestions in the below comment section..

379 total views, 0 views today

Leave a Reply

Your email address will not be published. Required fields are marked *