求php7.1 加密函式mcrypt_module_open()替換方案
php mcrypt 擴充套件模組安裝及使用
php7.1中使用openssl替換mcrypt
linux版openssl生成rsa公私鑰
php 7.2 安裝 mcrypt 擴充套件
1.yum 安裝依賴包
#yum install libmcrypt libmcrypt-devel mcrypt mhash
#wget
#tar xf mcrypt-1.0.1.tgz
#cd mcrypt-1.0.1
3.編譯安裝 mcrypt
#/usr/local/php/bin/phpize
#./configure --with-php-config=/usr/local/php/bin/php-config && make && make install
4.在php.ini加上擴充套件即可
#extension=mcrypt.so
5.重啟 php-fpm
#/etc/init.d/php-fpm restart
#service php-fpm restart
6.重啟apache
#service httpd restart
注意:
下面看看用openssl實現對稱加密aes和非對稱加密rsa.
aes:
<?php
header('content-type: text/plain;charset=utf-8');
$data = 'phpbest';
$key = 'oscgu3fj8m/tdcyvsbehwi91m1fcwvqqwufppodhlfk='; //echo base64_encode(openssl_random_pseudo_bytes(32));
$iv = 'w2wjcncteg09danppi7sxq=='; //echo base64_encode(openssl_random_pseudo_bytes(16));
echo '內容: '.$data."\n";
$encrypted = openssl_encrypt($data, 'aes-256-cbc', base64_decode($key), openssl_raw_data, base64_decode($iv));
echo '加密: '.base64_encode($encrypted)."\n";
$encrypted = base64_decode('to3qffvgjnm84kbkg1plza==');
$decrypted = openssl_decrypt($encrypted, 'aes-256-cbc', base64_decode($key), openssl_raw_data, base64_decode($iv));
echo '解密: '.$decrypted."\n";
?>
rsa:
用openssl生成rsa金鑰對(私鑰/公鑰):
openssl genrsa -out rsa_private_key.pem 1024
openssl rsa -pubout -in rsa_private_key.pem -out rsa_public_key.pem
<?php
header('content-type: text/plain;charset=utf-8');
$data = 'phpbest';
echo '原始內容: '.$data."\n";
openssl_public_encrypt($data, $encrypted, file_get_contents(dirname(__file__).'/rsa_public_key.pem'));
echo '公鑰加密: '.base64_encode($encrypted)."\n";
$encrypted = base64_decode('nmd7yrx37u5azrpxukingesunyisuhwthekrmra0od0=');
openssl_private_decrypt($encrypted, $decrypted, file_get_contents(dirname(__file__).'/rsa_private_key.pem'));
echo '私鑰解密: '.$decrypted."\n";
?>
執行程式報異常找不到rsa_public_key.pem,rsa_private_key.pem
#openssl version -v //檢視openssl的版本
//生成私鑰 *.pem檔案放在當前資料夾下
#openssl genrsa -out rsa_private_key.pem 1024
//對私鑰進行pkcs#8編碼
# openssl pkcs8 -topk8 -in rsa_private_key.pem -out pkcs8_rsa_private_key.pem -nocrypt
//根據生成的私鑰生成公鑰
#openssl rsa -in rsa_private_key.pem -out rsa_public_key.pem -pubout
安裝PHP7 0 32(yum安裝 原始碼安裝)
3 原始碼安裝php c 編譯 d 安裝 e 配置php fpm f php fpm的一些命令 本文介紹兩種php安裝方式 yum安裝 原始碼安裝 yum install php70w common php70w php70w opcache php70w gd php70w mysqlnd php...
CentOS下php安裝mcrypt擴充套件
原始碼編譯安裝 libmcrypt libmcrypt 2.5.8.tar.gz mcrypt mcrypt 2.6.8.tar.gz mhash mhash 0.9.9.9.tar.gz wget wget wget 安裝lmcrypt tar zxvf libmcrypt 2.5 8.tar g...
Mac 下 安裝php擴充套件 mcrypt
net distributions php 5.5 30.tar gz2.編譯 phpize configure make make install 3.開啟php.ini,新增extension mcrypt.so 問題一 執行 phpize 報錯如下 grep usr include php m...