Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to update historical unencrypted data #33

Closed
saulomaximo opened this issue Jul 19, 2024 · 3 comments
Closed

how to update historical unencrypted data #33

saulomaximo opened this issue Jul 19, 2024 · 3 comments

Comments

@saulomaximo
Copy link

Hello,

I'm currently using Ruby 2.5.9 and Rails 5.2. I'm facing difficulties updating historical records using the model, especially after set to encrypt a specific attribute.

The scenario involves a table with existing historical data where a decision was made to encrypt a particular attribute. After configuring the model, new objects are successfully created with the attribute encrypted. However, I encounter issues when attempting to load or update old records. Specifically, I'm receiving the error message ActiveSupport::MessageVerifier::InvalidSignature.

Could someone advise on how to update the historical data and ensure the attribute is encrypted properly?

@saulomaximo saulomaximo changed the title how to update historical unencrypted data on table how to update historical unencrypted data Jul 19, 2024
@alpaca-tc
Copy link
Owner

ActiveSupport has changed its default encryption method.
If a column is encrypted using an older method, it may not be decryptable by the new method.
While I don't have all the details to provide a comprehensive fix, here are some related changes and a simple solution that might help:

rails/rails#29263

# Use old cipher `cipher: 'aes-256-cbc'`
encrypted_attribute(:name, :field, encryption: { encryptor: :active_support, key: ENV['ENCRYPTION_KEY'], salt: ENV['ENCRYPTION_SALT'], cipher: 'aes-256-cbc' })

rails/rails#41043

# Use old hash_digest_class
Rails.application.config.active_support.hash_digest_class = OpenSSL::Digest::SHA1

@alpaca-tc
Copy link
Owner

Oops, were you talking about encrypting existing columns?
If you want to encrypt an existing column, the simplest way would be to add a new column for encryption and migrate the existing data to the new column.

@saulomaximo
Copy link
Author

Thank you for the explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants