I\'m working on a security application using my own customized cryptography method, and having a problem on message decryption.
According to the theory, the input has to
You can use a block cipher such as AES in streaming mode to get rid of the padding altogether. So you could use e.g. Cipher.getInstance("AES/CTR/NoPadding")
or if you also want to include an authentication tag Cipher.getInstance("AES/GCM/NoPadding")
. The latter will add some bytes to the end of your ciphertext which you can use to make sure that the ciphertext was created using the correct key, and that the ciphertext was not altered.
Beware that you may leak information about the size of the plain-text. This is also true for CBC-mode but in that case you will at least have a 16 byte (block size) margin. With streaming mode encryption you will encrypt to precisely the same number of bytes. Also be aware that you need to use a fresh IV value for each encryption with the same key, otherwise you may directly expose the plaintext to an attacker.