MySQL - How to store AES_Encrypted data?

只谈情不闲聊 提交于 2020-01-29 04:27:07

问题


So I have been browsing the internet, and came across the MySQL built-in function AES_ENCRYPT. It doesn't seem too hard to use, but some sources tell me to store the encrypted data as a VARCHAR, and some say to store it as a BLOB. What should I store the encrypted data as?


回答1:


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).

Source: http://dev.mysql.com/doc/refman/5.5/en/encryption-functions.html




回答2:


If you need to use VARCHAR, rather than BLOB, then convert the encrypted binary to Base64 which only uses printable characters and can be safely stored as VARCHAR. Of course you will need to convert it back from Base64 to binary before decrypting.




回答3:


I have always used blobs to stored encrypted data in MySQL.




回答4:


You can use Binary. BINARY in STRING. It have to work. I am using it. Write me answer if it doesn't working.



来源:https://stackoverflow.com/questions/7461962/mysql-how-to-store-aes-encrypted-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!