mcrypt.*锟斤拷
mdecrypt.*使锟斤拷 libmcrypt 锟结供锟剿对称的硷拷锟杰和斤拷锟杰★拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟街э拷锟�
mcrypt 锟斤拷展锟斤拷锟斤拷锟斤拷同锟斤拷锟姐法锟斤拷锟斤拷式为
mcrypt.ciphername锟斤拷锟斤拷锟斤拷
ciphername
锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷郑锟斤拷锟斤拷锟斤拷锟斤拷莞锟�
mcrypt_module_open()锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷茫锟�
锟斤拷锟斤拷 | 锟角凤拷锟斤拷锟� | 默锟斤拷值 | 取值锟斤拷锟斤拷 |
---|---|---|---|
mode | 锟斤拷选 | cbc | cbc, cfb, ecb, nofb, ofb, stream |
algorithms_dir | 锟斤拷选 | ini_get('mcrypt.algorithms_dir') | algorithms 模锟斤拷锟侥柯� |
modes_dir | 锟斤拷选 | ini_get('mcrypt.modes_dir') | modes 模锟斤拷锟侥柯� |
iv | 锟斤拷锟斤拷 | N/A | 锟斤拷锟斤拷为 8锟斤拷16 锟斤拷 32 锟街节的讹拷锟斤拷锟斤拷锟斤拷锟捷★拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟� |
key | 锟斤拷锟斤拷 | N/A | 锟斤拷锟斤拷为 8锟斤拷16 锟斤拷 32 锟街节的讹拷锟斤拷锟斤拷锟斤拷锟捷★拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟� |
Example #1 锟斤拷 3DES 锟斤拷锟侥硷拷锟斤拷锟斤拷锟斤拷锟�
<?php
$passphrase = 'My secret';
/* Turn a human readable passphrase
* into a reproducable iv/key pair
*/
$iv = substr(md5('iv'.$passphrase, true), 0, 8);
$key = substr(md5('pass1'.$passphrase, true) .
md5('pass2'.$passphrase, true), 0, 24);
$opts = array('iv'=>$iv, 'key'=>$key);
$fp = fopen('secert-file.enc', 'wb');
stream_filter_append($fp, 'mcrypt.tripledes', STREAM_FILTER_WRITE, $opts);
fwrite($fp, 'Secret secret secret data');
fclose($fp);
?>
Example #2 锟斤拷取锟斤拷锟杰碉拷锟侥硷拷
<?php
$passphrase = 'My secret';
/* Turn a human readable passphrase
* into a reproducable iv/key pair
*/
$iv = substr(md5('iv'.$passphrase, true), 0, 8);
$key = substr(md5('pass1'.$passphrase, true) .
md5('pass2'.$passphrase, true), 0, 24);
$opts = array('iv'=>$iv, 'key'=>$key);
$fp = fopen('secert-file.enc', 'rb');
stream_filter_append($fp, 'mdecrypt.tripledes', STREAM_FILTER_WRITE, $opts);
$data = rtrim(stream_get_contents($fp));
fclose($fp);
echo $data;
?>