Simple.php 933 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php namespace App\Servers\Encrypts;
  2. /**
  3. * 自定义简单对称加密
  4. *
  5. * @author 刘相欣
  6. */
  7. class Simple
  8. {
  9. /**
  10. * 简单对称加密算法之加密
  11. *
  12. * @param String $contents 需要加密的内容
  13. *
  14. * @return String
  15. *
  16. * */
  17. public function encode($contents)
  18. {
  19. //先用base64编码
  20. $contents = base64_encode($contents);
  21. //替换掉符号
  22. $encrypted = str_replace(['=', '+', '/'], [md5('ZZ22'), md5('Z22Z'), md5('XGHJ')], $contents);
  23. //返回结果
  24. return $encrypted;
  25. }
  26. /**
  27. * 简单对称加密算法之解密
  28. *
  29. * @param String $encrypted 需要解密的内容
  30. *
  31. * @return String
  32. *
  33. * */
  34. public function decode($encrypted)
  35. {
  36. //替换掉符号
  37. $encrypted = str_replace([md5('ZZ22'), md5('Z22Z'), md5('XGHJ')], ['=', '+', '/'], $encrypted);
  38. //先用base64编码
  39. $decrypted = base64_decode($encrypted);
  40. //返回结果
  41. return $decrypted;
  42. }
  43. }