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擴展。