Blowfish Encryption not working
Posted: Wed Mar 26, 2008 1:21 am
I would put this in security but it's more code than theory.
Those are my two functions. Here they are in use:
The result is nothing. I don't really see what I'm doing wrong though. The first function produces a cipher which consists of the encoded encrypted message and the encoded IV string in an array. The second function (decrypt function) takes that cypher along with the key and attempts to decrypt the message. Cans someone explain where I went wrong? Thanks.
Code: Select all
public function encryptBlowFish($key, $data)
{
$iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_CBC);
$iv = mcrypt_create_iv($iv_size, MCRYPT_DEV_URANDOM);
$data = mcrypt_encrypt(MCRYPT_BLOWFISH, $key,
$data, MCRYPT_MODE_CBC, $iv);
return array(base64_encode($data), base64_encode($iv));
}
public function decryptBlowFish($cyph, $key)
{
$out = mcrypt_decrypt(MCRYPT_BLOWFISH, $key, base64_decode($cyph[0]),
MCRYPT_MODE_CBC, base64_decode($cyph[1]));
return trim($out);
}Code: Select all
$test = $cell->protein->getProtein("Encrypt");
$cyph = $test->encryptBlowFish("mypass", "mysecmessage");
echo $test->decryptBlowFish($cyph, "mypass");