使用 AES 加密/解密
我正在编写小程序来使用 AES 加密/解密文件。我正在使用 Cryptopp 库。
我需要帮助来理解一些事情。
当我加密文件时,我应该在文件开头写入 IV 以便稍后解密吗?
我不想检查解密文件所给出的密码是否正确。我应该:
在加密之前在文件开头放置一些字符串(例如 TRUE)。解密后检查它。
加密前检查文件的MD5。将其放在加密文件的开头。解密前读取MD5,解密文件,检查解密文件的MD5并进行比较。
I'm writing small program to encrypt/decrypt files using AES. I'm using Cryptopp library.
I need help to understand some things.
When I'm encrypting file I should write IV at the beginning of file to decrypt it later?
I wan't to check password given do decrypt file was correct. Should I:
put some string at beginning of file (ex. TRUE) before it's encrypted. After decryption check it.
Check MD5 of file before encryption. Put it at beginning of encrypted file. Read MD5 before decryption, decrypt file, check MD5 of decrypted file and compare them.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 IV 写在文件开头就可以了。附加到末尾是另一种选择。
不要将静态字符串放入明文中:ENIGMA 转录本更容易被破解类似的原因,zip 格式会导致暴力破解密码。
md5 方法听起来还可以;但 hmac-sha256 将提供更强的完整性声明。 (我认为您甚至可以重复使用 hmac-sha256 的 AES 密钥或 IV,但我不确定它的安全性。)
Writing the IV at the beginning of the file is fine. Appending to the end is another option.
Do not put a static string into the plaintext: ENIGMA transcripts were more easily broken for very similar reasons, and the zip format makes brute-forcing passwords very easy for this identical mistake.
The md5 approach sounds tolerable; but hmac-sha256 would provide significantly stronger integrity claims. (I think you could even re-use the AES key or the IV for hmac-sha256, but I'm not positive of its safety.)