· 6 years ago · Jun 15, 2019, 04:39 AM
1function my_simple_crypt($string, $action = 'e')
2{
3 // you may change these values to your own
4 $secret_key = 'abcdefgh';
5 $secret_iv = 'xyz12345';
6
7 $output = false;
8 $encrypt_method = "AES-256-CBC";
9 $key = hash('sha256', $secret_key);
10 $iv = substr(hash('sha256', $secret_iv), 0, 16);
11
12 if ($action == 'e')
13 {
14 $output = base64_encode(openssl_encrypt($string, $encrypt_method, $key, 0, $iv));
15 }
16 else if ($action == 'd') {
17 $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
18 }
19 return $output;
20}