I'm trying to figure out how padding works by seeing what happens when I try to encrypt a 16 byte file with AES-128-CBC. My understanding was if I encrypt a file of size, say, 28, then there would automatically be 4 bytes of padding to make it 32. But when I encrypted my 16-byte file, the size ended up being 48 bytes. I did research and learned that a single padding block is automatically added to direct multiples in order to distinguish the padding from the plaintext, but if that's so, then why is it 48 bytes and not 32 as well (16 plaintext + 16 padding)?
Asked
Active
Viewed 1,955 times
openssl enccommand, or an alias (in this caseopenssl aes-128-cbc)? That doesn't do plain encryption per the specs of AES and CBC; it does password-pased encryption using salt, which is added to the file and changes its size; see https://crypto.stackexchange.com/questions/3298/is-there-a-standard-for-openssl-interoperable-aes-encryption (caveat: my answer) @kelalaka: and for len multiple of blocksize n that formula gives n (one block) as Q says – dave_thompson_085 Feb 12 '20 at 07:39Salted__in ASCII? In that case you are not using AES-CBC directly, you are using a AES-CBC after deriving a key from a password. – Maarten Bodewes Mar 09 '20 at 18:21