I encrypt some data and get significantly different results in srcipt runtime between systems.
Running my algorithm on a win7 machine, encryption is completed in 3-8 thousand seconds.
The same code on linux (ubuntu11 and debian6) takes 7 to 35 seconds.
This is not very acceptable for my needs, and I was wondering if any person could shed light.
Relevant code below:
<?php class MyEncryption { public function __construct( $keyData ) { $this->_encryptInit( $keyData ); } private function _encryptInit( $keyData ) { $this->ch = mcrypt_module_open('rijndael-256', '', MCRYPT_MODE_ECB , ''); $vector = mcrypt_create_iv (mcrypt_enc_get_iv_size( $this->ch ), MCRYPT_DEV_RANDOM ); $keySize = mcrypt_enc_get_key_size( $this->ch ); $key = substr( hash('SHA512', $keyData . $keySize ), 0, $keySize ); mcrypt_generic_init( $this->ch, $key, $vector ); } private function _encryptClose() { mcrypt_generic_deinit( $this->ch ); mcrypt_module_close( $this->ch ); } public function encryptData( $data ) { $safeData = mcrypt_generic( $this->ch, $data ); $this->_encryptClose(); return $safeData; } public function decryptData( $safeData ) { $data = mdecrypt_generic( $this->ch, $safeData ); $this->_encryptClose(); return $data; } }
running this code is where I see the discrepancies:
<?php echo microtime(). ' -- Start || '.PHP_EOL; $enc = new MyEncryption( 'astring' ); echo microtime(). ' -- Init || '.PHP_EOL; $data = array( 'dob'=>'1970-01-01','creditcardno'=>'4000123412345678' ); $safeData = $enc->encryptData( json_encode( $data ) ); echo microtime(). ' -- Encrypted || '.PHP_EOL; echo ' == ' . $safeData . ' == '.PHP_EOL; $dec = new MyEncryption( 'astring' ); echo microtime(). ' -- Init2 || '.PHP_EOL; $data = json_decode( $dec->decryptData( trim( $safeData ) ) ); echo microtime(). ' -- Decrypted || '.PHP_EOL; echo ' == ' . $data . ' == '.PHP_EOL;
Any pointers would be greatly appreciated.
source share