fork download
  1. <?php
  2.  
  3. function encdec($t, $s){
  4.  
  5. $secret_key = 'secret_key';
  6. $secret_iv = 'secret_iv';
  7.  
  8. $output = false;
  9. $encrypt_method = "AES-256-CBC";
  10. $key = hash( 'sha256', $secret_key );
  11. $iv = substr( hash( 'sha256', $secret_iv ), 0, 16 );
  12.  
  13. if( $t == 'e' ) {
  14. $output = base64_encode( openssl_encrypt( $s, $encrypt_method, $key, 0, $iv ) );
  15. }
  16. else if( $t == 'd' ){
  17. $output = openssl_decrypt( base64_decode( $s ), $encrypt_method, $key, 0, $iv );
  18. }
  19.  
  20. return $output;
  21. }
  22.  
  23. $my_secret_enc = encdec("e", "internal_XPto123");
  24. echo $my_secret_enc ."\n";
  25.  
  26. $my_secret_dec = encdec("d", $my_secret_enc);
  27. echo $my_secret_dec;
  28.  
Success #stdin #stdout 0.02s 24440KB
stdin
Standard input is empty
stdout
L3ByNThCSjRveVJQcjc1K3o4cTBuazRsWC9ValRNcWJYQUhERHZENCtwdz0=
internal_XPto123