如何检查文件是否使用AES加密(Rijndael) [英] How to Check If File is Encrypted using AES (Rijndael)

查看:1126
本文介绍了如何检查文件是否使用AES加密(Rijndael)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#中使用'RijndaelManaged'和'CryptoStream'类来加密文件。在加密文件之前,我想检查文件是否已加密。



我尝试使用 File.GetAttributes()方法来检查加密,但它不起作用。 >

我需要一些技巧,我可以检查文件是否已经加密。

解决方案

没有任何类型的自定义标题,绝对确保文件被加密的唯一方法是尝试解密它。



如果您尝试压缩该文件和它变小,那么这是非常不可能被加密。如果字节值不均匀分布(包括纯文本!),则不太可能被加密。



这些启发式依赖于正确执行加密。如果AES在一个时间段被应用于一个文件,那么文件可以在结果中出现,但是由于你使用CryptoStream这不应该是一个问题。



如果您自己的代码将始终用于加密和解密文件,那么您应该考虑添加一个自定义标题,表示它是一个加密文件。


I am using 'RijndaelManaged' and 'CryptoStream' classes in C# to encrypt files. Before encrypting the files, i want to check whether the file is already encrypted or not.

I tried using File.GetAttributes() method to check for Encryption but it is not working.

I need some tips on ways i can check whether the file is already Encrypted or not.

解决方案

Without any sort of custom headers, the only way to be absolutely sure the file is encrypted is to attempt to decrypt it.

If you attempt to compress the file and it gets smaller, then it is extremely unlikely to be encrypted. If there is a non-uniform distribution of byte values (including plain text!), then it is unlikely to be encrypted.

Those heuristics depend on proper execution of the encryption. If AES is applied to a file one block at time, then patters can emerge in the result, but since you are using CryptoStream this shouldn't be a problem.

If your own code will always be used to encrypt and decrypt the files, then you should consider adding a custom header that indicates it is an encrypted file.

这篇关于如何检查文件是否使用AES加密(Rijndael)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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