(PHP 4 >= 4.0.2, PHP 5, PHP 7 < 7.2.0, PECL mcrypt >= 1.0.0)
mdecrypt_generic — 锟斤拷锟斤拷锟斤拷锟斤拷
This function has been DEPRECATED as of PHP 7.1.0. Relying on this function is highly discouraged.
$td
, string $data
) : string锟斤拷锟斤拷锟斤拷锟捷★拷 锟斤拷注锟解,锟斤拷锟节达拷锟斤拷锟斤拷锟捷诧拷锟斤拷锟斤拷锟斤拷锟斤拷 锟斤拷锟斤拷锟街凤拷锟斤拷锟侥筹拷锟饺匡拷锟杰猴拷锟斤拷锟侥的筹拷锟饺诧拷锟斤拷取锟�
Example #1 mdecrypt_generic() 锟斤拷锟斤拷
<?php
/* 锟斤拷锟斤拷 */
$key = 'this is a very long key, even too long for the cipher';
$plain_text = 'very important data';
/* 锟津开硷拷锟斤拷模锟介,锟斤拷锟揭达拷锟斤拷锟斤拷始锟斤拷锟斤拷 */
$td = mcrypt_module_open('des', '', 'ecb', '');
$key = substr($key, 0, mcrypt_enc_get_key_size($td));
$iv_size = mcrypt_enc_get_iv_size($td);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
/* 锟斤拷始锟斤拷锟斤拷锟杰撅拷锟� */
if (mcrypt_generic_init($td, $key, $iv) != -1) {
/* 锟斤拷锟斤拷锟斤拷锟斤拷 */
$c_t = mcrypt_generic($td, $plain_text);
mcrypt_generic_deinit($td);
/* 为锟斤拷锟斤拷锟斤拷锟铰筹拷始锟斤拷锟斤拷锟斤拷锟斤拷 */
mcrypt_generic_init($td, $key, $iv);
$p_t = mdecrypt_generic($td, $c_t);
/* 执锟斤拷锟斤拷锟斤拷锟斤拷 */
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
}
if (strncmp($p_t, $plain_text, strlen($plain_text)) == 0) {
echo "ok\n";
} else {
echo "error\n";
}
?>
锟斤拷锟斤拷锟斤拷锟斤拷示锟斤拷锟斤拷渭锟斤拷 锟斤拷锟杰猴拷锟斤拷锟斤拷锟斤拷欠锟斤拷原始锟斤拷锟侥筹拷锟斤拷一锟铰★拷 锟斤拷要锟斤拷锟斤拷锟斤拷锟窖碉拷锟角o拷锟节讹拷锟斤拷锟捷斤拷锟叫伙拷锟斤拷之前锟斤拷 锟斤拷锟斤拷使锟斤拷 mcrypt_generic_init() 锟斤拷锟斤拷锟斤拷锟斤拷锟铰筹拷始锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷
锟斤拷锟矫憋拷锟斤拷锟斤拷之前锟斤拷 锟斤拷锟斤拷使锟斤拷锟斤拷钥锟酵筹拷始锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 mcrypt_generic_init() 锟斤拷锟斤拷 锟皆斤拷锟杰撅拷锟斤拷锟斤拷谐锟绞硷拷锟斤拷锟� 锟接斤拷锟杰癸拷锟斤拷锟斤拷锟街拷锟斤拷锟揭拷锟斤拷锟� mcrypt_generic_deinit() 锟斤拷锟酵放加斤拷锟杰伙拷锟斤拷锟斤拷锟斤拷 锟斤拷锟斤拷锟斤拷渭锟� mcrypt_module_open()锟斤拷