Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Check If File is Encrypted using AES (Rijndael)

Tags:

c#

encryption

aes

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.

like image 492
Mako Avatar asked Mar 05 '10 19:03

Mako


People also ask

How do I know if I have AES encryption?

In the absence of any standard header, you could look at the byte frequency. AES encrypted data (or indeed anything encrypted with a decent algorithm) will appear to be a random sequence of bytes. This means that the distribution of byte values 0-255 will be approximately flat (i.e. all byte values are equally likely).

How do you tell if a file is encrypted?

To Find All Encrypted Files in Windows 10, Open a new command prompt. Type the following command: cipher /u /n /h . The command will list your encrypted files.

Is Rijndael the same as AES?

Rijndael and AES differ only in the range of supported values for the block length and cipher key length. For Rijndael, the block length and the key length can be independently specified to any multiple of 32 bits, with a minimum of 128 bits, and a maximum of 256 bits.

Is Rijndael encryption secure?

At Rijndael, encryption is done with a 128, 192, or 256-bit key, which provides guaranteed increased security against brute-force attacks. In addition, this encryption method works three times faster than DES in software.


2 Answers

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.

like image 101
Jeffrey L Whitledge Avatar answered Sep 28 '22 10:09

Jeffrey L Whitledge


Suppose I have a file F containing ciphertext X, which is the enciphering of plaintext Y with key Z.

I wish to ensure that the plaintext Y can only be determined by someone who possesses both key Z and key Q. (I can think of a number of reasons why I might wish to do this.)

I therefore wish to encrypt the already-encrypted file with key Q.

You're telling me that your system wishes to detect that F is already encrypted, and then refuse to encrypt it with key Q?

That seems like a bad idea. I might want to encrypt the file with key Q irrespective of whether it is already encrypted with key Z or not.

like image 22
Eric Lippert Avatar answered Sep 28 '22 08:09

Eric Lippert