· 5 years ago · Jan 10, 2020, 11:58 AM
1public function data_encrypt_decrypt($string, $action,$secret_key,$secret_iv) {
2
3
4 $output = false;
5 $encrypt_method = "AES-256-CBC";
6 $key = hash( 'sha256', $secret_key );
7 $iv = substr( hash( 'sha256', $secret_iv ), 0, 16 );
8
9 if( $action == 'e' ) {
10 $output = base64_encode( openssl_encrypt( $string, $encrypt_method, $key, 0, $iv ) );
11 }
12 else if( $action == 'd' ){
13 $output = openssl_decrypt( base64_decode( $string ), $encrypt_method, $key, 0, $iv );
14 }
15
16 return $output;
17}