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

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

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

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

$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;
    }

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




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