AES

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-25 08:43:00970Durchsuche
  1. class aes {
  2. static public $mode = MCRYPT_MODE_NOFB;
  3. static public function generateKey($length=32) {
  4. if (!in_array($length,array(16,24,32)))
  5. return False;
  6. $str = '';
  7. for ($i=0;$i $str .= chr(rand(33,126));
  8. }
  9. return $str;
  10. }
  11. static public function encrypt($data, $key) {
  12. if (strlen($key) > 32 || !$key)
  13. return trigger_error('key too large or key is empty.', E_USER_WARNING) && False;
  14. $ivSize = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, self::$mode);
  15. $iv = mcrypt_create_iv($ivSize, (substr(PHP_OS,0,1) == 'W' ? MCRYPT_RAND : MCRYPT_DEV_URANDOM ));
  16. $encryptedData = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $data, self::$mode, $iv);
  17. $encryptedData = $iv . $encryptedData;
  18. return base64_encode($encryptedData);
  19. }
  20. static public function decrypt($data, $key) {
  21. if (strlen($key) > 32 || !$key)
  22. return trigger_error('key too large or key is empty.', E_USER_WARNING) && False;
  23. $data = base64_decode($data);
  24. if (!$data)
  25. return False;
  26. $ivSize = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, self::$mode);
  27. $iv = substr($data, 0, $ivSize);
  28. $data = substr($data, $ivSize);
  29. $decryptData = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $data, self::$mode, $iv);
  30. return $decryptData;
  31. }}
复制代码

AES


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn