简体   繁体   English

MySQL - 如何存储AES_Encrypted数据?

[英]MySQL - How to store AES_Encrypted data?

So I have been browsing the internet, and came across the MySQL built-in function AES_ENCRYPT. 所以我一直在浏览互联网,并且遇到了MySQL内置函数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. 它似乎并不太难使用,但有些消息来源告诉我将加密数据存储为VARCHAR,有人说将其存储为BLOB。 What should I store the encrypted data as? 我应该将加密数据存储为什么?

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. 如果要存储这些结果,请使用具有VARBINARY或BLOB二进制字符串数据类型的列。 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). 这将避免可能会更改数据值的尾随空格删除或字符集转换的潜在问题,例如,如果使用非二进制字符串数据类型(CHAR,VARCHAR,TEXT),则可能会出现此问题。

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

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. 如果需要使用VARCHAR而不是BLOB,则将加密的二进制文件转换为仅使用可打印字符的Base64,并且可以安全地存储为VARCHAR。 Of course you will need to convert it back from Base64 to binary before decrypting. 当然,在解密之前,您需要将它从Base64转换回二进制。

我总是使用blob在MySQL中存储加密数据。

You can use Binary. 你可以使用二进制。 BINARY in STRING. STRING中的BINARY。 It have to work. 它必须工作。 I am using it. 我正在使用它。 Write me answer if it doesn't working. 如果它不起作用,请给我回答。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM