English 中文(简体)
在 MySQL DB 中存储敏感数据
原标题:Store sensitive data in MySQL DB

敏感数据应如何储存在 MySQL 数据库中? < 坚固>

1) 我是否应该更注重 MySQL 数据库的安全性,并将数据作为纯文本存储?

2) 我应该加密数据吗?

  • If yes, then how should the encryption be done?
    1. Using MySQL aes_encrypt/aes_decrypt?
    2. Using PHP AES functions/algorithm for encrypting/decrypting data?
  • How should the data be stored in MySQL?
    1. BLOB
    2. BINARY
    3. VARBINARY

在我看来,敏感数据是个人支付的款项。

谢谢 谢谢

最佳回答

两者兼而有之。两种现有答案(当我写下这个)有效,你需要研究五种可能的攻击方法,我可以想象

  • 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, 那么您需要原始字符串 。 所以在设计结构时要记住它 。

希望这有帮助。

问题回答

如果攻击者能够访问纯文本数据,那么最糟糕的情景是什么?鉴于你必须解密数据,以便使其有用,因此你也需要加密密钥才能进入某处,任何能够到达 DB 的攻击者都可能也能找到密钥,除非这是为了存档,而不是像一个实况网站。我只关注 DB 服务器的安全性,除非你重新将可能丢失的数据全部嵌入 HDD 中,但它真的取决于你为什么需要加密它。

if you need to secure the data in your possibly hacked database, you can encrypt it with mcrypt

$key = "mykey";
$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256,$key,$data,MCRYPT_MODE_ECB,$key);

after that you can select BLOB,TEXT,MEDIUMTEXT or anything, based on the ~expected data size. * for VARBINARY/BINARY you might need to pack it first.

加密操作有额外的成本。

您需要评估在您的假想中,如果您的数据发展到相当大的规模,您需要评估在您的假想中,如果您的数据发展到相当大,这种额外费用将是一个问题,例如。

第一个避免数据泄漏的前沿是强有力的数据存取政策,配有存取图例的类似数据。 这样做的不利之处在于您需要管理 Mysql 并配置它 。

如果您想要关注剖面图的配置,您可以将数据加密,假设在 CPU 和(取决于电源算法) 的额外存储空间中产生额外费用。

系统的安全性相当于更弱部分的安全性, 不要只集中精力进行加密任务, 这只能给你一种安全感, 如果数据可以解密, 入侵者唯一需要的就是 打破加密的时间和粗力





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签