Rails: ActiveSupport::MessageEncryptor::InvalidMessage

前端 未结 5 1184
暗喜
暗喜 2020-12-30 06:35

Help me please, I\'ve finished 11 chapters of the rails tutorial, deployed my app to heroku (locally it worked perfectly) and it crashing all time. I\'m using rails 5.2.2 Af

相关标签:
5条回答
  • 2020-12-30 06:52

    I had this issue when working on a Rails 6 application in Ubuntu 20.04.

    The issue was that I was setting/specifying a wrong RAILS_MASTER_KEY environment variable in my .env files in development (.env, .env.development). I just wanted to use it as a placeholder temporarily since I did not need it in my development environment.

    This was then throwing the error below when I run a rails command, say rails generate uploader ProductImage:

    `rescue in _decrypt': ActiveSupport::MessageEncry ptor::InvalidMessage (ActiveSupport::MessageEncryptor::InvalidMessage)

    And even when I try generating a new master.key and the credentials.yml.enc files using rails credentials:edit or EDITOR="code --wait" bin/rails credentials:edit it throws the error below:

    key=': key must be 16 bytes (ArgumentError)
    

    Here's how to fix it:

    What you have to do is to either provide the correct RAILS_MASTER_KEY environment variable in the .env file(s) or comment out the RAILS_MASTER_KEY environment variable if you are not using it.

    That's it.

    I hope this helps

    0 讨论(0)
  • 2020-12-30 06:59
    1. Remove the credentials:
    rm -rf config/credentials.yml.enc
    
    1. Create a new credentials:
      EDITOR="mate --wait" bin/rails credentials:edit
    

    Hope it's helpful.

    0 讨论(0)
  • 2020-12-30 07:02

    You need to ask for the master key to you project leader / team leader / coworkers.

    With that long key like 3823729sdad29323832idsd you copy it and paste it the master.key file under config folder.

    That solve the issue.

    0 讨论(0)
  • 2020-12-30 07:04

    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
    }
    
    0 讨论(0)
  • the only way for me was to renew my master key.

    1. copy your decrypted credentials
    2. remove the files
    3. regenerate key
    4. read the datas

    This post help me https://github.com/rails/rails/issues/32718

    0 讨论(0)
提交回复
热议问题