· 6 years ago · May 07, 2019, 08:38 PM
1function my_simple_crypt($string, $action = 'e') {
2// you may change these values to your own
3 $secret_key = '&<py.<$sGD-hL~@RzNP!;F#S+;jK+BJ(#L[=\kx_bq59U.V#M!Mszn>PJ&A2Jj)s7`Ee{EK`PaG~Pw;q2EXNZD{T5hD.q)[P&+_G&R5!PcE"V]j_#dQs2>mPWNr.W##(';
4 $secret_iv = '[$~[auKRp>t\#/G,w\j"A8Z^He;x,F;]ZZ.<eV@zer/YzV$s/,^n$aqysQqSTz&WM4NfT{_]Q?"KuD?Uu=egmF;EcT,4qDn"x]E2kBDg\V_D_V^`Zj^3/zY@Ltzd3&=T';
5
6 $output = false;
7 $encrypt_method = "AES-256-CBC";
8 $key = hash('sha256', $secret_key);
9 $iv = substr(hash('sha256', $secret_iv), 0, 16);
10
11 if ($action == 'e') {
12 $output = base64_encode(openssl_encrypt($string, $encrypt_method, $key, 0, $iv));
13 } else if ($action == 'd') {
14 $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
15 }
16
17 return $output;
18}
19
20function encrypt($str) {
21 return my_simple_crypt($str, 'e');
22}
23
24function decrypt($str) {
25 return my_simple_crypt($str, 'd');
26}