无法附加到OpenSSL Cipher

时间:2014-06-23 16:39:02

标签: ruby-on-rails ruby openssl

我在创建密码时遇到了一些麻烦,奇怪的是如果我在irb中运行脚本或在我的ROR应用程序外面运行.rb文件一切正常。

继承我的剧本。

require 'openssl'
require 'digest/sha1'

cipher = OpenSSL::Cipher::Cipher.new("bf-cbc").encrypt
cipher.key_len = 16
cipher.key= "random encryption key*"
v = cipher.random_iv.unpack("H*").first
xs = ((cipher << Digest::SHA1.hexdigest("you@example.com")) + cipher.final).unpack("H*").first

错误:

 NoMethodError: undefined method `<<' for  OpenSSL::Cipher::Cipher:0x007f800b60c920

我尝试替换&lt;&lt;用推,我得到同样的错误。

IRB
Ruby:1.8.7

申请细节
Ruby:1.9.2
Rails:3.0.6

之前有没有人遇到过这个问题?

1 个答案:

答案 0 :(得分:1)

cipher上的<<方法在1.8.7中已弃用,在1.9中已删除(请参阅docs)。看起来您应该使用update方法。

猜测你安装了多个版本的ruby,调用的默认版本是1.8.7,但你的rails应用程序运行的是1.9或更新版本。这可能是因为.ruby-version文件,.rvmrc文件或因为仅为其中一个版本安装了rails。