I would like to know the size of the data after AES encryption so that I can avoid buffering my post AES data. Or memory) to learn the size mainly
I use 128 bit AES and javax.crypto.Cipher and javax.crypto.CipherInputStream for encryption.
Some tests conducted with different input sizes show that, following the calculation given below, the encryption size is correct:
longer size = input_Size_In_Bytes; Long post_asisICis = size + (16 - (size% 16)); But I'm not sure that the above formulas will apply to all possible input sizes.
After implementing AES encryption, there is no way to calculate the size of the data - encrypted data (on disk or memory) without having to know about its post-encryption size without advance?
AES has a fixed block size, regardless of the key size of the 16-bytes. Suppose you use PKCS 5/7 padding, use this formula,
cipherLen = (clear LAN / 16 + 1) * 16; Please note that if there is a majority of the size of the clear-text block, then a new block is required for padding. Say you have clear-cut 16 bytes. The ciphertext will take 32 bytes.
You may want to store IV (initial vector) with cipher-text. In that case, you have to add 16 more bytes to IV.
Comments
Post a Comment