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;
?>