×

Welcome to TagMyCode

Please login or create account to add a snippet.
1
0
 
1
Language: PHP
Posted by: Jacques Artgraven
Added: Aug 4, 2014 11:07 AM
Views: 20
Tags: no tags
a simple script for creating a nice encryption
  1. <?PHP
  2.  
  3. $string = "Some text to be encrypted";
  4. $secret_key = "This is my SeCrEt key";
  5.  
  6. // Encryption Algorithm
  7. $etype = MCRYPT_RIJNDAEL_256;
  8.  
  9. // Create the initialization vector for added security.
  10. $iv = mcrypt_create_iv(mcrypt_get_iv_size($etype, MCRYPT_MODE_ECB), MCRYPT_RAND);
  11.  
  12. // Output original string
  13. PRINT "Original string: $string <p>";
  14.  
  15. // Encrypt $string
  16. $encrypted_string = mcrypt_encrypt($etype, $secret_key, $string, MCRYPT_MODE_CBC, $iv);
  17.  
  18. // Convert to hexadecimal and send to browser
  19. PRINT "Encrypted string: ".BIN2HEX($encrypted_string)."<p>";
  20.  
  21. $decrypted_string = mcrypt_decrypt($etype, $secret_key, $encrypted_string, MCRYPT_MODE_CBC, $iv);
  22.  
  23. PRINT "Decrypted string is: $decrypted_string";
  24.  
  25. ?>