· 5 years ago · Apr 30, 2020, 05:30 AM
1<?php
2 function convert($action, $string) {
3 $output = false;
4
5 $encrypt_method = "AES-256-CBC";
6 $secret_key = 'rer54etrg5eysdkjhf8ds7gfdubfd8sfydvf';
7 $secret_iv = 'g5gtghh45dsnfiu73b38b83fb873fb8';
8
9 // hash
10 $key = hash('sha256', $secret_key);
11
12 // iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning
13 $iv = substr(hash('sha256', $secret_iv), 0, 16);
14
15 if( $action == 'encrypt' ) {
16 $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
17 $output = base64_encode($output);
18 }
19 else if( $action == 'decrypt' ){
20 $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
21 }
22
23 return $output;
24 }
25
26 function anti($string) {
27 $output = stripslashes(strip_tags(htmlspecialchars($string ,ENT_QUOTES)));
28 return $output;
29 }
30?>