我的 C# RSA/AES/salt/IV 最佳实践方法是否遗漏了什么?
虽然我不是密码学家,但我确实认为自己基本上了解有关对称加密、哈希和加密随机数生成的最佳实践。我搜索并发现了许多帖子,无论是在 SO 还是其他地方,都与加密数据、盐和 IV 的持久性有关。我所要求的是检查我正在做的事情,以确保我正在组装的各个部分正确地组装在一起,即安全地组装在一起。这是我的计划:
在 C# 中,我使用 RSACryptoServiceProvider 生成一个漂亮的、大的 4096 位密钥对。为了保留到磁盘/数据库,我使用包含私钥信息的 ToXmlString(true) 方法。然后,我使用 AES 加密整个 Xml 文档,如下所述: http://msdn.microsoft.com/en-us/library/sb7w85t6(v=VS.90).aspx,使用派生的密钥Rfc2898DeriveBytes 使用 10,000 轮和 RNGCryptoServiceProvider 生成的 64 位盐。但现在的问题是,储存盐以及静脉注射。我知道盐可以公开,而且我相当确定 IV 也可以。因此,最简单的方法似乎是将它们与加密的 Xml 一起放入纯文本 Xml 文档中并使用它来完成。
我有什么遗漏的吗?
Edit0:是的,IV 不需要保密:http://www.w3。 org/TR/xmlenc-core/#sec-Nonce。
Edit1:盐现在是从密码生成的(填充到至少 64 位后仍使用 10k 轮),因此它不会单独保存。 IV 自动作为 CipherValue 的前缀。
While I'm no cryptographer, I do consider myself mostly up to date on the best practices regarding [a]symmetric encryption, hashes, and crypto random number generation. I've searched, and found, many posts, both here on SO, and elsewhere, relating to the persistance of encrypted data, salt, and IV. What I'm asking for, is a look over of what I'm doing, to make sure that the pieces I'm putting together, are put together correctly, i.e. securely. Here's my plan:
In C#, I'm using RSACryptoServiceProvider to generate a nice, large, keypair of 4096 bits. To persist to disk/database, I'm using the ToXmlString(true) method which includes the private key info. I then encrypt the entire Xml document with AES as described here: http://msdn.microsoft.com/en-us/library/sb7w85t6(v=VS.90).aspx, using a key derived from Rfc2898DeriveBytes using 10,000 rounds and 64 bits of salt generated from RNGCryptoServiceProvider. But now the issues is, storing the salt, as well as the IV. I know the salt can be public, and I'm fairly sure that the IV can be too. So, the most simple way to do things seems to be to shove them into a plain text Xml document, along with the encrypted Xml and be done with it.
Anything at all I'm missing?
Edit0: Yes the IV need not be secret: http://www.w3.org/TR/xmlenc-core/#sec-Nonce.
Edit1: The salt is now produced from the password (still using 10k rounds after padding to a minimum of 64 bits), so it is not persisted separately. The IV is prefixed to the CipherValue automatically.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IV 和盐应该是安全的随机数并且可以公开存储。迭代计数也可以公开存储,尽管它通常是硬编码的。请注意保持迭代计数的上限,否则可能容易受到拒绝服务攻击。
所以基本上你做得还不错。如果加密 XML,我将遵守 XML 加密规范,并使用(建议的)GCM 模式加密(如果可用)。不过,请确保在解密时检查所有参数。
The IV and salt should be secure random numbers and may be stored publicly. The iteration count may be stored publicly as well, although it is normally hard coded. Be careful that you keep an upper bound on the iteration count or you may be susceptible to denial of service attacks.
So basically you are doing OK. If encrypting XML I would keep to the XML-encryption specifications, using (the proposed) GCM mode encryption if it is available. Make sure you check all the parameters when decrypting though.