Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8350761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:25:26+00:00 2026-06-09T08:25:26+00:00

I have attr_accessible :access_token attr_encrypted :access_token, key: ENV[‘ENCRYPTION_KEY’] and I’m doing some User.find_by_access_token ,

  • 0

I have

attr_accessible :access_token
attr_encrypted :access_token, key: ENV['ENCRYPTION_KEY']

and I’m doing some User.find_by_access_token, so I’d like to index the field in the db.

However, no access_token exists, only encrypted_access_token.

Does indexing this do the same thing as indexing any other field?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T08:25:27+00:00Added an answer on June 9, 2026 at 8:25 am

    The whole point of saving encrypted data is to prevent the cleartext from showing. Obviously you cannot search for it, or the whole concept would be flawed.

    You can index the encrypted token with a plain index and search the table with the encrypted token – for which you obviously need the encryption key.

    CREATE INDEX tbl_encrypted_access_token_idx ON tbl(encrypted_access_token);
    
    SELECT *
    FROM   tbl
    WHERE  encrypted_access_token = <encrypted_token>;
    

    If all your tokens can be decrypted with an IMMUTABLE Postgres function, you could use an index on an expression:

    CREATE INDEX tbl_decrypted_token_idx
    ON tbl(decrypt_func(encrypted_access_token));
    
    SELECT *
    FROM   tbl
    WHERE  decrypt_func(encrypted_access_token) = <access_token>;
    

    Note that the expression has to match the expression in the index for the index to be useful.

    But that would pose a security hazard on multiple levels.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say we have some basic AR model. class User < ActiveRecord::Base attr_accessible :firstname,
I have the following models: class EventParticipant < ActiveRecord::Base belongs_to :event has_one :user attr_accessible
I have 2 models: class UserPrice < ActiveRecord::Base attr_accessible :price, :product_name belongs_to :user belongs_to
I have this code in my user model: class User < ActiveRecord::Base attr_accessible :email,
I have these classes: class User has_one :user_profile accepts_nested_attributes_for :user_profile attr_accessible :email, :password, :password_confirmation,
Rails 2.3.8. I have 3 models, User, Source, and Subscription. User attr_accessible :source_ids has_many
I have a User and a Gallery model and the following associations: gallery.rb attr_accessible
I have users class User < ActiveRecord::Base devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable attr_accessible
i have a meeting.rb and user.rb model meeting.rb class Meeting < ActiveRecord::Base attr_accessible :intro,
I have a main model called 'Notes' which has the following: attr_accessible :name, :label_tokens

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.