rails: New app: "key must be 32 bits".

Steps to reproduce

Run rails s. No more… (new app)

Expected behavior

It should display my index.

Actual behavior

It fails.

Here is what is going wrong: capture d ecran 2016-05-28 a 21 18 13

Can you help me? Don’t understand at all.

System configuration

Rails version: 5.0.0.rc1

Ruby version: 2.4.0dev

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 30 (13 by maintainers)

Commits related to this issue

Most upvoted comments

Hmm, after some digging in some C code (💀), looks like there is a new breaking change in OpenSSL, which rejects certain values for key=, which is the bug you are running into. 😦

Looking into fixes.

Same issue (Rails 5.1.0.alpha1, ruby-2.4.preview1)

Upgrade your Rails version to 5.0.1

I still have the same issue when upgrading from ruby version 2.2.8 to 2.5.1. My rails version is 5.1.5. I have a key that has a size of 40 bytes. Is this considered an issue with rails and will this be patched in future versions or not?

I was experiencing this issue earlier my solution is described beneath the heading element at the bottom of this comment.

screen shot 2018-09-20 at 7 53 50 am

Rails and Ruby version:

$ ruby -v 
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]
$ rails -v
Rails 5.0.7

Stack trace:

activesupport (5.0.0) lib/active_support/message_encryptor.rb:72:in `key='
activesupport (5.0.0) lib/active_support/message_encryptor.rb:72:in `_encrypt'
activesupport (5.0.0) lib/active_support/message_encryptor.rb:58:in `encrypt_and_sign'
actionpack (5.0.0) lib/action_dispatch/middleware/cookies.rb:592:in `commit'
actionpack (5.0.0) lib/action_dispatch/middleware/cookies.rb:465:in `[]='
actionpack (5.0.0) lib/action_dispatch/middleware/session/cookie_store.rb:117:in `set_cookie'
rack (2.0.1) lib/rack/session/abstract/id.rb:353:in `commit_session'
rack (2.0.1) lib/rack/session/abstract/id.rb:224:in `context'
rack (2.0.1) lib/rack/session/abstract/id.rb:216:in `call'
actionpack (5.0.0) lib/action_dispatch/middleware/cookies.rb:613:in `call'
activerecord (5.0.0) lib/active_record/migration.rb:552:in `call'
actionpack (5.0.0) lib/action_dispatch/middleware/callbacks.rb:38:in `block in call'
activesupport (5.0.0) lib/active_support/callbacks.rb:97:in `__run_callbacks__'
activesupport (5.0.0) lib/active_support/callbacks.rb:750:in `_run_call_callbacks'
activesupport (5.0.0) lib/active_support/callbacks.rb:90:in `run_callbacks'
actionpack (5.0.0) lib/action_dispatch/middleware/callbacks.rb:36:in `call'
actionpack (5.0.0) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.0.0) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
actionpack (5.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'
actionpack (5.0.0) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.0.0) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.0.0) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.0.0) lib/active_support/tagged_logging.rb:70:in `block in tagged'
activesupport (5.0.0) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.0.0) lib/active_support/tagged_logging.rb:70:in `tagged'
railties (5.0.0) lib/rails/rack/logger.rb:24:in `call'
sprockets-rails (3.1.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.0.0) lib/action_dispatch/middleware/request_id.rb:24:in `call'
rack (2.0.1) lib/rack/method_override.rb:22:in `call'
rack (2.0.1) lib/rack/runtime.rb:22:in `call'
activesupport (5.0.0) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
actionpack (5.0.0) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.0.0) lib/action_dispatch/middleware/static.rb:136:in `call'
rack (2.0.1) lib/rack/sendfile.rb:111:in `call'
railties (5.0.0) lib/rails/engine.rb:522:in `call'
puma (3.6.0) lib/puma/configuration.rb:225:in `call'
puma (3.6.0) lib/puma/server.rb:578:in `handle_request'
puma (3.6.0) lib/puma/server.rb:415:in `process_client'
puma (3.6.0) lib/puma/server.rb:275:in `block in run'
puma (3.6.0) lib/puma/thread_pool.rb:116:in `block in spawn_thread'

Running bundle update was the key. I upgraded Ruby from 2.0 to 2.5.1 yesterday so that may have played a role. Here’s the terminal readout of the successful update which solved the problem:

screen shot 2018-09-20 at 8 04 50 am

How I Got it Running Locally

I ran bundle install then I followed up with bundle update.

Then I reset the server (CMD+C then rails s)

After updating bundle, I forgot to restart the server and spent a few minutes researching the error needlessly. So… restarting the server is important. 🥇

My motivation for putting this solution here is that I found this thread while seeking a solution to the error. The above conversation is helpful for understanding how problems in Rails are diagnosed. There was no specific solution for a young Rails developer like myself.

The problem is about the ruby 2.4.0, just for now if you want a quick solution use ruby 2.3.1

Hi, have the same issue on rails 7.0.4 and ruby 3.1.2

$ ruby -v
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux]
$ rails -v
Rails 7.0.4

image

 🚴  » rails -v
Rails 4.2.8
 🚴  » ruby -v
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin14]

Lot’s of fails during tests :

      ArgumentError:
        key must be 32 bytes
      # /Users/bti/.rvm/gems/ruby-2.4.0/gems/activesupport-4.2.8/lib/active_support/message_encryptor.rb:79:in `key='
      # /Users/bti/.rvm/gems/ruby-2.4.0/gems/activesupport-4.2.8/lib/active_support/message_encryptor.rb:79:in `_encrypt'
      # /Users/bti/.rvm/gems/ruby-2.4.0/gems/activesupport-4.2.8/lib/active_support/message_encryptor.rb:60:in `encrypt_and_sign'