在MySQL DB中存储“敏感”数据 [英] Store 'sensitive' data in MySQL DB

查看:105
本文介绍了在MySQL DB中存储“敏感”数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

应该如何将敏感数据存储在MySQL数据库中?

1)我应该更多地关注MySQL数据库的安全性并将数据存储为纯文本?

1) Should I focus more on the security of the MySQL database and store the data as plain text?

  • I found a step by step tutorial on how to make a MySQL database more secure:
  • http://www.symantec.com/connect/articles/securing-mysql-step-step

2)我应该加密数据吗?

2) Should I encrypt the data?


  • 如果是,那么应该如何进行加密?
  • If yes, then how should the encryption be done?

  1. 使用MySQL aes_encrypt / aes_decrypt?

  2. 使用PHP AES函数/算法对数据进行加密/解密?


  • 存储在MySQL中?

  • How should the data be stored in MySQL?


    1. BLOB

    2. BINARY

    3. VARBINARY


  • 在我的情况下,敏感数据是个人付款。

    In my case the 'sensitive' data are payments done by individuals.

    谢谢

    推荐答案

    这是两者的混合。两个现有的答案(当时我写这个 https://stackoverflow.com/a/10718397/1015483 https://stackoverflow.com/a/10718459/1015483 )是有效的 - 您需要查看5种可能的攻击方法我可以想到

    It's a mixture of both. Two existing answers (at the time I wrote this https://stackoverflow.com/a/10718397/1015483 and https://stackoverflow.com/a/10718459/1015483) are valid - you need to look at about 5 methods of possible attack that I can think of


    • 他们可以访问您的数据库服务器;所以是的,确保宝宝尽可能合理(马特的答案)

    • 独立数据劫持(有人以某种方式获取数据库数据,可能是备份,可能是他们猜测密码,如果您将数据从一个地方传输到另一个地方,可能是MITM)。为此,您可以剔除您的数据。您也可能会因某种原因进行CSV转储,并向某人发送电子邮件。哎呦。但是它发生了。所以加密(vlzvt的答案)

    但是没有提到三个元素:

    But three elements not mentioned:


    • 他们可以访问您的Web服务器(如果与DB服务器不同)。如果他们可以访问网络服务器,所有的赌注都是关闭的,因为他们有你的密码,贪婪的钥匙很多。所以你需要使数据库服务器更安全。 (Matt可能意味着以上 - 但只是清楚)

    • 与上述类似,但不要忘记,如果有人访问phpMyAdmin或您的管理团体。不要使用纯文本认证或配置存储的密​​码进行访问。

    • 最后,您的应用程序本身(最难锁定)。您需要防止可能泄露数据的SQL注入。如果有人通过未经查询的查询获得访问权限,则加密数据将阻止最小化问题 - 因此,加密是解决方案。

    对于您的问题的第2部分:

    For part 2 of your question:

    使用MySQL加密/解密功能将阻止有权访问原始数据的用户,但不是MITM或SQL注入,甚至是CSV转储用于传输。

    Using MySQL encrypt/decrypt functions will stop someone who has access to the raw data, but not MITM or SQL injection or even CSV dumps taken for transport.

    所以,IMO(这只是我的看法和我做的方式)是使用PHP加密,并通过线路加密数据,因为停止捕获数据的所有方法和CSV转储将被加扰。

    So, IMO (and it's only my opinion and the way I've done it) is to encrypt with PHP and sned the encrypted data over the wire, as that stops all methods of trapping the data, and a CSV dump will be "scrambled".

    如果你这样做,你可以使用varbinary / blob类型,因为它停止你不小心尝试读取/编辑phpMyAdmin。另外可以节省几个字节的名义上(尽管这取决于索引和其他的东西 - 所以一个人不是一个赢家的争论)。

    If you do that, you may as well use the varbinary / blob types as it stops you accidentally trying to read/edit in phpMyAdmin. Plus potentially saves a few bytes nominally (although this depends on indexes and other stuff - so that alone is not a winning argument).

    现在的下一面:搜索和排序。任何您索引或搜索的内容,如果加密,将只匹配完整的,精确的,区分大小写的字符串填充到正确的长度(通常搜索将不区分大小写,您可以使用LIKE进行部分搜索)。如果你想要ORDER BY,那么你需要原始的字符串。所以在设计结构时要记住。

    And now the down side: searching and sorting. Anything you index or search on, if encrypted, will only match the entire, exact, case sensitive string padded to the correct length (normally a search will be case insensitive, and you can do part searches with LIKE). And if you want to ORDER BY then you need the original strings. So bear than in mind when designing the structure.

    希望有帮助。

    这篇关于在MySQL DB中存储“敏感”数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆