doufuhuang6981 2017-06-30 12:50
浏览 39

Mcrypt,PHP / MYSQL和Web表单不适用于某些条目

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

  • 写回答

1条回答 默认 最新

  • dtcd27183 2017-06-30 15:30
    关注

    Thanks for the suggestions above, it got me thinking along the right lines. I wasn't escaping the Mycrypt result, so I was generating some invalid characters, causing the MYSQL error above.

    I used: $encrypted_id=mysql_real_escape_string($encrypted_id); to resolve.

    评论

报告相同问题?