I keep getting these warnings:
Warning: mcrypt_generic_init(): mcrypt_generic_init(): 1 is not a valid MCrypt resource in C:\Users\dever\Desktop\web code\HeloWorld\HeloWorld\Crypt.php on line 123, column 9.
Warning: mdecrypt_generic(): mdecrypt_generic(): 1 is not a valid MCrypt resource in C:\Users\dever\Desktop\web code\HeloWorld\HeloWorld\Crypt.php on line 124, column 9.
Warning: mcrypt_generic_deinit(): mcrypt_generic_deinit(): 1 is not a valid MCrypt resource in C:\Users\dever\Desktop\web code\HeloWorld\HeloWorld\Crypt.php on line 125, column 9.
Warning: mcrypt_generic_init(): mcrypt_generic_init(): 1 is not a valid MCrypt resource in C:\Users\dever\Desktop\web code\HeloWorld\HeloWorld\Crypt.php on line 100, column 9.
Warning: mcrypt_generic(): mcrypt_generic(): 1 is not a valid MCrypt resource in C:\Users\dever\Desktop\web code\HeloWorld\HeloWorld\Crypt.php on line 105, column 9.
Warning: mcrypt_generic_deinit(): mcrypt_generic_deinit(): 1 is not a valid MCrypt resource in C:\Users\dever\Desktop\web code\HeloWorld\HeloWorld\Crypt.php on line 107, column 9.
Since it is a warning and the strings "seem" to be encrypted I have ignored it till now. However it seems that the remote server I am working with is not liking the encrypted string and returning errors to me stating as much.
Here is the code generating those warnings:
mcrypt_generic_init($this->_td, $this->_key, $iv);
$data = mdecrypt_generic($this->_td, $data);
mcrypt_generic_deinit($this->_td);
and
$iv = mcrypt_create_iv(self::AES_BLOCK_SIZE, $random_source);
$s = mcrypt_generic_init($this->_td, $this->_key, $iv);
if( ($s < 0) || ($s === false))
die( "Really an error" );
$data = mcrypt_generic($this->_td, $data);
$data = $iv.$data;
mcrypt_generic_deinit($this->_td);
I have researched but could not find out what these warnings meen, if they are effecting the encryption/decryption or what exactly is the problem? Im pretty sure its not the code (as I have it working on a different server).
Here is a test I've performed, that reproduces the values you're seeing in your var_dump
s:
$td = mcrypt_module_open(MCRYPT_DES, '', MCRYPT_MODE_ECB, '/usr/lib/mcrypt-modes');
var_dump($td);
mcrypt_module_close($td);
var_dump($td);
It prints:
resource(4) of type (mcrypt)
resource(4) of type (Unknown)
Since you're seeing the same behavior (resource id remains the same, but loses its mcrypt
association), it seems that you're closing your module resource at some point between initializing $this->_td
and actually calling mcrypt_generic_init
.