Archived Forum Post

Index of archived forum posts

Question:

Decrypt always returns success even if the file is not encrypted?

Aug 29 '12 at 16:12

The CkDecryptFile() member function of CkCrypt2 C++ class always return true even if the file is not encrypted.

CkDecryptFile always returns true even though "Sunset.jpg" is unencrypted file.

In my code, i would like to know if the file is unencrypted. One way of determining the file is unencrypted is CkDecryptFile() fails, but since CkDecryptFile() returns true i cannot determine whether file is unencrypted.


Answer

Symmetric encryption algorithms, such as AES, Blowfish, 3DES, RC2, etc. are simply mathematical computations that transform input bytes to output bytes having the characteristics of random byte data (where each byte value 00 through FF is equally possible, and the bytes are seemingly random). There is no file format. In other words, encrypting a file w/ any of these symmetric algorithms does not result in output that is structured in any way (i.e. no headers, no identifying structure, etc.) Decryption is simply the reverse mathematical computation.

A method such as CkDecryptFile has a success/failure return because other things may happen that cause a failure. For example, maybe the input file could not be found or opened, or maybe the output file could not be created...