|
@@ -1548,15 +1548,20 @@ function number_pad($number,$n) {
|
|
|
|
|
|
//encrypt a string
|
|
//encrypt a string
|
|
if (!function_exists('encrypt')) {
|
|
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
|
|
//decrypt a string
|
|
if (!function_exists('decrypt')) {
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|