When using AES encryption, the plaintext must be supplemented by the size of the encryption block. Most libraries and standards use a pad where padding bytes can be determined from the unallocated length of the plaintext. Can random padding bytes be used if possible?
I implement a confidential data storage scheme for each user and each session. Data will typically be JSON-encoded key-value pairs and can be potentially short and duplicate. I am looking at PKCS # 5 for guidance, but I planned to use AES for the encryption algorithm, not DES3. I planned a random IV for each data item and a key defined by a user ID and a password or session ID, depending on the situation.
One thing that surprised me was the PKCS # 5 supplement scheme for clear text. To put the encrypted text in 8-byte blocks, 1 to 8 bytes are added at the end, and the contents of the byte complement fill the number of fill bytes (i.e. 01 , 0202 , 030303 , to 0808080808080808 ). My own padding scheme was to use random bytes at the beginning of plaintext, and the last character of the plaintext would be the number of bytes added.
My reasoning was that in AES-CBC mode, each block is a function of the ciphertext of the previous block. Thus, each plaintext will have an element of randomness, giving me another level of protection against known plaintext attacks, as well as IV and key issues. Since my plaintext is expected to be short, I do not mind keeping the entire decrypted string in memory, but cutting off the indentation in the front and back.
One of the drawbacks will be the same loose text, IV and key, which will lead to different ciphertext, which makes unit testing more difficult (and not impossible) - I can use the pseudo-random add-on generator for testing and cryptographically strong for production).
Another would be that to force random filling, I would need to add at least two bytes - an account and one random byte. For deterministic filling, the minimum size is one byte, either saved with clear text or in a shell of ciphertext.
Since a well-known standard, such as PKCS # 5, decided to use deterministic padding, I wonder if there is anything else that I missed, or I rate the benefits too high.