How To How to encrypt Personal data for GDPR in MySQL

How to encrypt Personal data for GDPR in MySQL

Encrypt personal data for GDPR in MySQL - Techbriefers

Before going towards how to encrypt Personal data for GDPR and knowing how to encrypt and decrypt MySQL data using AES_ENCRYPT() AND AES_DECRYPT() functions. Let me explain whether is it required to encrypt user data for GDPR compliance or not.

GDPR is “General Data Protection Regulation” which states so many set of rules for user data protection. Any website should follow these rules if it uses or stores end user data in any form. This is the reason why most of the websites need to display a cookie notice/policy. In accordance with using website functionality user will have to accept these policies. They also present their cookie and privacy policies on how they using the end user data.

Now talking about encryption of user data. As per my study it may be recommendation to encrypt user data for security and integrity reasons.

I have read many article along with some clauses of GDPR policies and found that “According to GDPR it is recommended to encrypt user’s personal data using a key“. I could not found anywhere that websites must have to encrypt the end user data to store it. So…

Encrypting personal data STRICTLY SPEAKING is not mandatory.

Internet

Well many website would like to follow the recommended guidelines. Each company do not have a database administrator. For those who are very small scale ones, it is very difficult to main such a scenario.

I have found a workaround by which there will be no data loss and encryption will be easily performed along with data retention.

The method I am using to encrypt and decrypt MySQL data is a by MySQL functions AES_ENCRYPT() AND AES_DECRYPT(). Anybody can use this method very efficiently for encryption decryption for GDPR.

What is AES_ENCRYPT() function? Read More

What is AES_DECRYPT() function? Read More

How to create encrypted data from the existing one using AES_ENCRYPT

Now i will discuss the main process of encrypting user data and create new encrypted data from the existing data. There are two options. You can chose any of them as per your comfort and requirement.

We are going to discuss with example in reference with the table ‘students‘.

Before opting any method please do take a backup of your data or at least backup your table.

Method One:

Suitable for the data where table has very few columns that need to be encrypted. If you have many or all columns for encryption it is better to chose the second method. Let see the method One:

  • Create columns with a similar name (or other) each for the column to be encrypted. Like I have to encrypt columns student_name, student_email and student_dob as these three column contain user’s personal data.
Add encryption column for GDPR data encryption| Techbriefers

Now Copy Original Column data to these new created columns in encrypted form.

Data after encrypted update for GDPR TechBriefers
Data after encrypted update – TechBriefers

Now rename the encrypted columns to original columns and before that rename original column to some other name or drop those columns

To rename original columns to some other (say suffixing ‘_old’) and encryption columns renaming to original ones..

Final table Structure supported for GDPR encryption- Techbriefers
Final table Structure – Techbriefers

If you want to drop the old columns use :

Now see the final table and data will now be like:

Data after encrypted update for GDPR encryption - TechBriefers
Data after encrypted update – TechBriefers

Let’s check if the Encryption is done correctly and the data is integrated. The decrypted result of encrypted columns and non encrypted old data is fetched by below query.

Decrypted result - GDPR dencryption - Techbriefers
Decrypted result – Techbriefers

4 thoughts on “How to encrypt Personal data for GDPR in MySQL

  1. Nice article. You mentioned a second way for more complex tables, but I dont see the Method 2 …?
    Im interested to know what route you suggest.
    Many Thanks

  2. That’s good for complying the law but where to save the key and how to refresh the key will need to be considered

Average
4.5 Based On 4

Leave a Reply