ezcrypto 在 JRuby 中加密不一致(MRI 没问题)
我正在尝试使用 Ruby 中的 Ezcrypto gem 加密一些数据。在 MRI 下运行时一切正常,但是当使用 JRuby 运行相同的代码时我得到了奇怪的结果。
执行以下命令应该通过重复调用产生相同的输出。
MRI 的输出:
irb(main):007:0> Base64.encode64(EzCrypto::Key.encrypt_with_password "password", "salt","Top secret should not be revealed")
=> "6KNkObMUfXzyPey+TOGFHbozsmj5bGYqKql2Qava7++j5Moz0Zi2MwRp/FEC\nkpqw\n"
irb(main):008:0> Base64.encode64(EzCrypto::Key.encrypt_with_password "password", "salt","Top secret should not be revealed")
=> "6KNkObMUfXzyPey+TOGFHbozsmj5bGYqKql2Qava7++j5Moz0Zi2MwRp/FEC\nkpqw\n"
irb(main):009:0> Base64.encode64(EzCrypto::Key.encrypt_with_password "password", "salt","Top secret should not be revealed")
=> "6KNkObMUfXzyPey+TOGFHbozsmj5bGYqKql2Qava7++j5Moz0Zi2MwRp/FEC\nkpqw\n"
这个输出可以很容易地被解密。
不过,从 JRuby 中,每次调用我都会得到不同的输出:
irb(main):020:0> Base64.encode64(EzCrypto::Key.encrypt_with_password "password", "salt","Top secret should not be revealed")
=> "oX5JKZVkDbpbnrizI2bxkLVfQVfxayBAa0RbG+sfa9OUP1epzAyR7eDf92Bf\nVAiK\n"
irb(main):021:0> Base64.encode64(EzCrypto::Key.encrypt_with_password "password", "salt","Top secret should not be revealed")
=> "mmyKTtn78Dv3eiH2AET1olTkHNPMhtbiXth68Lqoph1nKkYyQH6cSWws/KI5\nwza0\n"
irb(main):022:0> Base64.encode64(EzCrypto::Key.encrypt_with_password "password", "salt","Top secret should not be revealed")
=> "pzDxS0p0CyDCkEY+QVyQKdgP1Of2ZeiNE06InS70ndkHnPwYOFmlH3h+xKXd\nmx54\n"
没有一个可以成功解密。
JRuby 中是否需要执行任何额外的配置步骤才能使其正常工作?
I'm trying to encrypt some data using the Ezcrypto gem in Ruby. Things work perfectly when running under MRI, but I'm getting strange results when running the same code using JRuby.
Executing the following should produce the same output with repeated called.
Output from MRI:
irb(main):007:0> Base64.encode64(EzCrypto::Key.encrypt_with_password "password", "salt","Top secret should not be revealed")
=> "6KNkObMUfXzyPey+TOGFHbozsmj5bGYqKql2Qava7++j5Moz0Zi2MwRp/FEC\nkpqw\n"
irb(main):008:0> Base64.encode64(EzCrypto::Key.encrypt_with_password "password", "salt","Top secret should not be revealed")
=> "6KNkObMUfXzyPey+TOGFHbozsmj5bGYqKql2Qava7++j5Moz0Zi2MwRp/FEC\nkpqw\n"
irb(main):009:0> Base64.encode64(EzCrypto::Key.encrypt_with_password "password", "salt","Top secret should not be revealed")
=> "6KNkObMUfXzyPey+TOGFHbozsmj5bGYqKql2Qava7++j5Moz0Zi2MwRp/FEC\nkpqw\n"
This output can be decrypted quite happily.
From JRuby though, I get different output on every call:
irb(main):020:0> Base64.encode64(EzCrypto::Key.encrypt_with_password "password", "salt","Top secret should not be revealed")
=> "oX5JKZVkDbpbnrizI2bxkLVfQVfxayBAa0RbG+sfa9OUP1epzAyR7eDf92Bf\nVAiK\n"
irb(main):021:0> Base64.encode64(EzCrypto::Key.encrypt_with_password "password", "salt","Top secret should not be revealed")
=> "mmyKTtn78Dv3eiH2AET1olTkHNPMhtbiXth68Lqoph1nKkYyQH6cSWws/KI5\nwza0\n"
irb(main):022:0> Base64.encode64(EzCrypto::Key.encrypt_with_password "password", "salt","Top secret should not be revealed")
=> "pzDxS0p0CyDCkEY+QVyQKdgP1Of2ZeiNE06InS70ndkHnPwYOFmlH3h+xKXd\nmx54\n"
None of which can be successfully decrypted.
Are there any extra configuration steps in JRuby that need to be done to get this to work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最终直接使用 OpenSSL 编写了相同的代码。梅西耶,但它有效。
我有一个理论,JRuby 下的 EzCrypto 每次调用加密时都会随机重新生成初始化向量,无法设置它,因此每次都有不同的输出。
没有机会进一步调查
Ended up just coding the same thing using OpenSSL directly. Messier, but it works.
I've got a theory that EzCrypto under JRuby regenerates the initialization vector randomly each time encrypt gets called, with no way to set it, hence different output each time.
Haven't had a chance to investigate further
看起来像是一个错误,您应该在 http://jira.codehaus.org/browse/JRUBY。
Looks like a bug you should file at http://jira.codehaus.org/browse/JRUBY.