在MySQL中存储敏感数据的最好办法是什么? [英] What's the best way to store sensitive data in MySQL?

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

问题描述

我正在从PHP脚本管理MySQL数据库。
通过SSL保护服务器和客户端之间的通信。
我存储敏感的用户帐户数据。



输入数据库时​​是否有一种加密数据的方法?
什么是保护敏感数据的最佳方法?



编辑:我正在使用CRON作业更新依赖此密码登录的数据用户帐号。
所以我需要一个哈希密码的方法,并且能够获得我的CRON工作任务的原始密码。



实现它的最好方法是什么?



谢谢

解决方案

认真,不要使用MySQL的aes_encrypt()它是使用块密码最不安全的方法。它是使用ECB模式,我可以给一个简单的示例演示为什么这是一个严重的错误。



纯文本消息:





使用ECB模式加密的相同消息(无论使用什么密码) :



使用CBC模式的EXACT相同消息(再次,您使用的密码无关紧要):



有更多的原因不要使用mysql的aes_encrypt,最显着的是每一个您发送的查询也将具有您使用的aes密钥。如果数据库受到威胁,攻击者将启用日志记录,只需获取您的密钥并解密整个数据库



所以应该你使用?我喜欢这个类暂时。它使用CBC模式与String2Key函数和IV。您可以使用主键作为您的IV,每个消息必须具有唯一的IV。如果攻击者知道IV,而且如果它们是顺序的,那么只要块密码实现是安全的,它就可以了。重新使用IV, WEP不太安全


I'm managing the MySQL database from PHP scripts. the communication between server and client is secured via SSL. I store user account data which is sensitive.

Is there a way to encrypt this data when entered into the DB? What is the best way to protect this sensitive data?

EDIT: I’m using a CRON job for updating data which relies on this password to login the user account. So I need a way to hash this password and to be able to get the original password for my CRON job tasks.

What’s the best way to achieve it?

Thanks

解决方案

Seriously, DON'T USE MySQL's aes_encrypt() It is the the most insecure method of using a block cipher. It is using ECB mode, and I can give a simple example demonstration why this is a serious mistake.

Plain text message:

The same message encrypted with ECB mode (doesn't matter what cipher you use):

The EXACT same message using CBC mode (again, it doesn't matter what cipher you use):

There are even more reasons not to use mysql's aes_encrypt, most notably every single query you send will also have the aes key that you use. If the database is compromised the attacker will enable logging and just get your aes key and decrypt the entire database.

So what should you use? I like this class for the time being. Its using CBC mode with a String2Key function and an IV. You can use the primary key as your IV, each message must have a unique IV. Its okay if the attacker knows the IV, and if they are sequential, so long as the block cipher implementation is secure. Reuse of an IV made WEP much less secure.

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

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