zoukankan      html  css  js  c++  java
  • php支持解密的加密算法示例

    其实只是对位运算符的一种简单的应用。

    <?php
    class Helper_Inpass{
      private $keys='thisismytoken';//token
      function inpass($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 base64_encode($this->passport_key($tmp)); 
    }
    function depass($txt) { //解密
      $txt = $this->passport_key(base64_decode($txt)); 
      $tmp = ''; 
      for($i = 0;$i < strlen($txt); $i++) { 
        $md5 = $txt[$i]; 
        $tmp .= $txt[++$i] ^ $md5;
      }
      return $tmp; 
    }
    private function passport_key($txt) { 
      $encrypt_key = md5($this->keys); 
      $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; 
    }
    }
    ?>
    欢迎各位指点!
  • 相关阅读:
    docker log
    byte转String防止乱码
    SQL索引
    Redis 总结精讲
    如何保证消息队列是高可用的
    消息中间件(一)MQ详解及四大MQ比较
    @Bean和@Componet区别
    理解Spring的AOP和Ioc/DI就这么简单
    SpringBoot 基础
    《Linux 鸟哥私房菜》 第6章 Linux的文件权限与目录配置
  • 原文地址:https://www.cnblogs.com/thors/p/9494149.html
Copyright © 2011-2022 走看看