码迷,mamicode.com
首页 > 其他好文 > 详细

phalcon: crypt-encrypt/decrypt用法

时间:2016-10-12 13:41:45      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:

phalcon:crypt加密与解密

可以在入口文件index.php进行配置,也可以不配置:

$di->set(‘crypt‘, function(){
    $crypt = new \Phalcon\Crypt();
    return $crypt;
}, true);

或者:

$di[‘crypt‘] = function(){
   $crypt=new \Phalcon\Crypt();
   return $crypt; 
};

关于调用:
$this->crypt;
或者
$this->di[‘crypt‘];
或者
$this->di->crypt;

  

加密解密代码:

        $key = "le password";
        $password = "this is a secret text";
       
            //加密
            $crypt = new \Phalcon\Crypt();
            $encrypted = $crypt->encrypt($password, $key);
            echo $encrypted;

        
            //解密
            $crypt = new \Phalcon\Crypt();
            $encrypted = $crypt->encrypt($password, $key);
            //
            $password = $crypt->decrypt($encrypted, $key);
            echo $password;
       

  

64位的加密解密方便url传输:

      $crypt = new \Phalcon\Crypt();
       // $crypt->setCipher(‘blowfish‘);
        $key = "le password";
        $password = "this is a sicret text";

        //加密
        $encrypted = $crypt->encryptBase64($password, $key);
        echo $encrypted;

        echo "<br>";

       //解密
        $password = $crypt->decryptBase64($encrypted, $key);
        echo $password;

  

 

phalcon: crypt-encrypt/decrypt用法

标签:

原文地址:http://www.cnblogs.com/achengmu/p/5952085.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!