I inherited a Rails app that integrates with Facebook and encrypts a token sent from Facebook, which it saves as a user's identifying auth token.
For a variety of reasons, I ended up updating my Ruby, and some Gemfile changes have occurred which are causing issues with the app. The most significant one is a change to attr_encrypted
, which, through the encrypted
gem, handles the encryption of that Facebook token as it's saved to the database.
The trouble is, the app, which is live and already has many users, has an base secret encryption key that is too short for the newly updated attr_encrypted
's security standards. Specifically, when I try to encrypt a token now (in tests for now; I haven't pushed these changes live), an error is thrown saying that the key needs to be 32 bytes.
The question:
Does anyone have a suggestion for updating to a more secure token? If I change the token, I assume that will break decryption of the token, so that I, potentially permanently, lose the ability to read/use all the user identity tokens in the database. That's obviously pretty problematic, so I wanted to double check my thinking here.
My current thought is a migration: Run a migration that loops through each identity, decrypts the stored token using my old key, and then saves a newly-encrypted token with a new, longer key.
Then I can get rid of the old key without any issues. Right? Any issues anyone can think of regarding the peculiarities of the attr_encrypted
gem or issues with encryption generally that I might not be thinking about?