中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

PHP使用DES進行加密和解密

2018-07-20    來源:open-open

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用

php中有一個擴展可以支持DES的加密算法,是:extension=php_mcrypt.dll

在配置文件中將這個擴展打開還不能夠在windows環(huán)境下使用

需要將PHP文件夾下的 libmcrypt.dll 拷貝到系統(tǒng)的 system32 目錄下,這是通過phpinfo可以查看到mcrypt表示這個模塊可以正常試用了。

 下面是PHP中使用DES加密解密的一個例子:

//$input - stuff to decrypt
    //$key - the secret key to use

    function do_mencrypt($input, $key)
    {
        $input = str_replace(""n", "", $input);
        $input = str_replace(""t", "", $input);
        $input = str_replace(""r", "", $input);
        $key = substr(md5($key), 0, 24);
        $td = mcrypt_module_open('tripledes', '', 'ecb', '');
        $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
        mcrypt_generic_init($td, $key, $iv);
        $encrypted_data = mcrypt_generic($td, $input);
        mcrypt_generic_deinit($td);
        mcrypt_module_close($td);
        return trim(chop(base64_encode($encrypted_data)));
    }
    
    //$input - stuff to decrypt
    //$key - the secret key to use
    
    function do_mdecrypt($input, $key)
    {
        $input = str_replace(""n", "", $input);
        $input = str_replace(""t", "", $input);
        $input = str_replace(""r", "", $input);
        $input = trim(chop(base64_decode($input)));
        $td = mcrypt_module_open('tripledes', '', 'ecb', '');
        $key = substr(md5($key), 0, 24);
        $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
        mcrypt_generic_init($td, $key, $iv);
        $decrypted_data = mdecrypt_generic($td, $input);
        mcrypt_generic_deinit($td);
        mcrypt_module_close($td);
        return trim(chop($decrypted_data));

    }   

標簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:jq select操作全集

下一篇: php 將文件壓縮為zip文件