Advertisement
zero50x

Функция обратимого шифрования php

Aug 7th, 2016
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.95 KB | None | 0 0
  1. //Функция шифрования
  2. function simple_encrypt($text, $salt = "earlysandwich.com")
  3. {
  4.     return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $salt, $text, MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND))));
  5. }
  6.  
  7. //Функция дешифрования
  8. function simple_decrypt($text, $salt = "earlysandwich.com")
  9. {
  10.     return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $salt, base64_decode($text), MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND)));
  11. }
  12.  
  13. // Шифруемая строка
  14. $str = 'ddd777uuu888ooo';
  15.  
  16. // Encrypt a tring and echo it
  17. $encoded = simple_encrypt($str, "securedsecuredsecuredfff");
  18.  
  19. echo "<br />";
  20. echo "Зашифровано:  ". $encoded;
  21. echo "<br />";
  22.  
  23. // Now to decode the encoded text
  24. $decoded = simple_decrypt($encoded , "securedsecuredsecuredfff");
  25.  
  26. echo "Было:  ". $decoded;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement