两者兼而有之。两种现有答案(当我写下这个和)有效,你需要研究五种可能的攻击方法,我可以想象
- They get access to your DB server; so yes, secure that baby as much as is reasonable (Matt s answer)
- Stand alone data hijacking (someone gets to your database data somehow else, could be a backup, could be they guess a password, could be MITM if you transfer data from one place to another). For this, you do encypt your data. You also may do a CSV dump for some reason and e-mail to someone. Whoops. But it happens. So encrypt (vlzvt s answer)
但以下三个因素没有提及:
- They could gain access to your web server (if different from your DB server). If they have access to the webserver, all bets are off as they have your password, encyption keys the lot. So you need to make that even more secure than the DB server. (Matt might have meant that above - but just make it clear)
- Similar to above, but not to be forgotten, is if someone gets access to phpMyAdmin or your management consule. Don t use plain text auth or config stored passwords for access.
- Finally there s your application itself (and the hardest to lock down). You need to prevent against SQL injections that may reveal data. Encrypting the data would stop minimise problems if someone did gain access through an untrapped query - so for this, encryption is the solution.
关于你的第2部分问题:
使用 MySQL 加密/ 解密功能将阻止能够访问原始数据的人, 但不阻止 MITM 或 SQL 注入, 甚至阻止 CSV 垃圾堆放 。
因此,海事组织(而这只是我的看法和我的做法)是用PHP加密并把加密数据钉在铁丝上,因为这样可以停止所有捕捉数据的方法,而CSV垃圾场将被“拆散”。
如果您这样做, 您可能也可以使用 valbinary / blob 类型, 因为它阻止了您不小心在 phpMyAdmin 中尝试阅读/ 编辑。 此外, 名义上还可能节省几字节( 虽然这取决于指数和其他东西 — — 这样单靠指数和其他东西是不会赢的论据 ) 。
现在的下边是搜索和排序。 任何您索引或搜索, 如果加密的话, 只会匹配整个, 准确, 案件敏感字符串, 并添加到正确的长度( 通常搜索会不敏感, 您可以使用类似的方式进行部分搜索 ) 。 如果您想要 ORDER, 那么您需要原始字符串 。 所以在设计结构时要记住它 。
希望这有帮助。