Use the mcrypt library of functions available for encryption and decryption:
http://us3.php.net/manual/en/ref.mcrypt.php
Example:
<?PHP
define('MY_KEY', 'A very secret key');
//Encryption
function encrypt($input, &$iv) // Pass IV by reference
{
$td = mcrypt_module_open(MCRYPT_3DES, '', MCRYPT_MODE_ECB, '');
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
mcrypt_generic_init($td, MY_KEY, $iv);
$encrypted_data = mcrypt_generic($td, $input);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
$iv = trim(base64_encode($iv));
return trim(base64_encode($encrypted_data));
}
//Decryption
function decrypt($input, $iv)
{
$input = base64_decode($input);
$iv = base64_decode($iv);
$td = mcrypt_module_open(MCRYPT_3DES, '', MCRYPT_MODE_ECB, '');
mcrypt_generic_init($td, MY_KEY, $iv);
$decrypt = trim(mdecrypt_generic($td, $input));
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return $decrypt;
}
$data = 'Hello World!';
echo "Original data: $data <br>";
$IV = '';
$encrypted = encrypt($data, $IV);
// Save $encrypted and $IV values in file/DB.
echo "encrypted: $encrypted <br>";
echo "IV: $IV <br>";
// Retrieve values from file/DB and place in $encrypted and $IV
$unencrypted = decrypt($encrypted, $IV);
echo "decrypted data: $unencrypted <br>";
?>
Example of output:
Original data: Hello World!
encrypted: zZh/1vef0sS6Y+YyAsSmxQ==
IV: 5Fl6lc4xjwA=
decrypted data: Hello World!
Also, there's a PEAR blowfish encryption and decryption function that doesn't require the mcrypt library - see my post for the link to the class:
http://www.phpbuilder.com/board/showpost.php?p=10651372&postcount=16
When user has to enter personal or sensitive information, use SSL.
hth.