|
Posted by BKDotCom on 11/07/49 11:31
what kind of key do you need?
a simple encrypt/decrypt key, or a public/private key?
here's blowfish encryption using the mcrypt library
// returns base64_encoded string
function encrypt_blowfish($key,$data)
{
$mode = MCRYPT_MODE_CBC;
$iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, $mode);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$encrypted = $iv.mcrypt_encrypt(MCRYPT_BLOWFISH, $key, $data,
$mode, $iv);
$encrypted = base64_encode($encrypted);
return $encrypted;
}
// encrypted should be base64_encoded
function decrypt_blowfish($key,$encrypted)
{
$mode = MCRYPT_MODE_CBC;
$iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, $mode);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$encrypted = base64_decode($encrypted);
$decrypted = substr(trim(mcrypt_decrypt(MCRYPT_BLOWFISH, $key,
$encrypted, $mode, $iv),"\0"),$iv_size);
return $decrypted;
}
Navigation:
[Reply to this message]
|