大米CMS官网论坛,大米站长联盟,大米站长之家,大米开发者社区

标题: 字符串加解密 [打印本页]

作者: 追影    时间: 2023-5-30 09:28
标题: 字符串加解密
  1. //字符串加解密
  2. function encrypt_decrypt($string, $action = 'encrypt')
  3. {
  4.     $secret_key = 'key';
  5.     $secret_iv = 'iv';
  6.     $output = false;
  7.     $encrypt_method = "AES-256-CBC";
  8.     $key = hash('sha256', $secret_key);
  9.     $iv = substr(hash('sha256', $secret_iv), 0, 16);
  10.     if ($action == 'encrypt') {
  11.         $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
  12.         $output = base64_encode($output);
  13.     } else if ($action == 'decrypt') {
  14.         $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
  15.     }
  16.     return $output;
  17. }
复制代码







欢迎光临 大米CMS官网论坛,大米站长联盟,大米站长之家,大米开发者社区 (https://www.damicms.com/bbs/) Powered by Discuz! X3.1