0

我说的是这个:

$ openssl passwd -1 -salt thesalt thepassword
$1$thesalt$HAWpBmvUCutuyTS4JwevI.

在 PHP 中,它看起来像这样:

crypt('thepassword', ('$1$'.'thesalt')); # this gives the same output as above

我试图在 Ruby 1.9 中实现相同的格式。有人告诉我 Ruby 的 String#crypt 会这样做,但事实并非如此。我到处寻找答案,但我什么也没遇到。

如果它有任何帮助,我正在尝试在 Windows XP 上执行此操作。Ruby 版本:ruby 1.9.3p0 (2011-10-30) [i386-mingw32]

只是为了避免评论告诉我使用 MD5 或其他任何东西以外的东西,如果可以的话,我会的。这个选择不取决于我。

谢谢。

编辑:我想在不使用openssl的情况下做到这一点,因为这对于我需要的东西来说太慢了。

4

2 回答 2

0

该死。我希望同样的事情。

另请参阅使用 Ruby 生成 openssl 密码,以了解它不在 ruby​​ 中的原因。

于 2014-01-23T14:28:38.793 回答
0

如果一切都失败了,您可以openssl使用反引号调用可执行文件:

password = "thepassword"
salt = "thesalt"
hashed = `openssl passwd -1 -salt #{salt} #{password}`

puts hashed  # => $1$thesalt$HAWpBmvUCutuyTS4JwevI.
于 2012-03-19T03:38:00.303 回答