Search code examples
ruby-on-railsrubypostgresqlattr-encrypted

How we can decrypt data in rails raw sql query?


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?


Solution

  • @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.