AESEncrypter.php 877 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: wilson
  5. * Date: 16/7/7
  6. * Time: 11:07
  7. */
  8. namespace app\common\modules\yop\sdk\Util;
  9. abstract class AESEncrypter{
  10. /**
  11. * 算法,另外还有192和256两种长度
  12. */
  13. const CIPHER = MCRYPT_RIJNDAEL_128;
  14. /**
  15. * 模式
  16. */
  17. const MODE = 'AES-128-ECB';
  18. /**
  19. * 加密
  20. * @param string $str 需加密的字符串
  21. * @param string $key 密钥
  22. * @return type
  23. */
  24. static public function encode( $str, $key){
  25. return base64_encode(openssl_encrypt($str,self::MODE,base64_decode($key),OPENSSL_RAW_DATA));
  26. }
  27. /**
  28. * 解密
  29. * @param type $str
  30. * @param type $key
  31. * @return type
  32. */
  33. static public function decode( $str, $key ){
  34. return openssl_decrypt(base64_decode($str),self::MODE,base64_decode($key),OPENSSL_RAW_DATA);
  35. }
  36. }