· 7 years ago · May 09, 2018, 01:14 PM
1class Code
2{
3 protected $stringx;
4 protected $action;
5
6 public function Code_x($STRINGX, $ACTION)
7 {
8 $this->stringx = $STRINGX;
9 $this->action = $ACTION;
10 return $this->Hash_1($STRINGX, $ACTION);
11 }
12
13 protected function Hash_1( $stringx, $action )
14 {
15 $secret_key =
16 'xxxstring_secret_keyxxx'
17 ;
18 $secret_iv =
19 'xxxstring_secret_ivxxx'
20 ;
21 $output = false;
22 $encrypt_method = "AES-256-CBC";
23 $key = hash( 'sha512', $secret_key );
24 $iv = substr( hash( 'sha512', $secret_iv ), 64, 16 );
25 if( $action == 'E' ) {
26 $output = base64_encode( openssl_encrypt( $stringx, $encrypt_method, $key, 0, $iv ) );
27 return $output;
28 }
29 else if( $action == 'D' ){;
30 $tmp = base64_decode( $stringx );
31 $output = openssl_decrypt( $tmp, $encrypt_method, $key, 0, $iv );
32 return $output;
33 }
34
35
36 }
37}