微信小程序加密数据(encryptedData)解密中的PHP代码,php7.1报错mcrypt_module_ is deprecated
来源:互联网 发布:c语言对二维数组排序 编辑:程序博客网 时间:2024/05/16 09:47
最近在开发微信小程序涉及到加密数据(encryptedData)的解密,用的是PHP代码,在运行后报错mcrypt_module_ xxx is deprecated,提示方法已过时了
一看就知道是php7.1版本引起的,经研究得知,可以使用openssl方法代替解密.
首先要知道微信方使用的是AES-128-CBC加密的:
所以我们采用openssl也应该对应:
/** * 对密文进行解密 * @param string $aesCipher 需要解密的密文 * @param string $aesIV 解密的初始向量 * @return string 解密得到的明文 */public function decrypt( $aesCipher, $aesIV ){try {// $module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');// mcrypt_generic_init($module, $this->key, $aesIV);// //解密// $decrypted = mdecrypt_generic($module, $aesCipher);// mcrypt_generic_deinit($module);// mcrypt_module_close($module); $decrypted = openssl_decrypt($aesCipher, "aes-128-cbc", $this->key, OPENSSL_RAW_DATA ,$aesIV);} catch (Exception $e) {return array(ErrorCode::$IllegalBuffer, null);}try {//去除补位字符$pkc_encoder = new PKCS7Encoder;$result = $pkc_encoder->decode($decrypted);} catch (Exception $e) {//print $e;return array(ErrorCode::$IllegalBuffer, null);}return array(0, $result);}特别注意 :
很多解密失败是因为在使用openssl_decrypt解密的时候又使用了一次base_decode,实际上微信demo在调用这个方法之前就已经把所有参数都base_decode了一次:
所以解密的方法应该是如此
openssl_decrypt($aesCipher, "aes-128-cbc", $this->key, OPENSSL_RAW_DATA ,$aesIV);
阅读全文
0 0
- 微信小程序加密数据(encryptedData)解密中的PHP代码,php7.1报错mcrypt_module_ is deprecated
- 微信小程序解密encryptedData数据字符串,php中隐形字符65279(utf-8的BOM头)问题
- C#/.net微信小程序encryptedData解密
- C#/.net微信小程序encryptedData解密
- 微信小程序--用户信息encryptedData
- php数据加密解密
- php报错:Deprecated: Assigning the return value of new by reference is deprecated in
- php版本不同导致报错:Deprecated: Function eregi() is deprecated in
- php接口数据加密、解密、验证签名代码实例
- PHP代码加密_解密
- php简单加密解密代码
- 【php】数据加密与解密
- PHP的数据加密解密
- php 报错Deprecated: Assigning the return value of new by reference is deprecated in的解决办法
- MSSQL数据加密解密代码
- php 实现php代码的加密解密
- php7.1以上版本 mcrypt拓展无法使用导致小程序登录数据无法解密
- 微信小程序加密数据解密的java实现
- 函数柯里化
- activity的launchmode和taskAffinity学习笔记(二)
- StoryBoard segue 用法
- 使用Go实现了一个ping命令
- General Functions & Conditional Expressions
- 微信小程序加密数据(encryptedData)解密中的PHP代码,php7.1报错mcrypt_module_ is deprecated
- 解读大数据行业在2017年的新发展
- JS继承之间的
- char[] 操作
- Eclipse编写C++出现Symbol 'std' could not be resolved错误提示
- php发送get、post请求的6种方法简明总结
- Form submission canceled because the form is not connected 解决办法
- JNI NDK (AndroidStudio+CMake )实现C C++调用Java代码流程
- Ruby中的inject