{"action":"created","issue":{"url":"https://api.github.com/repos/attr-encrypted/attr_encrypted/issues/130","labels_url":"https://api.github.com/repos/attr-encrypted/attr_encrypted/issues/130/labels{/name}","comments_url":"https://api.github.com/repos/attr-encrypted/attr_encrypted/issues/130/comments","events_url":"https://api.github.com/repos/attr-encrypted/attr_encrypted/issues/130/events","html_url":"https://github.com/attr-encrypted/attr_encrypted/issues/130","id":45743401,"number":130,"title":"Cannot find by encrypted field","user":{"login":"josegrad","id":650553,"avatar_url":"https://avatars.githubusercontent.com/u/650553?v=3","gravatar_id":"","url":"https://api.github.com/users/josegrad","html_url":"https://github.com/josegrad","followers_url":"https://api.github.com/users/josegrad/followers","following_url":"https://api.github.com/users/josegrad/following{/other_user}","gists_url":"https://api.github.com/users/josegrad/gists{/gist_id}","starred_url":"https://api.github.com/users/josegrad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josegrad/subscriptions","organizations_url":"https://api.github.com/users/josegrad/orgs","repos_url":"https://api.github.com/users/josegrad/repos","events_url":"https://api.github.com/users/josegrad/events{/privacy}","received_events_url":"https://api.github.com/users/josegrad/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2014-10-14T12:20:58Z","updated_at":"2015-07-09T16:50:35Z","closed_at":null,"body":"Hi,\r\n\r\nI'm using version 1.3.3 with Rails 4.0.0 and Ruby 1.9.3.\r\nI can store encrypted fields but using a find or where with mongoid 4.0.0.beta1 returns nothing.\r\n\r\n```\r\nclass Discount\r\n  \tinclude Mongoid::Document\r\n    include Mongoid::Timestamps\r\n\r\n\r\n    field :encrypted_email, :type => String\r\n    attr_encrypted :email, :key => ENV['DISK'], :encode => true, :charset => \"utf-8\"\r\n\r\n    field :encrypted_address, :type => String\r\n    attr_encrypted :address, :key => ENV['DISK'], :encode => true, :charset => \"utf-8\"\r\n\r\nend\r\n\r\nDiscount.first.email\r\n => \"lucas@email.com\"\r\n\r\nDiscount.where(:email => \"lucas@email.com\").first\r\n => nil \r\n\r\n```\r\nAny hints?\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/attr-encrypted/attr_encrypted/issues/comments/120066645","html_url":"https://github.com/attr-encrypted/attr_encrypted/issues/130#issuecomment-120066645","issue_url":"https://api.github.com/repos/attr-encrypted/attr_encrypted/issues/130","id":120066645,"user":{"login":"spq24","id":631397,"avatar_url":"https://avatars.githubusercontent.com/u/631397?v=3","gravatar_id":"","url":"https://api.github.com/users/spq24","html_url":"https://github.com/spq24","followers_url":"https://api.github.com/users/spq24/followers","following_url":"https://api.github.com/users/spq24/following{/other_user}","gists_url":"https://api.github.com/users/spq24/gists{/gist_id}","starred_url":"https://api.github.com/users/spq24/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spq24/subscriptions","organizations_url":"https://api.github.com/users/spq24/orgs","repos_url":"https://api.github.com/users/spq24/repos","events_url":"https://api.github.com/users/spq24/events{/privacy}","received_events_url":"https://api.github.com/users/spq24/received_events","type":"User","site_admin":false},"created_at":"2015-07-09T16:50:35Z","updated_at":"2015-07-09T16:50:35Z","body":"Hi @billymonk \r\n\r\nI'm having an issue with this. I'm trying to use the find_by methods in the documentation and although they are set up the right way it doesn't seem to be working.\r\n\r\nI'm using this to encrypt stripe tokens for my customers. \r\n\r\nA given stripe customers unencrypted token is: cus_6ZqTwcXuvymA7SFD\r\n\r\nWhen I do c = customer.find(158) and get the customer back and look at c.stripe_token it comes back correctly and it's encrypted in the db so I know it's working.\r\n\r\nHowever when I do Customer.find_by_stripe_token('cus_6ZqTwcXuvymA7SFD')\r\n\r\nI get nil back. When I look at the encrypted stripe token in the SQL query it does not match the encrypted version for this customer's token. \r\n\r\nI have done this all in the console so far so I don't really have code to share, but I can put it together real quick if you think that would help, but if it works in code it should work in the console.\r\n\r\nAny ideas?\r\n\r\n\r\n\r\n"}}