如何在WAMP中使用MCRYPT_ARCFOUR加密? [英] How to encrypt with MCRYPT_ARCFOUR in WAMP?
问题描述
我想在我的PHP代码中使用ARCFOUR算法:
I'm trying to use ARCFOUR algorithm in my PHP code:
$td = mcrypt_module_open(MCRYPT_ARCFOUR, '', MCRYPT_MODE_CBC, '');
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
mcrypt_generic_init($td, $key, $iv);
$output = mcrypt_generic($td, $input);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
问题是第一行返回警告:
and the problem is that the first line returns warning:
mcrypt_module_open(): Could not open encryption module
< hr>
我的设置:
-
从php_info ()output:
From php_info() output:
命令configure:...--with-mcrypt = static...
command configure: ... "--with-mcrypt=static" ...
如果我是正确的,这意味着我不需要DLL的mcrypt扩展。
If I'm correct it means I do not need a DLL for mcrypt extension.
支持的密码: cast-128 gost rijndael-128 twofish arcfour cast-256 loki97 rijndael-192 saferplus wake blowfish-compat des rijndael-256 serpent xtea blowfish enigma rc2 tripledes
Supported ciphers: cast-128 gost rijndael-128 twofish arcfour cast-256 loki97 rijndael-192 saferplus wake blowfish-compat des rijndael-256 serpent xtea blowfish enigma rc2 tripledes
PHP版本5.3.8
PHP version 5.3.8
Wamp 2.2a (32位)
Wamp 2.2a (32 bits)
感谢您的帮助!
推荐答案
从PHP 5.3.6和5.4.0 RC6开始, arcfour
,唤醒
和 enigma
mcrypt密码需要使用 stream
/ em>。它们不会初始化任何其他模式,也不能使用任何其他密码使用 stream
模式。
As of PHP 5.3.6 and 5.4.0 RC6, the arcfour
, wake
and enigma
mcrypt ciphers require the use of stream
mode. They will not initialize any of the other modes, nor can any of the other ciphers use stream
mode.
演示代码,使用 @
现在静默无法打开模块警告:
Demo code, with the @
present to silence the "can't open module" warning:
foreach(mcrypt_list_algorithms() as $alg) {
printf("\n%20s:", $alg);
foreach(mcrypt_list_modes() as $mode) {
$mc = @mcrypt_module_open($alg, null, $mode, null);
if(is_resource($mc)) echo "\t$mode";
else echo "\t!!FAIL!!:$mode";
}
}
echo "\n";
演示输出:
cast-128: cbc cfb ctr ecb ncfb nofb ofb !!FAIL!!:stream
gost: cbc cfb ctr ecb ncfb nofb ofb !!FAIL!!:stream
rijndael-128: cbc cfb ctr ecb ncfb nofb ofb !!FAIL!!:stream
twofish: cbc cfb ctr ecb ncfb nofb ofb !!FAIL!!:stream
arcfour: !!FAIL!!:cbc !!FAIL!!:cfb !!FAIL!!:ctr !!FAIL!!:ecb !!FAIL!!:ncfb !!FAIL!!:nofb !!FAIL!!:ofb stream
cast-256: cbc cfb ctr ecb ncfb nofb ofb !!FAIL!!:stream
loki97: cbc cfb ctr ecb ncfb nofb ofb !!FAIL!!:stream
rijndael-192: cbc cfb ctr ecb ncfb nofb ofb !!FAIL!!:stream
saferplus: cbc cfb ctr ecb ncfb nofb ofb !!FAIL!!:stream
wake: !!FAIL!!:cbc !!FAIL!!:cfb !!FAIL!!:ctr !!FAIL!!:ecb !!FAIL!!:ncfb !!FAIL!!:nofb !!FAIL!!:ofb stream
blowfish-compat: cbc cfb ctr ecb ncfb nofb ofb !!FAIL!!:stream
des: cbc cfb ctr ecb ncfb nofb ofb !!FAIL!!:stream
rijndael-256: cbc cfb ctr ecb ncfb nofb ofb !!FAIL!!:stream
serpent: cbc cfb ctr ecb ncfb nofb ofb !!FAIL!!:stream
xtea: cbc cfb ctr ecb ncfb nofb ofb !!FAIL!!:stream
blowfish: cbc cfb ctr ecb ncfb nofb ofb !!FAIL!!:stream
enigma: !!FAIL!!:cbc !!FAIL!!:cfb !!FAIL!!:ctr !!FAIL!!:ecb !!FAIL!!:ncfb !!FAIL!!:nofb !!FAIL!!:ofb stream
rc2: cbc cfb ctr ecb ncfb nofb ofb !!FAIL!!:stream
tripledes: cbc cfb ctr ecb ncfb nofb ofb !!FAIL!!:stream
正在查看 PHP错误49311 ,该问题在2009年未收到任何反馈后被关闭。 RC4 , WAKE 和谜语被打破。代码演示问题:
It looks like you (and I) are seeing PHP bug 49311, which was closed after no feedback in 2009. RC4, WAKE and Enigma are broken. Code to demonstrate the problem:
foreach(mcrypt_list_algorithms() as $algo) {
echo $algo;
$td = mcrypt_module_open($algo, '', MCRYPT_MODE_CBC, '');
echo "\n";
}
从PHP交互式提示输出到我的系统:
Output on my system, from the PHP interactive prompt:
cast-128
gost
rijndael-128
twofish
arcfourPHP Warning: mcrypt_module_open(): Could not open encryption module in php shell code on line 1
PHP Stack trace:
PHP 1. {main}() php shell code:0
PHP 2. mcrypt_module_open() php shell code:1
cast-256
loki97
rijndael-192
saferplus
wakePHP Warning: mcrypt_module_open(): Could not open encryption module in php shell code on line 1
PHP Stack trace:
PHP 1. {main}() php shell code:0
PHP 2. mcrypt_module_open() php shell code:1
blowfish-compat
des
rijndael-256
serpent
xtea
blowfish
enigmaPHP Warning: mcrypt_module_open(): Could not open encryption module in php shell code on line 1
PHP Stack trace:
PHP 1. {main}() php shell code:0
PHP 2. mcrypt_module_open() php shell code:1
rc2
tripledes
直到(除非)他们修复此错误或找到解决方法,您将需要选择不同的加密算法。
Until (unless) they fix this bug or a workaround is found, you'll want to choose a different encryption algorithm.
这篇关于如何在WAMP中使用MCRYPT_ARCFOUR加密?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!