October 22, 2024
Chicago 12, Melborne City, USA
security

Encryption and Searching JSON Data using Laravel


I’m working on a system that stores users’ data in a JSON format. An example of table structure and JSON format is shown below.

Visitor Id Visitor Name JSON Data
101 John {JSON_DATA_SHOWN_BELOW}
102 Doe {JSON_DATA_SHOWN_BELOW}
{
 "fields": [
    {
        "name": "Email Address",
        "type": "email",
        "label": "Enter your email address.",
        "value": "name@email.com",
        "required": "false"
    },
    {
        "name": "Your Company",
        "type": "string",
        "label": "Enter Your Company",
        "value": "My Company Name",
        "required": "false"
    }
 ] 
}

Since it stores personal data, I need to encrypt the value properties of each object. This is pretty straightforward and I’m able to encrypt this. But the challenge is, the system has a requirement to search the records based on the field value. For example if user search "name@email.com", then the system should return back record corresponding whole record, say visitor id 101.

The challenge I’m facing is, I didn’t find any efficient and secure solutions to achieve this feature. Solutions that I know but doesn’t seems perfect are:

  • Retrieve all records at first, decrypt back each values and perform search operation. But this is not efficient as the system stores huge amount of data and this approach is not suitable.
  • I can add a hashed value of the data along with an encrypted value, so I can perform search operation based on hashed_value and decrypt back the actual data using encrypted value. This solves the problem, but still, it is not 100% secure as attackers could attack the hashed value with pre-computed tables or brute force attacks.

Is there any other secure and efficient way possible through Laravel & MySQL to perform encryption and searching, which I’m missing? All help would be much appreciated.



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video