hi Seth,
vincent is right about the hacker thing.
If you want to store passwords I'd suggest to use md5 and comparing the hashes.
If you're talking about large amounts of date I'd recommend the code below. It's using the RC4 algorithm - note that this is not very good encryption today but it'll suit most uses. Again, it won't stop a hacker.
Last note: The code below is my modified version of the original script found here: http://sourceforge.net/projects/rc4crypt/
It speeds up encryption/decryption by somewhat of 13%. If you want to understand the code I'd recommend the original version. For further speedup I'd recommend gzipping/gunzipping the data prior to encryption/decryption, the functions are fast enough.
Here we go:
//--------------------
function rc4 ($pwd, $data) {
$key[] = "";
$box[] = "";
$temp_swap = "";
$pwd_length = strlen($pwd);
$cipher = "";
$j = 0;
$dl = strlen($data);
for ($i = 0; $i < 256; $i++) {
$key[$i] = ord($pwd[$i % $pwd_length]);
$box[$i] = $i;
}
for ($i = 0; $i < 256; $i++) {
$x = ($x + $box[$i] + $key[$i]) % 256;
$temp_swap = $box[$i];
$box[$i] = $box[$x];
$box[$x] = $temp_swap;
}
for ($i = 0; $i < $dl; $i++) {
$a = ($a + 1) % 256;
$j = ($j + $box[$a]) % 256;
$temp = $box[$a];
$box[$a] = $box[$j];
$box[$j] = $temp;
$k = $box[(($box[$a] + $box[$j]) % 256)];
$cipher .= chr(ord($data[$i]) ^ $k);
}
return $cipher;
}
//--------------------
It can be used for both encrytion and decryption.
Hope that helps,
Dominique