Rails: ActiveSupport::MessageEncryptor::InvalidMessage (credentials.yml.enc can't be decrypted — wrong master.key)
Rails couldn't decrypt credentials.yml.enc (or a signed/encrypted cookie) because the key is wrong or the data changed.
ActiveSupport::MessageEncryptor::InvalidMessage (ActiveSupport::MessageEncryptor::InvalidMessage)OpenSSL::Cipher::CipherError credentials.yml.encCannot decrypt credentials with the wrong master key Meaning
For credentials: the config/master.key (or RAILS_MASTER_KEY) doesn't match the one that encrypted the file. Restore the right key from your team/secrets store; if lost, delete credentials.yml.enc and recreate (losing old secrets). For cookies: secret_key_base changed so old sessions are invalid — users just log in again.
Common causes
- Wrong or missing
RAILS_MASTER_KEY credentials.yml.enccommitted from another keysecret_key_basechanged (cookies/sessions)- Corrupted file after merge conflict
- Different environment credentials file
⚡ Quick fix
- Set the correct
RAILS_MASTER_KEY - Re-create credentials:
rm config/credentials.yml.enc && bin/rails credentials:edit(if the key is lost) - Clear old cookies after changing
secret_key_base
Detailed fix by platform
Rails
EDITOR=vim bin/rails credentials:edit(needs the correct master key)
How to diagnose
- Key — master.key matches?
- File — Merge conflict?
- Cookies — secret_key_base changed?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- ActiveRecord::AssociationTypeMismatch Rails: ActiveRecord::AssociationTypeMismatch: User(#1234) expected, got "42" which is an instance of String(#5678)
- ActiveRecord::ConnectionNotEstablished Rails: ActiveRecord::ConnectionNotEstablished: No connection pool for 'ActiveRecord::Base' found
- ActiveRecord::Deadlocked: PG::TRDeadlockDetected Rails: ActiveRecord::Deadlocked: PG::TRDeadlockDetected: ERROR: deadlock detected
Most viewed in Ruby / Rails
- ActiveRecord::PendingMigrationError Rails: ActiveRecord::PendingMigrationError — Migrations are pending. To resolve this issue, run: bin/rails db:migrate
- undefined method for nil Ruby: NoMethodError: undefined method `x' for nil (nil:NilClass)
- ActionController::InvalidAuthenticityToken Rails: ActionController::InvalidAuthenticityToken (Can't verify CSRF token authenticity)
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 5 Nov 2026