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.
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).
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With