# How can you tell if padding was used? [duplicate]

Let's say you have an encryption algorithm that uses PKCS5 padding. You input 'secret message', which is 14 characters long, but for some reason or another the algorithm needs it to be 16 characters long. So you add on two bytes that are equal to 2 at the end.

Then when you decrypt it, you just look at the last byte and take that many off for the end result. But how would you be able to tell if there was no padding in the first place? I'm just a noob so be nice please. Thanks in advance!

• If you don't know the length a-priori (as you do eg for MACs), you always pad. – SEJPM Feb 9 at 21:37
• So in the example I gave, if you always padded, how much would you pad? – Guest Feb 9 at 21:39
• It is part of your protocol that mentions the used padding otherwise by looking at only one output you may not decide. For example, - You get a message, decrypt it, and check, can you guarantee that if the message ends with byte 01 is the padding of PKCS#7 (PKCS#7 > PKCS#5) or not? - Keep it aside, you get another message, decrypt it, and check, it fits more into PKCS#7, then your belief increased. – kelalaka Feb 9 at 21:41
• are you asking how to unpaid or how the PKCS#7 padding is working? – kelalaka Feb 9 at 21:42
• how to unpad, and how to determine if no padding was used – Guest Feb 9 at 21:43