Unable to AES_DECRYPT after AES_ENCRYPT in mysql

前端 未结 4 576
遇见更好的自我
遇见更好的自我 2020-11-27 05:45

I created user table

CREATE  TABLE `user` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT ,
`first_name` VARBINARY(100) NULL ,
`address` VARBINARY(200) NOT N         


        
4条回答
  •  北荒
    北荒 (楼主)
    2020-11-27 06:40

    I had the same issue, turns out I had my column data type set as VARCHAR when I encrypted the data and when I switched over to MEDIUMTEXT, it wouldn't return anything else than a BLOB.

    Quoting a part from dev.mysql:

    Many encryption and compression functions return strings for which the result might contain arbitrary byte values. If you want to store these results, use a column with a VARBINARY or BLOB binary string data type. This will avoid potential problems with trailing space removal or character set conversion that would change data values, such as may occur if you use a nonbinary string data type (CHAR, VARCHAR, TEXT).

    Switching to a supported column type worked for me.

提交回复
热议问题