我怎样才能安全地存储在MySQL数据库中的敏感数据?(How can I store sensiti

2019-07-20 11:00发布

我正在为我工​​作的公司的工作申请。 我知道了,以防止SQL注入和XSS一些技巧。 我的主要问题是保持安全的敏感信息,如SSN和地址,因为公司需要,为了使1099分的形式对销售人员的税收。

我不知道如何做到这一点的一部分,但我要加密的一切,然后将其解密,当它进入MySQL数据库?

Answer 1:

这是一个过于简化的答案,并应采取与一粒盐,因为有关安全最答案:

  • 到处使用SSL。

  • 使用安全的加密密钥

对于加密数据的存储,你可以使用一个BLOB字段,并使用MySQL的内置加密功能 。 例:

update mytable set myfield = AES_ENCRYPT('some value', SHA2('your secure secret key', 512));

如果你喜欢做在应用程序代码的加密/解密,看看PHP的这个Mcrypt功能。

  • 加密用户输入
  • 在数据库中存储
  • 读取之后将其解密

这绝不是一个完整的指南,但它是一个开始,比什么都不做要好。

您可以了解更多关于https://security.stackexchange.com/



Answer 2:

SQL query with key in it (as Wesley Murch suggests) is not a good idea. If you do:

update mytable set myfield = AES_ENCRYPT('some value', 'your secure secret key');

... and the query gets logged (slowlog for inst.) your secure secret key is captured in plain text, which should never happen. Such a query with the secret key would be also visible when you run query like SHOW PROCESSLIST.

Next problem where to store the secure key? In PHP file? It is again plain text.

Encrypt data:

Use private/public key encryption (http://en.wikipedia.org/wiki/Public-key_cryptography). PHP has quite good support for it.

  • Public keys can be stored with the user in DB, it is public.
  • Private key can be encrypted with user's password. When user logs in, you decrypt the private key and store it in his cookies (if you use SSL, it is not that bad place) or session. Both are not perfect but better than plain text in php file.
  • Use the public key to encrypt, private key to decrypt.
  • Only user will have the access to his data.

If you want to learn more, you can google "user controlled encryption" or "zero knowledge privacy".

SQL inserts / XSS:

The best protection is secure app. No doubt. If you want to secure it, you can use for inst PHP IDS to detect attacks: https://github.com/PHPIDS/PHPIDS

I have quite good experience with it.



Answer 3:

正如评论暗示,你问一个巨大的问题。 你将需要研究一些不同的问题:

  • SQL注入和如何预防
  • XSS和如何预防
  • 加密使用SSL提交的表单数据
  • 用于在数据库中存储的敏感信息的最佳实践

这将是很难解决所有这些问题的一个答案。 我建议在这个网站上面提到的话题进行一些搜索。



文章来源: How can I store sensitive data securely in a MySQL database?