×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Tommaso Vietina
Added: Jan 26, 2022 9:16 AM
Views: 401
Tags: no tags
  1. <?php
  2.  
  3. // Store a string into the variable which
  4. // need to be Encrypted
  5. $simple_string = "Welcome to GeeksforGeeks\n";
  6.  
  7. // Display the original string
  8. echo "Original String: " . $simple_string;
  9.  
  10. // Store the cipher method
  11. $ciphering = "AES-128-CTR";
  12.  
  13. // Use OpenSSl Encryption method
  14. $iv_length = openssl_cipher_iv_length($ciphering);
  15. $options = 0;
  16.  
  17. // Non-NULL Initialization Vector for encryption
  18. $encryption_iv = '1234567891011121';
  19.  
  20. // Store the encryption key
  21. $encryption_key = "GeeksforGeeks";
  22.  
  23. // Use openssl_encrypt() function to encrypt the data
  24. $encryption = openssl_encrypt($simple_string, $ciphering,
  25.             $encryption_key, $options, $encryption_iv);
  26.  
  27. // Display the encrypted string
  28. echo "Encrypted String: " . $encryption . "\n";
  29.  
  30. // Non-NULL Initialization Vector for decryption
  31. $decryption_iv = '1234567891011121';
  32.  
  33. // Store the decryption key
  34. $decryption_key = "GeeksforGeeks";
  35.  
  36. // Use openssl_decrypt() function to decrypt the data
  37. $decryption=openssl_decrypt ($encryption, $ciphering,
  38.         $decryption_key, $options, $decryption_iv);
  39.  
  40. // Display the decrypted string
  41. echo "Decrypted String: " . $decryption;
  42.  
  43. ?>