(PHP 4 >= 4.0.2, PHP 5, PHP 7 < 7.2.0, PECL mcrypt >= 1.0.0)
mcrypt_module_open — 锟斤拷锟姐法锟斤拷模式锟斤拷应锟斤拷模锟斤拷
This function has been DEPRECATED as of PHP 7.1.0. Relying on this function is highly discouraged.
$algorithm
, string $algorithm_directory
, string $mode
, string $mode_directory
) : resource
锟斤拷锟斤拷锟斤拷锟斤拷指锟斤拷锟姐法锟斤拷模式锟斤拷应锟斤拷模锟介。
锟姐法锟斤拷锟狡匡拷锟斤拷锟斤拷锟街凤拷锟斤拷锟斤拷锟斤拷锟斤拷 "twofish"锟斤拷
也锟斤拷锟斤拷锟斤拷 MCRYPT_ciphername
锟斤拷锟斤拷锟斤拷
锟斤拷锟斤拷 mcrypt_module_close() 锟斤拷锟斤拷锟斤拷锟皆关憋拷模锟介。
algorithm
MCRYPT_ciphername
锟斤拷锟斤拷锟叫碉拷一锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟街凤拷锟斤拷值锟斤拷锟姐法锟斤拷锟狡★拷
algorithm_directory
algorithm_directory
锟斤拷锟斤拷指示锟斤拷锟斤拷模锟斤拷锟轿伙拷谩锟�
锟斤拷锟斤拷锟斤拷峁╋拷瞬锟斤拷锟斤拷锟斤拷锟绞癸拷锟斤拷锟街革拷锟斤拷锟街碉拷锟�
锟斤拷锟斤拷锟斤拷瞬锟斤拷锟斤拷锟斤拷锟轿拷锟斤拷址锟斤拷锟斤拷锟�""锟斤拷锟斤拷锟斤拷使锟斤拷
php.ini 锟叫碉拷 mcrypt.algorithms_dir 锟斤拷
锟斤拷锟斤拷锟街革拷锟斤拷瞬锟斤拷锟斤拷锟斤拷锟绞癸拷锟� libmcrypt 锟侥憋拷锟斤拷路锟斤拷
锟斤拷通锟斤拷锟斤拷 /usr/local/lib/libmcrypt锟斤拷锟斤拷
mode
MCRYPT_MODE_modename
锟斤拷锟斤拷锟叫碉拷一锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟街凤拷锟斤拷锟叫碉拷一锟斤拷锟斤拷"ecb"锟斤拷"cbc"锟斤拷"cfb"锟斤拷"ofb"锟斤拷"nofb" 锟斤拷 "stream"锟斤拷
mode_directory
algorithm_directory
锟斤拷锟斤拷指示锟斤拷锟斤拷模式锟斤拷位锟矫★拷
锟斤拷锟斤拷锟斤拷峁╋拷瞬锟斤拷锟斤拷锟斤拷锟绞癸拷锟斤拷锟街革拷锟斤拷锟街碉拷锟�
锟斤拷锟斤拷锟斤拷瞬锟斤拷锟斤拷锟斤拷锟轿拷锟斤拷址锟斤拷锟斤拷锟�""锟斤拷锟斤拷锟斤拷使锟斤拷
php.ini 锟叫碉拷 mcrypt.modes_dir 锟斤拷
锟斤拷锟斤拷锟街革拷锟斤拷瞬锟斤拷锟斤拷锟斤拷锟绞癸拷锟� libmcrypt 锟侥憋拷锟斤拷路锟斤拷
锟斤拷通锟斤拷锟斤拷 /usr/local/lib/libmcrypt锟斤拷锟斤拷
锟缴癸拷锟津返回硷拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷蚍祷锟� FALSE
锟斤拷
Example #1 mcrypt_module_open() 锟斤拷锟斤拷
<?php
$td = mcrypt_module_open(MCRYPT_DES, '',
MCRYPT_MODE_ECB, '/usr/lib/mcrypt-modes');
$td = mcrypt_module_open('rijndael-256', '', 'ofb', '');
?>
锟斤拷锟斤拷锟叫的碉拷一锟叫达拷默锟斤拷目录锟斤拷 DES 锟斤拷锟斤拷锟姐法锟斤拷 锟斤拷 /usr/lib/mcrypt-modes 目录锟斤拷 ECB 模式锟斤拷 锟节讹拷锟斤拷示锟斤拷锟叫o拷使锟斤拷锟街凤拷锟斤拷锟斤拷式锟斤拷示锟姐法锟斤拷模式锟斤拷 锟斤拷锟斤拷锟斤拷式锟斤拷锟斤拷锟斤拷锟斤拷 libmcrypt 2.4.x 锟斤拷 2.5.x 锟芥本锟斤拷
Example #2 锟节硷拷锟斤拷锟斤拷使锟斤拷 mcrypt_module_open()
<?php
/* 锟津开硷拷锟斤拷锟姐法锟斤拷模式 */
$td = mcrypt_module_open('rijndael-256', '', 'ofb', '');
/* 锟斤拷锟斤拷锟斤拷始锟斤拷锟斤拷锟斤拷锟斤拷锟揭硷拷锟斤拷锟皆匡拷锟斤拷取锟�
* Windows 平台锟斤拷使锟斤拷 MCRYPT_RAND锟斤拷 */
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_DEV_RANDOM);
$ks = mcrypt_enc_get_key_size($td);
/* 锟斤拷锟斤拷锟斤拷钥 */
$key = substr(md5('very secret key'), 0, $ks);
/* 锟斤拷始锟斤拷锟斤拷锟斤拷 */
mcrypt_generic_init($td, $key, $iv);
/* 锟斤拷锟斤拷锟斤拷锟斤拷 */
$encrypted = mcrypt_generic($td, 'This is very important data');
/* 锟斤拷锟斤拷锟斤拷锟杰o拷执锟斤拷锟斤拷锟斤拷锟斤拷 */
mcrypt_generic_deinit($td);
/* 锟斤拷始锟斤拷锟斤拷锟斤拷模锟斤拷 */
mcrypt_generic_init($td, $key, $iv);
/* 锟斤拷锟斤拷锟斤拷锟斤拷 */
$decrypted = mdecrypt_generic($td, $encrypted);
/* 锟斤拷锟斤拷锟斤拷锟杰o拷执锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟揭关憋拷模锟斤拷 */
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
/* 锟斤拷示锟侥憋拷 */
echo trim($decrypted) . "\n";
?>