0
$\begingroup$

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!

$\endgroup$
11
  • $\begingroup$ If you don't know the length a-priori (as you do eg for MACs), you always pad. $\endgroup$ – SEJPM Feb 9 at 21:37
  • $\begingroup$ So in the example I gave, if you always padded, how much would you pad? $\endgroup$ – Guest Feb 9 at 21:39
  • $\begingroup$ 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. $\endgroup$ – kelalaka Feb 9 at 21:41
  • $\begingroup$ are you asking how to unpaid or how the PKCS#7 padding is working? $\endgroup$ – kelalaka Feb 9 at 21:42
  • $\begingroup$ how to unpad, and how to determine if no padding was used $\endgroup$ – Guest Feb 9 at 21:43

Browse other questions tagged or ask your own question.