简体   繁体   English

在哪里存储AesCryptoServiceProvider的Key和IV?

[英]where to store Key and IV for AesCryptoServiceProvider?

We have a C# (.net 3.5) application. 我们有一个C#(。net 3.5)应用程序。 During the installation, we use AesCryptoServiceProvider to encrypted some useful info in the config file. 在安装过程中,我们使用AesCryptoServiceProvider加密配置文件中的一些有用信息。 Those info will be decrypted by the application when it is running. 这些信息将在应用程序运行时由应用程序解密。 So the application needs to know the Key and IV 因此应用程序需要知道KeyIV

We are thinking to store the Key and IV byte[] in a secure place on the machine. 我们正在考虑将KeyIV byte []存储在机器上的安全位置。 I know there is a machine store which can store RSA key pair. 我知道有一个machine store可以存储RSA密钥对。 Can I store the Key and IV byte[] in there? 我可以在那里存储KeyIV字节[]吗? I searched online and read the MSDN doc but cannot find a way to do it. 我在网上搜索并阅读了MSDN文档,但找不到办法。

Do you know how to do it? 你知道怎么做吗? Do you have any other good idea? 你有什么好主意吗?

What you are attempting is a crypto violation. 你正在尝试的是加密违规。 Cryptographic keys are commonly stored in plain text in a config file. 加密密钥通常以纯文本形式存储在配置文件中。 The IV is commonly stored with the cipher text in your data store. IV通常与数据存储中的密文一起存储。 As long as you don't violate CWE-329 you should be golden with this design. 只要您不违反CWE-329,您就应该采用这种设计。

Where all of this breaks down for you is that you are trying to hide cipher text on the same machine as the key. 所有这些都打破了你的意思是你试图隐藏与密钥相同的机器上的密文。 Where is the attacker? 攻击者在哪里? If he is already on your machine then he can just fire up a debugger and read the key or plain text in memory. 如果他已经在你的机器上,那么他可以启动调试器并读取内存中的密钥或纯文本。 Cryptography cannot address this problem, what you are looking for is Security Though Obscurity (Which isn't a secure solution.). 密码学无法解决这个问题,您正在寻找的是Security It Obscurity (这不是一个安全的解决方案)。

I'll respond first to the question, "Do you have any other good idea?" 我会首先回答这个问题:“你还有其他好主意吗?”

The .Net framework has built-in support for encrypting configuration sections. .Net框架内置了对加密配置节的支持。 You can apply this encryption to most configuration sections with a few exceptions (eg machine.config). 您可以将此加密应用于大多数配置节,但有一些例外(例如machine.config)。 Unless you have a good reason to roll your own configuration encryption, it might be a better idea to use what's already provided to you in the framework. 除非您有充分的理由推出自己的配置加密,否则最好使用框架中已经提供给您的内容。

If you go that route, here's a good starting point. 如果你走这条路,这是一个很好的起点。 http://msdn.microsoft.com/en-us/library/53tyfkaw(v=vs.100).aspx http://msdn.microsoft.com/en-us/library/53tyfkaw(v=vs.100).aspx

If you go with RSA you're still going to need to get your public and private key onto the machine during installation. 如果您使用RSA,您仍需要在安装过程中将公钥和私钥放入计算机。 Based on your question, presumably you have a way to get the key to the machine -- you just need to know where to store it. 基于你的问题,大概你有办法获得机器的钥匙 - 你只需要知道在哪里存放它。 In that case Microsoft provides a place to store your RSA keys. 在这种情况下,Microsoft提供了存储RSA密钥的位置。 You can follow this article on how to import and export keys: http://msdn.microsoft.com/en-us/library/yxw286t2(v=vs.100).aspx 您可以按照本文介绍如何导入和导出密钥: http//msdn.microsoft.com/en-us/library/yxw286t2(v = vs.100).aspx

On the machines that run the application, mark the private key as non-exportable when installing the key pair for some added security. 在运行应用程序的计算机上,在安装密钥对时将私钥标记为不可导出,以增加安全性。 If the application runs under a specific user account, install the key pair in the user store. 如果应用程序在特定用户帐户下运行,请在用户存储中安装密钥对。

The user (or app pool in the case of most web apps) will need permission to read the private key. 用户(或大多数Web应用程序中的应用程序池)将需要读取私钥的权限。 You can use aspnet_regiis.exe for the permission grant. 您可以使用aspnet_regiis.exe获取权限授予。

Most of the examples on the web will refer to aspnet_regiis.exe for creating, exporting, importing, and granting permission to RSA key pairs. Web上的大多数示例都将引用aspnet_regiis.exe来创建,导出,导入和授予RSA密钥对的权限。 You don't have to use that program, but if you do, there are a couple gotchas: 您不必使用该程序,但如果您这样做,则有几个问题:

  1. It only runs on files named web.config. 它仅在名为web.config的文件上运行。 So if you have a console app, you have to rename your config file to web.config to use it with aspnet_regiis.exe. 因此,如果您有控制台应用程序,则必须将配置文件重命名为web.config以将其与aspnet_regiis.exe一起使用。

  2. If you use aspnet_regiis.exe to create your key pair, it will ignore the key length paramater. 如果使用aspnet_regiis.exe创建密钥对,它将忽略密钥长度参数。 As of this response, the current recommended key length is 3072. To create a key pair with a 3072 bit private key, don't use aspnet_regiis.exe. 在此响应中,当前建议的密钥长度为3072.要使用3072位私钥创建密钥对,请不要使用aspnet_regiis.exe。 Refer to How to set key size of RSA key created using aspnet_regiis? 请参阅如何设置使用aspnet_regiis创建的RSA密钥的密钥大小? for an example of how to create a larger key length. 有关如何创建更大密钥长度的示例。

After all that, if you still need to store the aes key somewhere, you might consider putting it in a file and protecting it with EFS using cipher.exe. 毕竟,如果您仍然需要在某处存储aes密钥,您可以考虑将其放在一个文件中并使用cipher.exe使用EFS保护它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM