PHP DES加密

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

 

posted on 2015-05-14 00:48  与非朋仔  阅读(491)  评论(0编辑  收藏  举报

导航