Php mcrypt初始化模块的时间过长
我有一个类,它有以下结构Php mcrypt初始化模块的时间过长,php,mcrypt,Php,Mcrypt,我有一个类,它有以下结构 final class mydecoder { private $td; public function __construct($key){ /* Open the cipher */ $this->td = mcrypt_module_open(MCRYPT_BLOWFISH, '', 'ecb', ''); /* Create the IV and determine the keysize l
final class mydecoder {
private $td;
public function __construct($key){
/* Open the cipher */
$this->td = mcrypt_module_open(MCRYPT_BLOWFISH, '', 'ecb', '');
/* Create the IV and determine the keysize length, use MCRYPT_RAND
* on Windows instead */
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($this->td), MCRYPT_DEV_RANDOM);
$ks = mcrypt_enc_get_key_size($this->td);
/* Create key */
$key = substr(md5($key), 0, $ks);
/* Intialize encryption */
mcrypt_generic_init($this->td, $key, $iv);
}
}
当我这样称呼它时:
$encoder = new myfish('mykey1');
$encoder = new myfish('mykey2');
我有以下问题
第一次翻页
construct #1 execution time: 5s
construct #2 execution time: 0s
按F5
construct #1 execution time: 0s
construct #2 execution time: 14s
construct #1 execution time: 5s
construct #2 execution time: 14s
按F5
construct #1 execution time: 0s
construct #2 execution time: 14s
construct #1 execution time: 5s
construct #2 execution time: 14s
捣碎F5 3次(排队)
看起来像是在排队?它是如何工作的?也许我没有正确地使用它?我对加密技术没有太多经验,因为我以前从未使用过:)问题是由初始化向量(IV)生成器引起的,即这一行:
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($this->td), MCRYPT_DEV_RANDOM);
如果您使用MCRYPT\u DEV\u RANDOM
模式,PHP将等到有足够的熵来保证安全
但是,如果您将模式更改为
MCRYPT\u DEV\u URANDOM
(安全性会降低),但如果熵太低,它不会等待,从而提高速度。因此,基本上,使用MCRYPT\u DEV\u RANDOM
会造成延迟,因此随机数彼此之间的距离“更远”?我为您找到了一个更好的解释: