Heim  >  Artikel  >  Backend-Entwicklung  >  PHP实现简单的对称加密和解密方法

PHP实现简单的对称加密和解密方法

WBOY
WBOYOriginal
2016-07-25 08:45:29985Durchsuche
  1. /**
  2. * 通用加密
  3. * @param String $string 需要加密的字串
  4. * @param String $skey 加密EKY
  5. * @return String
  6. */
  7. function enCode($string = '', $skey = 'echounion') {
  8. $skey = array_reverse(str_split($skey));
  9. $strArr = str_split(base64_encode($string));
  10. $strCount = count($strArr);
  11. foreach ($skey as $key => $value) {
  12. $key }
  13. return str_replace('=', 'O0O0O', join('', $strArr));
  14. }
  15. /**
  16. * 通用解密
  17. * @param String $string 需要解密的字串
  18. * @param String $skey 解密KEY
  19. * @return String
  20. */
  21. function deCode($string = '', $skey = 'echounion') {
  22. $skey = array_reverse(str_split($skey));
  23. $strArr = str_split(str_replace('O0O0O', '=', $string), 2);
  24. $strCount = count($strArr);
  25. foreach ($skey as $key => $value) {
  26. $key }
  27. return base64_decode(join('', $strArr));
  28. }
复制代码

PHP


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