I am encrypting and storing sensitive values in the database. I have a set max length in the database, but in order to provide useful user feedback, I'd like to know the max input I should allow for a given database length.
I can throw together a test that brute forces an answer, but I'd like to understand more generally how to go about calculating.
In my specific case, I'm using Twofish in CBC mode with PKCS7 padding. The result is stored as base64 encoded string. The database column is a VARCHAR(512) column.
I know base64 has an overhead of about 137% of input so, roughly, 512/1.37 = ~373
.
But now where? is 373, which happens to be 23 blocks, the maximum size, or is there more to it?
Thank you very much for your patience. :)