aes key iv从mysql,如何安全地处理AES“Key”和“IV”值

news/2024/7/7 15:20:08

If I use AES (System.Security.Cryptography) to simply encrypt and decrypt blob or memo fields in a SQL server, then where do I store the “Key” and “IV” values on the server? (File, Regkey, Dbase,...)

And what with the protection of those AES “Key” and “IV” values?

The background question is more : If “they” hack the server and get the dbase... then probably they can get to the program that do the encryption stuff also (It's on the same server, can't help it)... and if "they" are very good, then they will notice where the “Key” and “IV” values are stored...(.NET 4.5 ILSPY) and everything can be decrypted again.

Please advice? How do you all handle AES “Key” and “IV” value’s?

Ps: This is not about pwd fields... so, it's not about hashing... its pure data cryptography.

解决方案

The IV has been thoroughly covered by the other answers, so I'll focus just on storing the key.

First...

I can't except it could not be done on a single server at software level.

Anything done in software can be undone in software. You can encrypt, hide, and lock it in as many safes as you want, but your application still needs to be able to get access to the key. If your application has access, then someone with the same level of access as your application is able to get to it as well.

Developers have been dealing with this problem for a very long time and there is no silver bullet.

This all is setup in a single server environment (application plus dbase), so I’m not able to send/retrieve the key to a second server. Also, in this “special” case I’m not able to encrypt the key by a machine-level or user-level RSA key container.

I can think of two possible solutions.

Option 1:

Store the key on disk and, at the OS level, configure file access so that only the account your application is running under can read the file the key is contained in. The file could be a flat file, or an encrypted container that's protected by a password which your application knows (up to you to decide, but an encrypted container is better).

Pros:

Restarts without human intervention.

Cons:

You have to do OS security right and there is no room for error.

An attacker with administrator access can get to the key.

Another similar option to this would be to use DPAPI instead of files for storing the key (as long as you're able to do this given your "special case"). This is an API built in to windows that utilizes the password for whatever windows account you (or your application) is running under to securely store data. Only the windows account that stored the data is able to retrieve it.

One particularly nice feature of DPAPI is that, if an administrator resets a users password (via computer management), access to that users DPAPI data is lost. An attacker would need to compromise the actual account that was used to store the data in the first place without resetting the password.

Option 2:

Require that a pass phrase be entered by a person at application start up and derive an encryption key from that pass phrase. Once you have the key, discard the pass phrase and retain the key in memory only.

Pros:

The key is never on disk.

Even if the server is rooted, getting to the key is not a simple task.

Cons:

Automated reboots are not possible.

You'll likely have to share the pass phrase with anyone handling support.

You need to keep in mind that data stored in memory may transparently be written to disk in certain situations.

Or you could do a compromise between these two systems where, a pass phrase is initially used to derive the encryption key which is held in memory, and the key is temporarily written to disk or encrypted container whenever the application is gracefully restarted. When the restart is complete the application loads the key and then deletes it from temporary storage (and if necessary, be sure to overwrite the disk location where the key was stored so that it can't be recovered).


http://www.niftyadmin.cn/n/2210913.html

相关文章

qmake工具生成项目文件与Makefile文件

qmake 是一个协助简化跨平台进行专案开发的构建过程的工具程式,也是Qt附带工具之一。可以根据项目环境构建.pro项目文件,再根据项目文件生成Makefile文件。相对于手写一个项目Makefile来说,使用qmake生成Makefile比较简便。 查看qmake Ubu…

谈谈对Canal(增量数据订阅与消费)的理解

概述 canal是阿里巴巴旗下的一款开源项目,纯Java开发。基于数据库增量日志解析,提供增量数据订阅&消费,目前主要支持了mysql(也支持mariaDB)。 起源:早期,阿里巴巴B2B公司因为存在杭州和美国…

【noi 2.6_666】放苹果 【noi 2.6_8467】鸣人的影分身(DP)

这题其实在2.6前面的专题也有出现过,我还以为我有写,结果发现,并没有。于是就现在写了。这2题其实重复了......我就按放苹果的来说。 题意:把N个苹果放在M个盘子里,允许有的盘子空着不放,问共有多少种不同的…

php 随机在文章中添加锚文本_原创文章SEO技巧——嘉定行吟科技

一、网站内容关键词的选定是根据自动分词许多SEO优化人员,对于网站页面内容的选择大多都是在关键词标签中出现的,但实际上这是一种错误的方法,其中一些只是优化人员的主观看法,没有从搜索引擎的规则上考虑,如果优化人员…

mysql中的(null)_mysql中的NULL

[mysql - rootlocalhosttestmysql.sock 23:44:48] >select * from a;------------ --------------a表中包含a,c,无NULL| a | c |------------| 2 | 1 || 3 | 1 || 1 | 2 |------------3 rows in set (0.00 sec)[mysql - rootlocalhosttestmysql.sock …

SMTP基本电子邮件发送协议原理

1.电子邮件发送客户端发送给服务器端,postfix软件提供MTA,MDA.MTA 提供SMTP服务,接受邮件(读取DNS的MX记录)--》保存MDA 传送邮件MUA 用户代理 1-1服务器使用SMTP协议将电子邮件提交至TCP端口25,或由本地客户端通过 /usr/bin/sendmail程序进行提交。如…

Qt执行出现:can‘t resolve symbol ‘_ZN15lanStatusWidgetC1EP7QWidget‘

can’t resolve symbol这种问题是:编译过了,但是dvr424识别不了.so里面的_ZN15lanStatusWidgetC1EP7QWidget这个东西,说明你dvr424和.so不是同一个版本。 解决:重新编译整个工程。

android 访问服务器sql_1.sql注入基础

1.1 前言从本节开始,讲开始第二章web漏洞原理篇的讲解。首先带给大家的是sql注入漏洞。sql注入漏洞是web层面最高危的漏洞之一。2008年至2018年期间,sql注入漏洞连续三年位于owasp漏洞排行榜中的第一名。1.2 免责声明该课程中涉及的技术只适合于CTF比赛…