Activesupport和openssl:密钥必须为32个字节

时间:2018-09-28 16:00:33

标签: ruby-on-rails-4 openssl activesupport

我有一个Rails 4.2.1项目,需要一个与openssl 2.1.1有关的gem。我的红宝石版本是2.3.1。当我添加openssl gem时,对于我加载的任何页面,都会出现以下错误:

lib/active_support/message_encryptor.rb:100: warning: constant OpenSSL::Cipher::Cipher is deprecated

ArgumentError (key must be 32 bytes):
activesupport (4.2.1) lib/active_support/message_encryptor.rb:72:in `key='
  activesupport (4.2.1) lib/active_support/message_encryptor.rb:72:in `_encrypt'
  activesupport (4.2.1) lib/active_support/message_encryptor.rb:58:in `encrypt_and_sign'
  actionpack (4.2.1) lib/action_dispatch/middleware/cookies.rb:527:in `[]='
  actionpack (4.2.1) lib/action_dispatch/middleware/session/cookie_store.rb:110:in `set_cookie'
  rack (1.6.10) lib/rack/session/abstract/id.rb:351:in `commit_session'
  rack (1.6.10) lib/rack/session/abstract/id.rb:226:in `context'
  rack (1.6.10) lib/rack/session/abstract/id.rb:220:in `call'
  actionpack (4.2.1) lib/action_dispatch/middleware/cookies.rb:560:in `call'

是否存在使两者兼容的解决方法?

1 个答案:

答案 0 :(得分:0)

在不更改旧密钥的情况下,我使用下面的代码来接收密钥:succsscull:

  

attr_encrypted:属性,密钥:ENV ['MY_KEY']。bytes [0..31] .pack(“ c” * 32)