반응형
mcrypt_* 이 PHP 7.1 에서 deprecated 이 되었고, PHP7.2 에서 mcrypt_* 이 삭제되어 사용이 불가능 해졌다.
대신 openssl encrypt 를 사용하면 된다.
private static $key = "key_pass";
private static $cipher = "aes-256-cbc";
public static function encrypt($buffer){
$ivlen = openssl_cipher_iv_length(self::$cipher);
$iv = openssl_random_pseudo_bytes($ivlen);
return openssl_encrypt($buffer, self::$cipher, self::$key, $options=0, $iv, $tag);
}
public static function decrypt($buffer){
$ivlen = openssl_cipher_iv_length(self::$cipher);
$iv = openssl_random_pseudo_bytes($ivlen);
return openssl_decrypt($buffer, self::$cipher, self::$key, $options=0, $iv, $tag);
}
반응형
'웹프로그래밍 > PHP' 카테고리의 다른 글
[PHP] phpMyAdmin blowfish_secret 경고 해결법 (0) | 2022.05.04 |
---|---|
[PHP 7.2] mcrypt_create_iv, mcrypt_encrypt, mcrypt_decrypt is undefined function (0) | 2018.08.28 |
php : Thread Safe 와 Non Thread Safe 차이점 (0) | 2017.12.02 |
PHP: Simple compression of JSON data (0) | 2016.06.16 |
How to call PHP function from string stored in a Variable (0) | 2016.05.24 |
HTTP GET String + 등이 삭제되었을 때 (0) | 2016.04.18 |