I'm conducting an experiment dealing with differences in padding across different aes operations for my Intro to Crypto class, and the question says OpenSSL uses PKCS5 padding, and that I need to prove this. All we've been taught up to this point was how to encrypt something by doing this:

openssl enc -aes-128-cbc -e -in example.txt -out example.bin -K 1001001 -iv 0100110

Now my question, really, is: Where do you implement the padding into this shell command, or is the padding automatically added, and if it is auto added, why can I not see in it my hex editor?

  • $\begingroup$ I'm no openssl expert here, but the documentation states: "All the block ciphers normally use PKCS#5 padding also known as standard block padding". I tried your code from the command line and padding was indeed used. Keep in mind that padding might just be a single byte, depending on the length of the input. $\endgroup$
    – hunter
    Oct 22, 2013 at 16:56
  • $\begingroup$ Tha padding is added to the plaintext to get encrypted. If you view the output in cipher text, the padding will not be recognizable. You may still notice existence of the padding from extension of the output. Try to decrypt the ciphertext with -nopad option to find out any possible padding following the cipher text. $\endgroup$
    – user4982
    Oct 22, 2013 at 16:58
  • $\begingroup$ @user4982 - PCKS5 padding is recognizable in the ciphertext by comparing its length with that of the cleartext. $\endgroup$
    – hunter
    Oct 22, 2013 at 17:01
  • $\begingroup$ @hunter Like I said, "You may still notice existence of the padding from extension of the output.". It often not possible to distinguish PKCS#5 padding from other possible paddings like "bit padding", ANSI X.923 etc. merely from the size expansion. This is why I suggested decryption. $\endgroup$
    – user4982
    Oct 22, 2013 at 19:49

1 Answer 1


You can decrypt with the -nopad option and check the HEX output.

Example piped command :

$ echo "hi" 
| openssl enc -aes-128-cbc -e -K 1001001 -iv 0100110 
| openssl enc -aes-128-cbc -d -nopad -K 1001001 -iv 0100110 
| hd

And output :

00000000  68 69 0a 0d 0d 0d 0d 0d  0d 0d 0d 0d 0d 0d 0d 0d  |hi..............|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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