How we can decrypt data in rails raw sql query?

488 Views Asked by At

In rails i have used gem => attr_encrypted using above gem data encrypted in PostgreSQL DB table.

using model name can be decrypt. But how I can do in raw query in select query like i have column encrypted in table like email encrypted and email_encrypted_iv

now I want to use raw query in rails application like

User.select('email, id')

Using above query how we can get data decrypted in select query?

1

There are 1 best solutions below

0
Chiperific On BEST ANSWER

@Sergio is right, you can't decrypt the database data via SQL when Rails did the encrypting.

You'll have to pull out the record(s) with Rails and do the decryption via the gem.