CI框架中自带的加密解密如何应用

首先我们找到配置文件application/config/config.php  ,找到如下代码:

?
1
$config [ 'encryption_key' ] =  "YOUR KEY" ;

在控制器里面我们要调用加密类文件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
$this ->load->library( 'encrypt' ); //在控制器里面调用加密类
function  pwdtest(){
         /*加密过程*/
         //第一种方法
         $a  'My secret message' ;
         $aa  $this ->encrypt->encode( $a );
         echo  $aa ;
         echo  "<br />" ;
         //第二种方法
         $b  'My secret message' ;
         $b1  'super-secret-key' ;
         $bb  $this ->encrypt->encode( $b $b1 );
         echo  $bb ;
         echo  "<br />" ;
         /*解密过程*/
         //第一种方法
         $c  $aa ;
         $cc  $this ->encrypt->decode( $c );
         echo  $cc ;
         echo  "<br />" ;
         //第二种方法
         $d  $bb ;
         $d2  'super-secret-key' ;
         $dd  $this ->encrypt->decode( $d $d2 );
         echo  $dd ;
     }

经过测试确实可以加密和解密的

 

你可能感兴趣的:(加密解密)