I need to strip off padding after decrypting AES(CBC)-encrypted data (I have control over encryption and data transmission), so have looked at adding the length of the original data to the payload being transmitted.
Option 1: [ IV | Length | Encrypt(original data) ]
Option 2: [ IV | Encrypt([ Length | original data ]) ]
Where: "Length" is the 4-byte length of the original data
Would either of these approaches compromise the security of the message?
My concern with Option 1 is that you're giving away information for free: is there a way in which a potential attacker might be able to utilize the length of the data in attempting to compromise the message?
My concern with Option 2 is that a potential attacker (after determining by decompiling source code that the first 4 bytes indicate length) might try a brute-force approach, only needing to go through a much smaller part of the data for each potential key to determine if the message for that particular key is valid; i.e. that he only has to try one block or only the first 4 bytes of the message until he ends up with a block for which the first 4 bytes are relatively close to the size of the payload (hence effectively reducing the amount of time it would take to determine the message's key)
Are any of the aforementioned concerns valid?
What are the best-practices to store the message length / strip away padding?