Crypt.class.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * 洛阳赤炎鹰网络科技有限公司
  4. * https://www.cyyvip.com
  5. * Copyright (c) 2022 赤店商城 All rights reserved.
  6. */
  7. // +----------------------------------------------------------------------
  8. // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
  9. // +----------------------------------------------------------------------
  10. // | Copyright (c) 2006-2014 http://thinkphp.cn All rights reserved.
  11. // +----------------------------------------------------------------------
  12. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  13. // +----------------------------------------------------------------------
  14. // | Author: liu21st <liu21st@gmail.com>
  15. // +----------------------------------------------------------------------
  16. namespace Think;
  17. /**
  18. * 加密解密类
  19. */
  20. class Crypt {
  21. private static $handler = '';
  22. public static function init($type=''){
  23. $type = $type?:C('DATA_CRYPT_TYPE');
  24. $class = strpos($type,'\\')? $type: 'Think\\Crypt\\Driver\\'. ucwords(strtolower($type));
  25. self::$handler = $class;
  26. }
  27. /**
  28. * 加密字符串
  29. * @param string $str 字符串
  30. * @param string $key 加密key
  31. * @param integer $expire 有效期(秒) 0 为永久有效
  32. * @return string
  33. */
  34. public static function encrypt($data,$key,$expire=0){
  35. if(empty(self::$handler)){
  36. self::init();
  37. }
  38. $class = self::$handler;
  39. return $class::encrypt($data,$key,$expire);
  40. }
  41. /**
  42. * 解密字符串
  43. * @param string $str 字符串
  44. * @param string $key 加密key
  45. * @return string
  46. */
  47. public static function decrypt($data,$key){
  48. if(empty(self::$handler)){
  49. self::init();
  50. }
  51. $class = self::$handler;
  52. return $class::decrypt($data,$key);
  53. }
  54. }