paip.提升安全性----Des加密 java php python的实现总结

paip.提升安全性----Des加密 java php python的实现总结

///////////    uapi
        private static String decryptByDes(String s_en) {
        
        }

        private static String encryptByDes(String str1) {
            
            
        }  
    
////////////python的雅要自己写了..
/////////////    java的雅十..

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

在配置文件中将这个扩展打开还不能够在windows环境下使用

需要将PHP文件夹下的 libmcrypt.dll 拷贝到系统的 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));

    }    
    
    
    
    

    
    

    
    作者Attilax  艾龙, EMAIL:1466519819@qq.com
来源:attilax的专栏
地址:http://blog.csdn.net/attilax


参考    
JAVA实现DES加密 - RAPE JAVA的专栏 - 博客频道 - CSDN.NET.htm
    python实现DES加密算法 - 开源中国社区.htm
PHP使用DES进行加密和解密 - Cocowool - 博客园.htm
原文地址:https://www.cnblogs.com/attilax/p/5964048.html