微信(小程序)mcrypt_module_open() 无法使用
发布时间:2023-09-15, 00:43:16 分类:PHP | 编辑 off 网址 | 辅助
正文 2713字数 46,829阅读
在PHP7 中 mcrypt_module_open()已经被 OPENSSL 取代.
当然你要是还是想用 mcrypt_module_open()就安装 mcrypt 扩展.
扩展从PHP7.1.0 开始废弃
方法一:
宝塔面板安装mcrypt扩展
yum install libmcrypt libmcrypt-devel mcrypt mhash
wget http://pecl.php.net/get/mcrypt-1.0.1.tgz
tar xf mcrypt-1.0.1.tgz
cd mcrypt-1.0.1
/www/server/php/72/bin/phpize
./configure --with-php-config=/www/server/php/72/bin/php-config && make && make install
Run code
Cut to clipboard
成功后在宝塔面板-软件管理-PHP7.2 设置-配置文件
随便在合适的位置添加一行:
extension=mcrypt.so
Run code
Cut to clipboard
之后重启服务器的PHP服务即可完成mcrypt扩展的安装。
方法二:
使用 openssl 代替 mcrypt:
WXBizDataCrypt.php
public function decryptData( $encryptedData, $iv, &$data )
{
if (strlen($this->sessionKey) != 24) {
return ErrorCode::$IllegalAesKey;
}
$aesKey=base64_decode($this->sessionKey);
if (strlen($iv) != 24) {
return ErrorCode::$IllegalIv;
}
$aesIV=base64_decode($iv);
// $aesCipher=base64_decode($encryptedData);
$aesCipher=$encryptedData;
$pc = new Prpcrypt($aesKey);
$result = $pc->decrypt($aesCipher,$aesIV);
//var_dump($result);
if ($result[0] != 0) {
return $result[0];
}
$dataObj=json_decode( $result[1] );
if( $dataObj == NULL )
{
return ErrorCode::$IllegalBuffer.'--';
}
if( $dataObj->watermark->appid != $this->appid )
{
return ErrorCode::$IllegalBuffer.';;';
}
$data = $result[1];
return ErrorCode::$OK;
}
Run code
Cut to clipboard
PKCS7Encoder.php
/**
* 对密文进行解密
* [@param](https://my.oschina.net/u/2303379) string $aesCipher 需要解密的密文
* [@param](https://my.oschina.net/u/2303379) string $aesIV 解密的初始向量
* [@return](https://my.oschina.net/u/556800) 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_ZERO_PADDING,$aesIV);
// var_dump($decrypted);
} 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);
}
Run code
Cut to clipboard
原文
https://blog.kieng.cn/2740.html
(支付宝)给作者钱财以资鼓励 (微信)→
有过 1 条评论 »
宝塔面板安装第三方 PHP 扩展 libsodium sodium
php sodium.so
宝塔多个版本PHP切换默认PHP版本
切换命令
php -v
ln -sf /www/server/php/72/bin/php /usr/bin/php
Laravel 报错:”RuntimeException inEncrypter.php line 43: The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.”是因为没有有效的APP_KEY。
php artisan key:generate
打开.env配置文件会发现APP_KEY处已经生成了一个新的APP_KEY,如果没有,把运行命令生成的key值复制粘贴到文件中保存即可。
Please provide a valid cache path.
Please provide a valid cache path.
是因为laravel的缓存路径没有找到,
laravel的缓存文件路径是在 config/cache.php中设置的,
默认存放在storage文件夹中。
解决方法是:
确保storage目录下有app,framework,views三个目录并有读写权限
确保storage/framework目录下有cache,sessions,views三个目录并有读写权限
如果缺少以上目录,手动创建出来即可。
重新生成
php artisan key:generate
清除缓存
php artisan config:clear
记得缓存回来
php artisan config:cache
php artisan key:generate
The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct