码迷,mamicode.com
首页 > Web开发 > 详细

PHP DES加密

时间:2015-05-14 06:10:16      阅读:481      评论:0      收藏:0      [点我收藏+]

标签:

    public function encrypt($str)
    {
        
        
        //$str = "hh";
        $key = "key:123";//密钥
        $cipher = MCRYPT_DES;
        $models = MCRYPT_MODE_ECB;
        $iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher,$models),MCRYPT_RAND);
        //加密
        $str_encrypt = mcrypt_encrypt($cipher,$key,$str,$models,$iv);
        return $str_encrypt;
    }
    
    public function decrypt($str_encrypt)
    {
        $key = "key:123";//密钥
        $cipher = MCRYPT_DES;
        $models = MCRYPT_MODE_ECB;
        $iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher,$models),MCRYPT_RAND);
        $str_decrpt = mcrypt_decrypt($cipher,$key,$str_encrypt,$models,$iv);
        return $str_decrpt;
    }

 

PHP DES加密

标签:

原文地址:http://www.cnblogs.com/flintlovesam/p/4502234.html

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