I have a MYSQL database with a column of data of which is encrypted using AES_ENCRYPT. I also have a form, where the user inputs some of this data, it's encrypted using Mcrypt (see below for code used) and verified against the MYSQL database, then if there's a match it returns true.
For most cases this works fine. However, for a small number of submissions, I get a failure in the connection to the database. It always fails for this same data, but if I try different data it is successful. So there is something unique about the data, which is causing it to fail and I can't spot a pattern. The data is the same length of characters, just a different combination of letters and numbers, i.e. hr152698 or tq452698
$mode=MCRYPT_MODE_ECB;
$enc=MCRYPT_RIJNDAEL_128;
$numblock=floor(strlen($id) / 16);
$pad_len= 16-(strlen($id) % 16);
$id=str_pad($id, (16*(floor(strlen($id) / 16)+1)),
chr($pad_len));
$encrypted_id=mcrypt_encrypt($enc, $ky, $id, $mode,
mcrypt_create_iv( mcrypt_get_iv_size($enc, $mode), MCRYPT_DEV_URANDOM));
I'm wondering if it could be to do with the number 16 in the code above. Perhaps it needs to be higher if certain text is entered? The MYSQL column that holds this data is setup as: varbinary(25).
Regards Mark