Possible Duplicate:
Removing Padded Value in Decrypted Message

I tried to encrypt and decrypt a file in ECB mode using AES Algorithm but I encountered one problem during decryption, I don't know how to remove the padded value.. because every byte in a file is unpredicted.. I am only using 0x00 in padding.

how to remove the padded value in a encrypted file during decryption? how can I also determined that is a padded value and not a original byte of a file.

  • $\begingroup$ Sorry, it is not really clear how this differs from your previous question. If you think your previous question needs clarification, feel free to edit it. $\endgroup$ Commented Jun 5, 2012 at 20:06

1 Answer 1


To repeat the answer I gave you, with zero padding; "if you can assume that the message will never end in a zero byte, then it is easy to remove. If you can't make that assumption, it sounds like you may need to switch to another padding method".

So, to answer your question "how can I determine that it is a padded value and not an original byte of the file", the answer is "you can't -- switch to a padding method where you can".

  • $\begingroup$ is it okay to create my own padding method? $\endgroup$
    – goldroger
    Commented Jun 6, 2012 at 3:53
  • $\begingroup$ @JohnPaulParreño Why create your own? There are more than enough padding methods already. $\endgroup$ Commented Jun 6, 2012 at 13:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.