Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mcrypt相关的加解密方法已经被废弃了 #21

Closed
DaPoHou opened this issue Nov 14, 2018 · 3 comments
Closed

mcrypt相关的加解密方法已经被废弃了 #21

DaPoHou opened this issue Nov 14, 2018 · 3 comments

Comments

@DaPoHou
Copy link

DaPoHou commented Nov 14, 2018

php7.1.*或者以上版本中,mcrypt相关的加解密方法已经被废弃了,当公众号平台启用消息加密后,无法正常使用。希望能更换为openssl,谢谢。

@DaPoHou
Copy link
Author

DaPoHou commented Nov 14, 2018

src/WechatPhpSdk/Utils/Prpcrypt.class.php
其中使用的是mcrypt解密,修改为openssl方法:
第一种方法:直接使用我修改好的附件替换
Prpcrypt.class.zip
第二种方法:手动修改
30行开始,将try内容替换成下面:

try {
			//获得16位随机字符串,填充到明文之前
			$random = $this->getRandomStr();
			$text = $random . pack("N", strlen($text)) . $text . $appid;
			// 网络字节序
			$iv = substr($this->key, 0, 16);
			//使用自定义的填充方式对明文进行补位填充
			$pkc_encoder = new Pkcs7Encoder;
			$text = $pkc_encoder->encode($text);
		    $encrypted = openssl_encrypt($text, 'AES-256-CBC', $this->key, OPENSSL_RAW_DATA|OPENSSL_ZERO_PADDING, $iv);
			//使用BASE64对加密后的字符串进行编码
			return base64_encode($encrypted);
		} 

56行开始,将try内容替换成下面:

try {
			//使用BASE64对需要解密的字符串进行解码
			$ciphertext_dec = base64_decode($encrypted);
			$iv = substr($this->key, 0, 16);
		    $decrypted = openssl_decrypt($ciphertext_dec, 'AES-256-CBC', $this->key, OPENSSL_RAW_DATA|OPENSSL_ZERO_PADDING, $iv);
		} 

@hmmabc
Copy link

hmmabc commented Jul 30, 2019

我也遇到这个问题了,建议你发一个pull request

@gaoming13
Copy link
Owner

fixed in 1.8.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants