F
Filament14mo ago
Emaz

Encryption of text data

I'd like to do encryption/decryption of text data in a mutator. Is that going to impact places where I allow filtering and searching? That would depend on how Filament handles search/filter. If it's a normal Eloquent query this might be a no-go. On the other hand, if it's loading data in a way that goes through the mutator I'd be OK. Anyone know?
Solution:
Nope, nope, I take it back. I mixed up local and prod. The end result is as you'd expect. Encryption works but search and sort do not. Bummer. I'd like to suggest this goes on a roadmap for a feature but I have no idea how it would be done....
Jump to solution
8 Replies
toeknee
toeknee14mo ago
That's a good question, I would suspect you will have issues with searching since eloquent will encrypt the data you are passing through it so it will likely only allow exact matches...
Dennis Koch
Dennis Koch14mo ago
Searching/Filtering happens on DB level, so you definitely will have issues.
Emaz
EmazOP14mo ago
Somehow, this is working. Searches and sorts are fine and my DB is encrypted. protected function name(): Attribute { return Attribute::make( get: fn (string $value) => Crypt::decryptString($value), set: fn (string $value) => Crypt::encryptString($value), ); } protected function details(): Attribute { return Attribute::make( get: fn (string $value) => Crypt::decryptString($value), set: fn (string $value) => Crypt::encryptString($value), ); }
Dennis Koch
Dennis Koch14mo ago
Interesting 🧐
Solution
Emaz
Emaz14mo ago
Nope, nope, I take it back. I mixed up local and prod. The end result is as you'd expect. Encryption works but search and sort do not. Bummer. I'd like to suggest this goes on a roadmap for a feature but I have no idea how it would be done.
Dennis Koch
Dennis Koch14mo ago
Yeah, that's the point of encryption right? 😅
Emaz
EmazOP14mo ago
I’m so used to clever and useful Laravel features I thought maybe there were some magic way somebody had figured out how to do this. I mean, Agolia can but I’ve never gone down that path. I know this is a difficult problem & there are a handful of solutions. But yeah, not the easy one that I had hoped for. Lol
toeknee
toeknee14mo ago
It's just physically impossible which encrypted data without first decrypting it and then searching. In doing this it would be a massive slow down, I beleive some databases do allow this on the fly, but then the salt would need to be at the database level.
Want results from more Discord servers?
Add your server