function customEncrypt($data, $key) {
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_DEV_URANDOM);
$cipherText = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_CBC, $iv);
return base64_encode($iv . $cipherText);
}
function customDecrypt($data, $key) {
$data = base64_decode($data);
$ivSize = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$iv = substr($data, 0, $ivSize);
$cipherText = substr($data, $ivSize);
$plainText = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $cipherText, MCRYPT_MODE_CBC, $iv);
return $plainText;
}
$data = "This is a secret message";
$key = "mysecretkey";
$encryptedData = customEncrypt($data, $key);
echo "Encrypted Data: " . $encryptedData . "\n";
$decryptedData = customDecrypt($encryptedData, $key);
echo "Decrypted Data: " . $decryptedData . "\n";
以上是一个基本的使用示例,您可以根据自己的需求来定制加密和解密函数,以实现更复杂的加密算法和逻辑。请注意,使用mcrypt进行加密需要确保您的服务器已安装mcrypt扩展。