Using attr_encrypted with Rails 5.2 credentials master key

Andrey Viktorov
1 min readNov 20, 2018

Today’s another short tutorial is about using encryption key from Rails 5.2 credentials to encrypt/decrypt fields with attr_encrypted.

This way you can encrypt your database fields in Rails 5.2 without using separate keys for the fields and for the credentials:

attr_encrypted :super_secret_token, key: Rails.application.credentials.key

Aaaaand… that’s it ¯\_(ツ)_/¯

--

--