Reputation: 881
I am trying to read from a file and encrypt the data using AES in CFB mode with no padding
'AES/CFB/NoPadding'. The IV is 16bytes long.
Given that AES by default, works with 16 byte blocks, I would have thought of using a padding scheme if I were using CBC or any other mode but CFB. CFB essentially requires no padding for plaintext.
So the problem is that if my file contains data which is less than 16 bytes, then nothing gets encrypted. If it is greater than 16 bytes, then only the first 16 bytes get encrypted.
This clearly indicates that the block size is kicking in and if there is an underflow or overflow of bytes w.r.t. the block size, then that data/bytes are discarded.
What I don't understand is while using CFB, I need not pad the data.. right! Then why is the 16byte default block size of AES coming into action and truncating data?
Upvotes: 6
Views: 1612
Reputation: 41967
You have failed to specify the number of bits you want to feedback for that mode, and thus you are getting the default 128 bits. It sounds like you want 8 bits, for which you should use the following argument to getInstance():
Cipher.getInstance("AES/CFB8/NoPadding");
Upvotes: 4