Okay.. so I've been poking around with encryption things.. looking through the PHP manual and whatnot.. I looked up CAST_256 encryption and it seems to be quite good (as far as the documentation on it goes) .. has anyone ever heard bad things about it? I couldn't find much.
But, beyond that, my encrypt() and decrypt() functions I wrote aren't producing the results I want..
What is happening, is I encode the text using a key specified (from a form, for now), and then it writes the crypted text to a file. Then it asks for the key, and it tries to decrypt it. What is happening is when it tries to decrypt it, the first line is complete garbage then the rest of the text is as it was before it was encrypted. what could the problem be? here are my two functions:
function encrypt($key, $plain_text) {
// returns encrypted text
// incoming: should be the $key that was encrypt
// with and the $plain_text that wants to be encrypted
$iv = mcrypt_create_iv (mcrypt_get_iv_size (MCRYPT_CAST_256, MCRYPT_MODE_CF😎, MCRYPT_URANDOM);
$c_t = trim(base64_encode(mcrypt_cfb (MCRYPT_CAST_256, $key, $plain_text, MCRYPT_ENCRYPT, $iv)));
return $c_t;
}
function decrypt($key, $c_t) {
// incoming: should be the $key that you encrypted
// with and the $c_t (encrypted text)
// returns plain text
$c_t = trim(base64_decode($c_t));
$iv = mcrypt_create_iv (mcrypt_get_iv_size (MCRYPT_CAST_256, MCRYPT_MODE_CF😎, MCRYPT_URANDOM);
$p_t = mcrypt_cfb (MCRYPT_CAST_256, $key, $c_t, MCRYPT_DECRYPT, $iv);
return $p_t;
}
thanks for input,
kyle