>  기사  >  백엔드 개발  >  PHP 암호화 클래스

PHP 암호화 클래스

不言
不言원래의
2018-05-04 09:14:531263검색

이 글의 주요 내용은 특정 참조 가치가 있는 PHP 암호화 클래스를 소개하는 것입니다. 이제 필요한 친구들이 참조할 수 있습니다.

<?php
namespace app\index\controller;class Crypt{
    private $key = "";  
    public function __construct($key = null)    
    {
            if (!is_null($key)) {
                        $this->key = $key;        
                        }    
     }    
     //加密函数    
     public function passport_encrypt($txt)
     {
             srand((double)microtime() * 1000000);        
             $encrypt_key = md5(rand(0, 32000));        
             $ctr = 0;        
             $tmp = '';        
             for ($i = 0; $i < strlen($txt); $i++) {
                         $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;            
                         $tmp .= $encrypt_key[$ctr] . ($txt[$i] ^ $encrypt_key[$ctr++]);        
                         }        
                         return urlencode(base64_encode($this->passport_key($tmp, $this->key)));    
        }    
        //解密函数    
        public function passport_decrypt($txt)    
        {        
        $txt = $this->passport_key(base64_decode(urldecode($txt)), $this->key);        
        $tmp = '';        
        for ($i = 0; $i < strlen($txt); $i++) {
                    $md5 = $txt[$i];            
                    $tmp .= $txt[++$i] ^ $md5;        
                    }        
                    return $tmp;    
       }    
       private function passport_key($txt, $encrypt_key)    
       {        
       $encrypt_key = md5($encrypt_key);        
       $ctr = 0;        
       $tmp = '';        
       for ($i = 0; $i < strlen($txt); $i++) {
                   $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;            
                   $tmp .= $txt[$i] ^ $encrypt_key[$ctr++];        
                   }        
                   return $tmp;    
                   }
           }


위 내용은 PHP 암호화 클래스의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.