<?php
//$key = 24982988;
//$iv = 2498298824982988;

$key = "94hO36ICRKW2tprVZU1guM6wAUBgl440";  // 32 bytes
$iv = "HanyuVr-24982988"; // 16 bytes
function encrypt($data, $key, $iv) {
    // 使用 AES 加密算法加密数据
   // $encrypted = openssl_encrypt($data, 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv);
    $encrypted = openssl_encrypt($data, 'AES-256-CBC', $key, OPENSSL_RAW_DATA, $iv);

    // 对加密后的数据进行 Base64 编码
    $encrypted_base64 = base64_encode($encrypted);
    return $encrypted_base64;
}

// 解密函数
function decrypt($data, $key, $iv) {
  // 对 Base64 编码的数据进行解码
  $decoded_str = base64_decode(str_replace([' ', '-'], ['+', '/'], $data));
  // 使用 AES 解密算法解密数据
  $decrypted = openssl_decrypt($decoded_str, 'AES-256-CBC', $key, OPENSSL_RAW_DATA, $iv);
  return $decrypted;
}

// $action = 'token=HanyuToken24982988&act=send_customer_mail&email=jackywu0203+123@gmail.com&userRid=39';
// $mdata = ((!empty($_REQUEST['data'])) ? $_REQUEST['data'] : $action); 
// $rs = encrypt($mdata, $key, $iv);

// echo $mdata ;
// echo "\n";
// echo "加密後的密文: " . $rs . "\n";
// $rs = 'qudd8gfafRv3lgnenyFWCLe8lvgUNNpEEeENFVPom/k8KdgVmzZmDJpxLRR77DBsKEw5kz/fO3yPUVDKGY/xi4iGDSYNTg2rMj/WR09uHvNKs8ZQa7PiXUdkwk6gc2SF';
// echo "解密後的明文: " . decrypt($rs, $key, $iv) . "\n";

?>