Page 1 of 1

Field encryption with existing data (v2023)

Posted: Mon Apr 10, 2023 8:38 pm
by philmills

I have an existing project with is in production environment
I'd like to start using field encryption for some table fields, but am looking for some clarification on how to convert existing unencrypted data to encrypted.

I have a MEDIUMTEXT field with existing data (including html) which needs to be encrypted, and some VARCHAR fields in a users table containing existing data which should also be encrypted.
If I was starting from a fresh table it would be ok, but the problem is with converting existing unencrypted data to encrypted

Thanks


Re: Field encryption with existing data (v2023)

Posted: Mon Feb 19, 2024 7:57 am
by philmills

So I got this far:

  • I discovered that encrypted fields containing existing data still display that data correctly which is great
  • on save the data then gets encrypted, this is good to know

I don't want users to have to re-save every record
How can i encrypt them all at once?
I'm thinking maybe to create a table purely for this purpose:
e.g.
Table name: Encrypt_Tool
fields: id, targetTable, targetField - plus some custom fields to show encrypted and unecrypted records count for each row for checking

Then add a row_inserted or row_updated event to encrypt the target table's Field for all records

Or is there an easier way?


Re: Field encryption with existing data (v2023)

Posted: Mon Feb 19, 2024 8:51 am
by arbei

You may create a simple script yourself to loop through the records and encrypt the fields by using the PhpEncrypt().

When you connect to your database, make sure you use the same encoding as your project, e.g. If you use MySQL 8, you should set name as "utf8bm4".


Re: Field encryption with existing data (v2023)

Posted: Tue May 14, 2024 7:29 pm
by philmills

I built a function which encrypts remaining unencrypted records on page edit.
I added it to User Submitted Tips:
viewtopic.php?t=59091