1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- namespace app\service;
- use laytp\traits\Error;
- use think\facade\Cache;
- use think\facade\Config;
- use think\facade\Request;
- class Encrypt{
- use Error;
- /**
- * 初始化
- * @param $token
- * @return bool
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function encrypt($str, $key='A68AA4BA448752AC147A81ACBE2A8B4C'){
- $mixStr = md5(date('Y-m-d H:i:s').rand(1000,10000));
- $tmp = '';
- $strLen = strlen($str);
- for($i=0, $j=0; $i<$strLen; $i++, $j++){
- $j = $j == 32 ? 0 : $j;
- $tmp .= $mixStr[$j].($str[$i] ^ $mixStr[$j]);
- }
- return base64_encode($this->bind_key($tmp, $key));
- }
- public function bind_key($str, $key){
- $encrypt_key = md5($key);
- $tmp = '';
- $strLen = strlen($str);
- for($i=0, $j=0; $i<$strLen; $i++, $j++){
- $j = $j == 32 ? 0 : $j;
- $tmp .= $str[$i] ^ $encrypt_key[$j];
- }
- return $tmp;
- }
- }
|