Rails: ActiveSupport::MessageEncryptor::InvalidMessage
Here are the docs for environmental security on rails https://guides.rubyonrails.org/security.html#environmental-security
In your case, you should have these files
config/master.key
config/credentials.yml.enc
Delete those files and then you can generate with this:
rails credentials:edit
Now the file master.key is ignored by your version control because it is the key rails use to decrypt the .enc, just commit your credentials.yml.enc and push it to heroku.
For master.key on heroku you can define the environment variable RAILS_MASTER_KEY on your heroku app and put the value of master.key on it.
Now to access the environments variables that you defined on your .enc file you must access through Rails.application.credentials
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => Rails.application.credentials.SENDGRID_USERNAME,
:password => Rails.application.credentials.SENDGRID_PASSWORD,
:domain => 'heroku.com',
:enable_starttls_auto => true
}
- Remove the credentials:
rm -rf config/credentials.yml.enc
- Create a new credentials:
EDITOR="mate --wait" bin/rails credentials:edit
Hope it's helpful.
the only way for me was to renew my master key.
- copy your decrypted credentials
- remove the files
- regenerate key
- read the datas
This post help me https://github.com/rails/rails/issues/32718