代码部分
<?php
class Aes {
CONST OPTIONS = OPENSSL_RAW_DATA;
/**
* @param $input
* @param string $keys
* @param string $cipher
* @return string
*/
public static function encrypt($input, $keys = '', $cipher = 'AES-128-ECB')
{
if(empty($keys)) $keys = self::$keys;
$data = openssl_encrypt($input, $cipher, $keys, self::OPTIONS);
return bin2hex($data);
}
/**
* @param $output
* @param string $keys
* @param string $cipher
* @return string
*/
public static function decrypt($output, $keys = '', $cipher = 'AES-128-ECB')
{
if(empty($keys)) $keys = self::$keys;
$data = hex2bin($output);
return openssl_decrypt($data, $cipher, $keys, self::OPTIONS);
}
}
使用方法
Aes::encrypt('需要加密的数据');