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.

    评论

报告相同问题?

悬赏问题

  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭