Friday, January 30, 2009

Quick Solution to String Encryption (MD5 and SHA)

For a fast solution to string encryption or verify MD5 hash, PHP provides a very simple function for encrypting string or displaying hash key in either SHA or MD5 algorithm.

As for encryption:
The pro is simplicity.
The con is you don't get to define the salt.

methods for encrypting string
$encrypted_MD5_Str = md5($string);
$encrypted_SHA_Str = sha1($string);

methods for displaying hash key
$filename = "test.gz";
echo "MD5 hash value is: ".md5_file($filename);
echo "SHA1 hash value is: ".sha1_file($filename);

1 comment:

  1. Thanks for these quick solution to verify if the encryption done on the string is accurate or not. I will do try all these methods posted. But its not easy for a new user to learn about they actually work.
    digital signature FAQ