如何存储用于加密文件的密钥 [英] How to store the key used to encrypt files

查看:229
本文介绍了如何存储用于加密文件的密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在玩一个应用程序来备份文件到云:),我想在存储文件之前加密文件。这部分我已经覆盖了,但是由于这个应用程序将监视文件夹的更改和上传更改的文件,我需要存储我用来加密文件的密钥。这个想法是用户提供密码,并生成密钥。



目前我正在使用.NET Framework进行加密。我正在使用RijndaelManaged类加密/解密和PasswordDeriveBytes类来获取密钥。



但是如何保留用于加密文件的密钥?我也希望程序开始使用Windows,而不需要让用户再次输入密码。

解决方案

我建议避免使用非对称加密来加密文件。非对称加密比同等强度的对称加密算法显着更昂贵(计算)。对于加密大文件,我建议在任何一天推荐AES超过RSA。



关于你的问题 - 数据保护API(DPAPI)Gaurav提到是Windows上最好的选择。 如何:使用数据保护



DPAPI提供 ProtectedMemory ProtectedData 。前者允许您保护内存中的秘密,后者可以保护持久存储在磁盘上的秘密。 API负责加密和解密为您,(根据指定的范围)将保护您的数据免受其他用户或其他机器的访问/解密。



要在您的场景中使用DPAPI,我建议使用用户密码,生成对称加密密钥(例如 PasswordDeriveBytes ),存储使用DPAPI并限制对当前用户的访问。



您的应用程序可以使用该密钥加密所有上传。您的应用程序可以在不重新提示用户的情况下获取密钥,并且用户可以在新系统上重新生成密钥。



一个缺点是恶意应用程序也可以由同一用户执行可能获得秘密密钥。为了防止这种情况,必须在保护& 取消保护。然而,实现这个可能会偏离你的目标 - 因为现在你需要提示用户看起来像一个密码很糟糕的东西。



另外:有趣的阅读:



您还可以从Backblaze找到这篇有趣的阅读文章。虽然他们不解释他们如何支持您的方案(加密上传,云提供商无法解密 - 只有他们提供这样的服务):
http://blog.backblaze.com/2008/11/12/how-to-make-strong -encryption-easy-to-use /



免责声明:我是一个满意的Backblaze客户,但与其服务无关。 p>

PS:请花时间标记可接受的答案。社区会奖励你。


I'm playing around with an app to backup files to "the cloud" :) and I want to encrypt the files before I store them. That part I have covered, but as this app will be monitoring folders for change and uploading the changed files I need to store the key that I use to encrypt the files with. The idea is that the user provides a password and a key is generated.

At the moment I'm using the .NET Framework to do the encryption. I'm using the RijndaelManaged class to encrypt/decrypt and the PasswordDeriveBytes class to get the key.

But how should I keep the key that is used for encrypting the files? I also want the program start to with Windows and not need to have the user enter their password again.

解决方案

I'd recommend avoiding using asymmetric encryption for encryption of your files. Asymmetric encryption is significantly more expensive (computationally) than symmetric encryption algorithms of equal strength. For encrypting large files I'd recommend AES over RSA any day.

As to your question - the Data Protection API (DPAPI) Gaurav mentions is your best bet on Windows. How to: Use Data Protection

DPAPI offers ProtectedMemory and ProtectedData. The former allowing you to protect secrets in memory, the latter affords protection for secrets persisted to disk. The API takes care of encryption & decryption for you, and (depending on the specified scope) will protect your data from access/decryption by other users or on other machines.

To use DPAPI in your scenario, I'd recommend taking the users password, generating a symmetric encryption key (e.g. PasswordDeriveBytes), storing that using DPAPI and restricting access to the current user.

Your application can use that key to encrypt all uploads. Your application can obtain the key without re-prompting the user, and the key could be regenerated by the user on a new system.

One downside would be that a malicious application also executed by the same user could potentially obtain the secret key. To protect against this scenario additional entropy (effectively a salt) must be provided in Protect & Unprotect. However implementing this will likely stray from your objective - because now you'll need to prompt the user for something that seems an awful lot like a password.

Also: interesting reading:

You may also find this post from Backblaze an interesting read. Although they do not explain how they support your scenario (encrypted uploads that the cloud provider cannot decipher - only that they offer such a service): http://blog.backblaze.com/2008/11/12/how-to-make-strong-encryption-easy-to-use/

Disclaimer: I am a satisfied Backblaze customer, but am in no other way affiliated with their service.

PS: Do take the time to mark acceptable answers. The community will reward you.

这篇关于如何存储用于加密文件的密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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