[code]
define(‘SECRET_KEY’, ‘1234567890’);
define(‘SECRET_IV’, ‘#@$%^&*()_+=-‘);
function Encrypt($str)
{
$key = hash(‘sha256’, SECRET_KEY);
$iv = hex2bin(substr(hash(‘sha256’, SECRET_IV), 0, 32));
return str_replace(“=”, “”, base64_encode(openssl_encrypt($str, “AES-256-CBC”, $key, 0, $iv)));
}
function Decrypt($str)
{
$key = hash(‘sha256’, SECRET_KEY);
$iv = hex2bin(substr(hash(‘sha256’, SECRET_IV), 0, 32));
return openssl_decrypt(base64_decode($str), “AES-256-CBC”, $key, 0, $iv);
}
// 사용예
$str = “안녕하세요”;
$enc = Encrypt($str);
echo $enc.PHP_EOL;
$dec = Decrypt($enc);
echo $dec.PHP_EOL;
[/code]