Home > Backend Development > PHP Tutorial > php-mcrypt 在PHP5.60+的版本中怎么使用?

php-mcrypt 在PHP5.60+的版本中怎么使用?

WBOY
Release: 2016-06-02 11:32:59
Original
1226 people have browsed it

php

目前项目中的一个密码对接放在正式环境之后出现了问题,
原因是在PHP5.6以上的版本中修改了mcrypt_encrypt 和 mcrypt_decrypt,
有人知道在新版本的PHP中应该怎么使用这两个方法吗?

<code>protected function encrypt($string) {        //加密用的密钥文件         $key = md5("xxxxxxxx");        //加密方法         $cipher_alg = MCRYPT_TRIPLEDES;        //初始化向量来增加安全性         $iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher_alg,MCRYPT_MODE_ECB), MCRYPT_RAND);         //开始加密         $encrypted_string = mcrypt_encrypt($cipher_alg, $key, $string, MCRYPT_MODE_ECB, $iv);        var_dump($encrypted_string);        return base64_encode($encrypted_string);//转化成16进制    }protected function decrypt($string) {        $string = base64_decode($string);        //加密用的密钥文件         $key = md5("xxxxxxxx");        //加密方法         $cipher_alg = MCRYPT_TRIPLEDES;        //初始化向量来增加安全性         $iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher_alg,MCRYPT_MODE_ECB), MCRYPT_RAND);         //开始解密         $decrypted_string = mcrypt_decrypt($cipher_alg, $key, $string, MCRYPT_MODE_ECB, $iv);         return $decrypted_string;    }</code>
Copy after login
Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template