Advertisement
scriptz-team

[PHP] Strong Encrypt & Decrypt Function + Example of usage

Oct 26th, 2013
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.70 KB | None | 0 0
  1. <?php
  2. $password_x = "
  3. +7):;25<%]~78413899672afeec
  4. 3736306831e9d13c13a3cw3%N:<
  5. W7L!|E7:_*$[m}341#R4%}f7751
  6. j@^!'&f40<5#e63892cfadbed1c
  7. 315f32c55e2888487x2&Q[,4k2{
  8. ,&$:e6&:[)'*j&48-H^Y1zO@8xq
  9. ";
  10. $key        = pack('H*', $password_x);
  11. $key_x      = base64_encode(substr($password_x, 3, 6)) . pack('H*', sha1(substr($password_x, 5, 10))) . md5($key) . "^#^" . $key;
  12. $password   = $key_x;
  13.  
  14. function encrypt_x($text)
  15. {
  16.     global $password;
  17.     $key_x             = $password;
  18.     $key_size          = strlen($key_x);
  19.     $plaintext         = $text;
  20.     $iv_size           = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
  21.     $iv                = mcrypt_create_iv($iv_size, MCRYPT_RAND);
  22.     $ciphertext        = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key_x, $plaintext, MCRYPT_MODE_CBC, $iv);
  23.     $ciphertext        = $iv . $ciphertext;
  24.     $ciphertext_base64 = base64_encode($ciphertext);
  25.     return $ciphertext_base64;
  26. }
  27.  
  28. function decrypt_x($text)
  29. {
  30.     global $password;
  31.     $key_x          = $password;
  32.     $ciphertext_dec = base64_decode($text);
  33.     $iv_size        = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
  34.     $iv             = mcrypt_create_iv($iv_size, MCRYPT_RAND);
  35.     $iv_dec         = substr($ciphertext_dec, 0, $iv_size);
  36.     $ciphertext_dec = substr($ciphertext_dec, $iv_size);
  37.     $plaintext_dec  = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key_x, $ciphertext_dec, MCRYPT_MODE_CBC, $iv_dec);
  38.     return $plaintext_dec;
  39. }
  40.  
  41. $crypt_text   = encrypt_x("sCRiPTz-TEAM.iNFO");
  42. $decrypt_text = decrypt_x($crypt_text);
  43. echo "Encypted: " . $crypt_text . "<br/><br/>";
  44. echo "Decrypted: " . $decrypt_text . "<br/><br/>";
  45. echo "Password: <pre>" . $password . "</pre>";
  46. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement