# Is it possible to unpad a file that is not padded

I used "AES/CBC/PKCS5Padding" to encrypt some files. But I did not provide any identifier to detect if the file is encrypted or not. Now one way to detect if a file is encrypted or not, that I can think of, is to try to decrypt it and see if there is a padding miss match.

Now my question is,
Is it possible for some random file to match the padding scheme?

• Be very careful with decrypting and looking for a padding mismatch. This can lead to padding oracle attacks. – mikeazo Aug 24 '18 at 13:32
• @mikeazo: want to turn that into an answer? I can't think of anything to add... – poncho Aug 24 '18 at 14:28
• If you had used an authenticated-encryption scheme, then checking if the file can be correctly decrypted would be a reliable (if rather inefficient) way to distinguish encrypted and unencrypted files. – Ilmari Karonen Aug 25 '18 at 12:09

For a file of random byte length, there is probability 1/16 (6.25%) that its length is that of a valid encrypted file, and then there is probability just below 1/255 (≈0.392%) that after decryption, the last block ends with 01, or 0202, or 030303, or 04040404...