fork(2) download
  1. <?php // http://stackoverflow.com/questions/37719160/compare-the-data-of-two-csv-file
  2. // https://i...content-available-to-author-only...e.com/uZnCVb
  3.  
  4.  
  5. $srcText = "Hello World! - " . uniqid();
  6. $key = 's7aBkf4Ypn59bWviQziPDXyPasdaYlhQ';
  7.  
  8. $srcEncrypted = '';
  9. $srcDecrypted = '';
  10.  
  11. $srcEncrypted = encrypt($srcText, $key);
  12.  
  13. $srcDecrypted = decrypt($srcEncrypted, $key);
  14.  
  15. var_dump($srcText,
  16. $srcEncrypted,
  17. $srcDecrypted,
  18. $srcDecrypted == $srcText);
  19.  
  20. exit(__FILE__.__LINE__);
  21.  
  22.  
  23. /**
  24.  * Encrypt a string
  25.  *
  26.  * Include the exact length of the data string so we can return the exact length
  27.  * after the decryption.
  28.  *
  29.  * @Param string $data
  30.  * @Param string $key
  31.  *
  32.  * @return string - base64_encoded
  33.  */
  34. function encrypt($data, $key) {
  35.  
  36. $cypher = $cypher = 'aes-256-cbc';
  37. $ivSize = openssl_cipher_iv_length($cypher);
  38. $ivData = openssl_random_pseudo_bytes($ivSize);
  39.  
  40. $encripted = openssl_encrypt($data,
  41. $cypher,
  42. $key,
  43. // USE THIS ONLY !!!!
  44. OPENSSL_RAW_DATA,
  45. $ivData);
  46.  
  47.  
  48. return base64_encode($ivData . $encripted);
  49. }
  50.  
  51.  
  52. /**
  53.  * Decrypt a string
  54.  *
  55.  * @Param string $data
  56.  * @Param string $key
  57.  *
  58.  * @return string - original text
  59.  */
  60. function decrypt($data, $key) {
  61.  
  62. $cypher = 'aes-256-cbc';
  63. $ivSize = openssl_cipher_iv_length($cypher);
  64.  
  65. $data = base64_decode($data);
  66. $ivData = substr($data, 0, $ivSize);
  67.  
  68. $encData = substr($data, $ivSize);
  69.  
  70. $output = openssl_decrypt($encData,
  71. $cypher,
  72. $key,
  73. OPENSSL_RAW_DATA,
  74. $ivData);
  75. return $output;
  76. }
  77.  
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
string(28) "Hello World! - 577e7d8bb8be2"
string(64) "AjHjH0K/CWDDPW9e9mTlm0BI9C/nlTsFJC+r+aKR0r1ZbIhBvorT0BD+/oU+DAwI"
string(28) "Hello World! - 577e7d8bb8be2"
bool(true)
/home/xRsGe5/prog.php20