mcrypt_module_open

(PHP 4 >= 4.0.2, PHP 5, PHP 7 < 7.2.0, PECL mcrypt >= 1.0.0)

mcrypt_module_open — ���㷨��ģʽ��Ӧ��ģ��

Warning

This function has been DEPRECATED as of PHP 7.1.0. Relying on this function is highly discouraged.

˵��

mcrypt_module_open ( string $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 ģʽ�� �ڶ���ʾ���У�ʹ���ַ�����ʽ��ʾ�㷨��ģʽ�� ������ʽ�������� 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');

    
/* �������ܣ�ִ�������� */
    
mcrypt_generic_deinit($td);

    
/* ��ʼ������ģ�� */
    
mcrypt_generic_init($td, $key, $iv);

    
/* �������� */
    
$decrypted = mdecrypt_generic($td, $encrypted);

    
/* �������ܣ�ִ�������������ҹر�ģ�� */
    
mcrypt_generic_deinit($td);
    
mcrypt_module_close($td);

    
/* ��ʾ�ı� */
    
echo trim($decrypted) . "\n";
?>

�μ�