ezcrypto 在 JRuby 中加密不一致(MRI 没问题)

发布于 2024-08-11 13:11:56 字数 1549 浏览 3 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故笙诉离歌 2024-08-18 13:11:56

最终直接使用 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

巴黎盛开的樱花 2024-08-18 13:11:56

看起来像是一个错误,您应该在 http://jira.codehaus.org/browse/JRUBY

Looks like a bug you should file at http://jira.codehaus.org/browse/JRUBY.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文