Simple ActiveRecord attributes encryption in Rails 5+
Some notes:

The recommended way to overwrite accessors is to use super.

As @Flambino says, it's better not to hardcode secrets directly in the code. It can be a file not committed to the repository.



I'd write the crypt method this way:
  def crypt
    @crypt ||= begin
      key = ActiveSupport::KeyGenerator.new('password').generate_key('salt')    
      ActiveSupport::MessageEncryptor.new(key)
    end
  end