使用Ruby生成openssl密码 [英] Generate openssl password with Ruby
问题描述
我想使用ruby openssl库生成与此openssl命令相同的东西:
I'd like to use the ruby openssl library to generate the same thing as this openssl command:
$ openssl passwd -1 mypassword
现在,在我的代码中,我正在这样做:
Right now, in my code, I'm doing this:
mypass = `openssl passwd -1 mypassword`
...这可行,但似乎很愚蠢.我觉得您应该可以使用OpenSSL :: Digest来达到相同的结果.但是,我似乎无法使其正常工作.
... this works, but it seems silly. I feel like you should be able to use OpenSSL::Digest to achieve the same result. However, I can't seem to get it to work.
推荐答案
openssl passwd -1
实现 UNIX加密(3)算法.实现(md5crypt)位于 apps/passwd.c
.结果,实现代码不是OpenSSL库函数.如功能注释所述:
openssl passwd -1
implements UNIX crypt(3) algorithm. The implementation (md5crypt) resides in apps/passwd.c
. As a result, the implementation code is not a OpenSSL library function. As the function comment says:
基于MD5的密码算法(应该可以作为 库功能;那么静态缓冲区是不可接受的.
MD5-based password algorithm (should probably be available as a library function; then the static buffer would not be acceptable).
因此您将无法在OpenSSL :: Digest中找到它.
So you will not find it in OpenSSL::Digest.
但是,您可能会发现其他有用的库,例如 unix-crypt .
However, you may find other libraries useful, such as unix-crypt.
这篇关于使用Ruby生成openssl密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!