Encryption will fail with a database insert error when applied to text_textfield (varchar) fields with a pre-set maxlength shorter than what is needed to store the serialized array.

Example: Text field set to a length of 9. The field value, when serialized, resulted in a string 143 characters-too long to fit into the varchar(9) field.

This should be addressed, if possible,
In my case, I was able to work around it by setting the field length to 255 and adding additional validation to the field to ensure what the user entered did not exceed my desired length. That probably won't work with longer fields.

Possible solutions could include storing the data in a separate field and storing the key to it in the field value or altering the field value datatype to be a LONGTEXT field.

Putting it up for discussion.

Comments

justAChris’s picture

This error is easy to replicate, you don't even need to shorten the field length. If you leave the default 255 characters and enter close to that many, you'll get the same error.

I wouldn't recommend altering the data type on an existent field, especially one provided by core. I think that creating a separate table for encrypted storage is a good idea. A similar technique is provided by the field encrypt module, using mediumtext as the data type. That module doesn't implement a revisions table for the table it creates, which is something to consider.

It'll be a significant patch to get the above running, I can help out if we think this a good direction to go in.