mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2026-02-21 18:36:31 +00:00
Modify en/decryption functions to be openssl-based - mcrypt_* functions are now deprecated as of PHP 7.1.0
This commit is contained in:
@@ -1548,15 +1548,20 @@ function number_pad($number,$n) {
|
||||
|
||||
//encrypt a string
|
||||
if (!function_exists('encrypt')) {
|
||||
function encrypt($key, $str_to_enc) {
|
||||
return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $str_to_enc, MCRYPT_MODE_CBC, md5(md5($key))));
|
||||
function encrypt($key, $data) {
|
||||
$encryption_key = base64_decode($key);
|
||||
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
|
||||
$encrypted = openssl_encrypt($data, 'aes-256-cbc', $encryption_key, 0, $iv);
|
||||
return base64_encode($encrypted.'::'.$iv);
|
||||
}
|
||||
}
|
||||
|
||||
//decrypt a string
|
||||
if (!function_exists('decrypt')) {
|
||||
function decrypt($key, $str_to_dec) {
|
||||
return rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($str_to_dec), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
|
||||
function decrypt($key, $data) {
|
||||
$encryption_key = base64_decode($key);
|
||||
list($encrypted_data, $iv) = explode('::', base64_decode($data), 2);
|
||||
return openssl_decrypt($encrypted_data, 'aes-256-cbc', $encryption_key, 0, $iv);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user