PHP7安装已废弃的对称加密扩展mcrypt记录

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

http://pecl.php.net/package/mcrypt

某PHP项目中需要使用对称加密 mcrypt 加密库,由于PHP7已经将此扩展移除到PECL,需要手动安装,现记录一下。

通过 apt-cache search 名称查找 mcrypt:

$ sudo apt-get update
$ sudo apt-cache search mcrypt
gnupg-utils - GNU privacy guard - utility programs
overlayroot - use an overlayfs on top of a read-only root filesystem
golang-github-xordataexchange-crypt - Store/retrieve encrypted configs from etcd or Consul (CLI tool)
libcryptx-perl - Perl module that provides a self-contained crypto toolkit
libgringotts-dev - development files for the gringotts data encapsulation library
libgringotts2 - gringotts data encapsulation and encryption library
libmcrypt-dev - De-/Encryption Library development files
libmcrypt4 - De-/Encryption Library
libmrtd-dev - Development files for libmrtd0
libmrtd0 - MRTD - Machine-readable travel document library
libtomcrypt-dev - static library, header files and documentation for libtomcrypt
libtomcrypt1 - public domain open source cryptographic toolkit
mcrypt - Replacement for old unix crypt(1)
php7.0-mcrypt - libmcrypt module for PHP
php5.6-mcrypt - libmcrypt module for PHP
php7.1-mcrypt - libmcrypt module for PHP

可以看到,目前三个版本的(php5.6-mcrypt,php7.0-mcrypt,php7.1-mcrypt )可以选择。

安装 mcrypt 扩展

本例中的环境是通过 Laravel Homestead 安装的,有多个PHP版本。

  • PHP7.0 安装 php7.0-mcrypt
sudo apt-get install php7.0-mcrypt
sudo apt-get install libmcrypt-dev;
sudo pecl install channel://pecl.php.net/mcrypt-1.0.0 
sudo echo 'extension=mcrypt.so'|sudo tee /etc/php/7.0/mods-available/mcrypt.ini
sudo ln -s /etc/php/7.0/mods-available/mcrypt.ini /etc/php/7.0/cli/conf.d/20-mcrypt.ini
sudo service php7.0-fpm restart
  • PHP7.2 安装 php7.1-mcrypt
sudo apt-get install mcrypt php7.1-mcrypt
sudo apt-get install libmcrypt-dev;
sudo pecl install channel://pecl.php.net/mcrypt-1.0.1 
sudo echo 'extension=mcrypt.so'|sudo tee /etc/php/7.2/mods-available/mcrypt.ini
sudo ln -s /etc/php/7.2/mods-available/mcrypt.ini /etc/php/7.2/cli/conf.d/20-mcrypt.ini
sudo service php7.2-fpm restart

关于 mcrypt

本扩展是 mcrypt 库的接口,mcrypt 库提供了对多种块算法的支持, 包括:DES,TripleDES,Blowfish (默认), 3-WAY,SAFER-SK64,SAFER-SK128,TWOFISH,TEA,RC2 以及 GOST,并且支持 CBC,OFB,CFB 和 ECB 密码模式。 甚至,它还支持诸如 RC6 和 IDEA 这两种“非免费”的算法。 默认情况下,CFB/OFB 是 8 比特的。 (-- PHP手册)

mcrypt_encrypt — 使用给定参数加密明文
mcrypt_decrypt — 使用给定参数解密密文

参考链接:

PHP手册>函数参考>加密扩展(mcrypt)

PECL-Mcrypt

https://www.jianshu.com/p/4b7cdbf3bd6c

转载于:https://my.oschina.net/wangyongtao/blog/1810993

你可能感兴趣的:(PHP7安装已废弃的对称加密扩展mcrypt记录)