can anybody share, the best encryption and decryption technique in PHP.
here i just found 3 ways. are that any better technique?

<?php
//1
$password = 'mothafucka';
$sSalt = '8*S&AsEc4qUs';
$sHash = hash( 'whirlpool', $password . $sSalt );
echo $sHash."<br><br>";

//2
$password = "palancau87";
$password = sha1($password);
$password = md5($password);
echo $password."<br><br>";

//3
function getSalt( $iLength = 10 )
{
	$sPossible = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()-+=[]{}|';
	$iPossibleCount = strlen( $sPossible );
 
	$sSalt = '';
	for( $i=0; $i<$iLength; $i++ )
	{
		$sSalt .= $sPossible[mt_rand(0, $iPossibleCount)];
	}
 
	return $sSalt;
}
 
$sSalt = getSalt();
$sHash = hash('whirlpool', $password . $sSalt );
echo $sHash."<br><br>";
?>

Output:
52fc3756a4248bd5c059174d6d43f3579796ffb7f260451413bdc7ba821e7260f33306aa0973c6c5371632ca097deb93a6e8e54f3eb2e43035f037e74a423bad

20ccad752a137fe77724688ff82a5fd9

418b652b4a858e740202d88483636cdd181e74dc4bc25bab3b887a566e43bf9d542c0c21304b738ddb41a1735d8bdbfbe75156826bfdaa18083047a58e06103f

Recommended Answers

All 5 Replies

Do you want a hash (as shown), or do you want to be able to decrypt it? Also have a look at this thread.

Hashing is not the same thing as encryption. Your examples are all hashing.

If you need to be able to encrypt and decrypt the data than check out the php documentation for the mcrypt library.
http://php.net/manual/en/book.mcrypt.php

Do you want a hash (as shown), or do you want to be able to decrypt it? Also have a look at this thread.

3 above examples are from that link actually.
I just want to know the technique to decrypt it, so we as an admin, can echo it to view the encrypted word.

or, this encrypt technique cannot be decrypt?

See mschroeder's link, if you want en-/decryption, instead of hashes. A hash is not meant to be decrypted.

ok got it

tq

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.