· 6 years ago · Jun 25, 2019, 07:48 AM
1function encrypt($string, $public_key = "public key", $action = "e") {
2 $secret_key = "secret key";
3 $encrypt_method = "AES-256-CBC";
4 $key = hash( 'sha256', $public_key );
5 $secret = substr( hash( 'sha256', $secret_iv ), 0, 16 );
6
7 if( $action == 'e' ) {
8 $output = base64_encode( openssl_encrypt( $string, $encrypt_method, $key, 0, $secret) );
9 } else if ( $action == 'd') {
10 $output = openssl_decrypt( base64_decode( $string ), $encrypt_method, $key, 0, $secret);
11 }
12 if (empty($output)) {
13 denyAccess();
14 }
15 return $output;
16}