How to decrypt using Encrypted Field Type
Created 6 years ago by kiltedup

Greetings,

I have added a field using the Encrypted Field Type. All fine and can see it is indeed encrypted in db.

However when I come to decrypt, I'm getting this error : "Call to a member function decrypt() on string"

The config is the default, so auto_decrypt is set to false - getting the error when using $entry->thefield->decrypt() as per docs.

Anyway using this field type / seen this / have any tips?

Ta 😄

ryanthompson  —  6 years ago

decrypt is a presenter method so you will need to do $entry->decorated->thefield->decrypt()

kiltedup  —  6 years ago

Thanks for the reply. I tried that as well but the output was still the encrypted string.

kiltedup  —  6 years ago

OK - I see what is going on but not sure why?

I have a stream with around 15 fields - one of them is the encrypted field type. When the form is first submitted, all fields are entered and checking again, the decrypt is fine.

But I reuse the form again in a couple of places to edit the entry but just 2 of the fields (not the encrypted one) - they are set using $builder->setFields([...])

When that is submitted, the two fields are updated however the encryption is done again on the encrypted field. So my output that I thought was the encryption not working when using ->decorated, is in fact the decrypted value, except it is a decryption of the previous encrypted value !!!!!!!

My head hurts 😄

Is there a way to stop the encrypted field updating like this?

Ta

ryanthompson  —  6 years ago

Aha! You want to skip those fields. You can do $builder->skipField($slug) or $builder->setSkips($fieldSlugs) or a combination of the two (The latter is dictative)

ryanthompson  —  6 years ago

Fields is more about configuration overrides n such.. and simple placement sometimes when no layout.

kiltedup  —  6 years ago

Already tried skipping the field. No cigar!

modify in EncryptedFieldTypeModifier still gets hit - takes the old value and encrypts it again ?!?!?!

ryanthompson  —  6 years ago

I'll test on this end momentarily but check for slugs and if it's a multiform builder you'll need to skip it (including prefix) from the parent / muti builder OR without prefix from the child form.