zoukankan      html  css  js  c++  java
  • php代码加密笔记(二)

    php实现基于openssl的加密解密方法

    <?php
    class openssl{
    	private $key = 'key';
    	public $id = '';
    	function encrypt($id){
    	  $id=serialize($id);
    	  $this->id = $id;
    	  $key= $this->key;
    	  $data['iv']=base64_encode(substr('fdakinel;injajdji',0,16));
    	  $data['value']=openssl_encrypt($id, 'AES-256-CBC',$key,0,base64_decode($data['iv']));
    	  $encrypt=base64_encode(json_encode($data));
    	  return $encrypt;
    	}
    	function decrypt($encrypt){
    	  $key = $this->key;//解密钥匙
    	  $encrypt = json_decode(base64_decode($encrypt), true);
    	  $iv = base64_decode($encrypt['iv']);
    	  $decrypt = openssl_decrypt($encrypt['value'], 'AES-256-CBC', $key, 0, $iv);
    	  $id = unserialize($decrypt);
    	  if($id){
    	    return $id;
    	  }else{
    	    return 0;
    	  }
    	}
    }
    
    $obj = new openssl();
    $encrypt = $obj->encrypt('1');
    echo $obj->decrypt($encrypt);
    

      

  • 相关阅读:
    java下载url图片链接
    mysql 设计索引的原则
    169. 多数元素
    263. 丑数
    markdown 语法笔记
    70.爬楼梯
    540. 有序数组中的单一元素
    88. 合并两个有序数组
    面试题57
    152. 乘积最大子序列
  • 原文地址:https://www.cnblogs.com/burningc/p/8656736.html
Copyright © 2011-2022 走看看