Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. public static $key = "+7qC@+AS5@#pozrTUnY&j)Hb+H)R**NS";
  2.  
  3. public static function Encrypt($encrypt){
  4. $key = Encryption::$key;
  5. $encrypt = serialize($encrypt);
  6. $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC), MCRYPT_DEV_URANDOM);
  7. $mac = hash_hmac('sha256', $encrypt, substr(bin2hex($key), -32));
  8. $passcrypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $encrypt.$mac, MCRYPT_MODE_CBC, $iv);
  9. $encoded = base64_encode($passcrypt).'|'.base64_encode($iv);
  10. return $encoded;
  11. }
  12.  
  13. public static function Decrypt($decrypt){
  14. $key = Encryption::$key;
  15. $decrypt = explode('|', $decrypt.'|');
  16. $decoded = base64_decode($decrypt[0]);
  17. $iv = base64_decode($decrypt[1]);
  18. if(strlen($iv)!==mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC)){ return false; }
  19. $decrypted = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $decoded, MCRYPT_MODE_CBC, $iv));
  20. $mac = substr($decrypted, -64);
  21. $decrypted = substr($decrypted, 0, -64);
  22. $calcmac = hash_hmac('sha256', $decrypted, substr(bin2hex($key), -32));
  23. if($calcmac!==$mac){ return false; }
  24. $decrypted = unserialize($decrypted);
  25. return $decrypted;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement