Home > Backend Development > PHP Tutorial > PHP implements simple symmetric encryption and decryption methods

PHP implements simple symmetric encryption and decryption methods

WBOY
Release: 2016-07-25 08:45:29
Original
1037 people have browsed it
  1. /**
  2. * Universal encryption
  3. * @param String $string The string that needs to be encrypted
  4. * @param String $skey Encrypted 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 < $strCount && $strArr[$key].=$value;
  13. }
  14. return str_replace('=', 'O0O0O', join('', $strArr));
  15. }
  16. /**
  17. * Universal decryption
  18. * @param String $string The string to be decrypted
  19. * @param String $skey Decryption KEY
  20. * @return String
  21. */
  22. function deCode($string = '', $skey = 'echounion') {
  23. $skey = array_reverse(str_split($skey));
  24. $strArr = str_split(str_replace('O0O0O', '=', $string), 2);
  25. $strCount = count($strArr);
  26. foreach ($skey as $key => $value) {
  27. $key < $strCount && $strArr[$key] = rtrim($strArr[$key], $value);
  28. }
  29. return base64_decode(join('', $strArr));
  30. }
复制代码

PHP


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template