retesere20

sample php encrypt decrypt

May 28th, 2020
31
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. public function my_simple_crypt( $string, $secret_key='my_simple_secret_key', $secret_iv = 'my_simple_secret_iv', $action = 'encrypt' ) {
  3. $encrypt_method = "AES-256-CBC";
  4. $key = hash( 'sha256', $secret_key );
  5. $iv = substr( hash( 'sha256', $secret_iv ), 0, 16 );
  6. return $action == 'encrypt' ? base64_encode( openssl_encrypt( $string, $encrypt_method, $key, 0, $iv ) ) : openssl_decrypt( base64_decode( $string ), $encrypt_method, $key, 0, $iv );
  7. }
RAW Paste Data