Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

codepotato's avatar

Querying encrypted columns - what do you do?

We're building a service that will contain sensitive information (financial data) and I've taken the standpoint to encrypt the data before pushing into the database.

However, the column also needs to be queryable and as the encryption happens in a trait it's only decrypted once plucked out of the database and converted to an object.

This means that for now, we would have to pull ALL rows and then query the object in PHP. As this app grows this won't be ideal, so just curious what others do?

0 likes
1 reply
Tray2's avatar

I would not pull data out of the database and the filter it, I would encode the search data then query the database.

Something like this (pseudo code)

public function search(CustomRequest $request )
{
	$searchTerm = $request->encode('search_term');
	$record = Model::where('field', $searchTerm)->get();
	$data = $record->decode();
	return view('secret.show)->with(['data' => $data]);
}

Please or to participate in this conversation.