[b]用途:[/b]
用于加密,解密数据。
[b]安装:[/b]
先安装libmcrypt库
#wget http://softlayer.dl.sourceforge.net/sourceforge/mcrypt/libmcrypt-2.5.8.tar.gz#tar -zxvf libmcrypt-2.5.8.tar.gz#cd 源代码/libmcrypt-2.5.8#./configure --prefix=/usr/local#make#make install
安装php扩展
# cd php-5.x.x/ext/mcrypt# phpize# aclocal# ./configure# make && make installEnable the module by adding: 'extension=mcrypt.so' to PHP.ini.
[b]使用:[/b]
用于加密,解密数据。
[b]安装:[/b]
先安装libmcrypt库
#wget http://softlayer.dl.sourceforge.net/sourceforge/mcrypt/libmcrypt-2.5.8.tar.gz#tar -zxvf libmcrypt-2.5.8.tar.gz#cd 源代码/libmcrypt-2.5.8#./configure --prefix=/usr/local#make#make install
安装php扩展
# cd php-5.x.x/ext/mcrypt# phpize# aclocal# ./configure# make && make installEnable the module by adding: 'extension=mcrypt.so' to PHP.ini.
[b]使用:[/b]
class Cipher {
private $securekey, $iv;
public function __construct($key) {
if (!function_exists('mcrypt_create_iv')) {
throw new Exception('Please install mcrypt extension!');
}
$this->securekey = hash('sha256',$key,TRUE);
$this->iv = mcrypt_create_iv(32);
}
public function encrypt($input) {
return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->securekey, $input, MCRYPT_MODE_ECB, $this->iv));
}
public function decrypt($input) {
return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->securekey, base64_decode($input), MCRYPT_MODE_ECB, $this->iv));
}
}