Guest User

Untitled

a guest
Apr 24th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. <?php
  2. $key = "mySecretKey";
  3. $cipher = "aes-128-gcm";
  4. $ivlen = openssl_cipher_iv_length($cipher);
  5.  
  6. $iv = openssl_random_pseudo_bytes($ivlen);
  7. $ciphertext = openssl_encrypt("message to be encrypted", $cipher, $key, $options=0, $iv, $tag);
  8.  
  9. $original_plaintext = openssl_decrypt($ciphertext, $cipher, $key, 0, $iv, $tag);
  10.  
  11. echo "original message: ".$original_plaintext."n";
  12.  
  13. // $iv and $tag change each time we encrypt the data, so store these
  14. ?>
Add Comment
Please, Sign In to add comment