php encryption/decryption function

WBOY
Release: 2016-07-25 08:44:11
Original
943 people have browsed it
php encryption/decryption function
Encryption/decryption function
Usage
var_dump(Fun::Jmen('aah',$_ENV['Only']));
var_dump(Fun::Jmun('ADYAsVzEX94%3D',$ _ENV['Only']));
Parameters:
$str: str type, content that needs to be encrypted or decrypted
$key: str type, key (the encryption and decryption keys must be the same)
Return:
str type , decrypted or decrypted content
  1. /**
  2. Encryption/decryption function
  3. Usage
  4. var_dump(Fun::Jmen('aah',$_ENV['Only']));
  5. var_dump(Fun::Jmun('ADYAsVzEX94%3D',$_ENV['Only' ]));
  6. Parameters:
  7. $str: str type, the content that needs to be encrypted or decrypted
  8. $key: str type, key (the encryption and decryption keys must be the same)
  9. Return:
  10. str type, decryption or decryption completed The content of
  11. /**/
  12. public static function Jmen($str,$key){
  13. $encrypt_key=md5(mt_rand(0,100));$ctr=0;$tmp='';
  14. for ($i=0;$i
  15. if($ctr==strlen($encrypt_key)){$ctr=0;}$tmp.=substr($encrypt_key,$ctr ,1).(substr($str,$i,1) ^ substr($encrypt_key,$ctr,1));$ctr++;
  16. }
  17. unset($encrypt_key,$ctr,$str);
  18. return rawurlencode( base64_encode(self::_m_($tmp,$key)));
  19. }
  20. public static function Jmun($str,$key){
  21. $txt=self::_m_(base64_decode(rawurldecode($str)),$ key);$tmp='';
  22. for($i=0;$i
  23. unset($txt,$md5,$str,$key);
  24. return $tmp;
  25. }
  26. private static function _m_($txt, $key){
  27. $key=md5($key);$ctr=0;$tmp='';
  28. for($i=0;$i
  29. return $tmp;
  30. }
Copy code
php


Related labels:
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