如何将 php crypt 函数(SHA512)转换为 ruby?
注意:我不是在寻找解决方法,我在寻找一个普通的 ruby 解决方案!
这个问题类似于这个 问题,但没有得到回答,这只是那里的炮弹突击队的一种解决方法.
this question is the similar to this question, but it isn't answerd, its just a workaround to a shell commando there.
我想生成一个与 debian/etc/shadow 格式兼容的 sha512 加密字符串.
i want to generate a sha512 encrypted string which is compatible with the format in debian /etc/shadow.
以下使用 php 创建一个正确的字符串:p>
the following create a correct string with php:
$salt = 'fGn9LR75';
$hash = crypt('test', '$6$'.$salt);
// hash is:
// $6$fGn9LR75$YpI/vJHjEhvrYp5/eUSRinpiXdMthCxFWSEo0ktFNUaRBsA7pCWYzzmQptmnfyHno9YEJFNHYuESj3nAQmSzc1
据我所知,这是一个正常的、加盐的 base64 编码字符串.sha 生成方法的规范是 这里
as far as i know this a normal, salted base64 encoded string. the spec of the sha generation method is here
推荐答案
irb(main):001:0> salt = 'fGn9LR75';
irb(main):002:0* hash = 'test'.crypt('$6$' + salt);
irb(main):003:0* hash
=> "$6$fGn9LR75$YpI/vJHjEhvrYp5/eUSRinpiXdMthCxFWSEo0ktFNUaRBsA7pCWYzzmQptmnfyHno9YEJFNHYuESj3nAQmSzc1"
SHA256/512 的 crypt()
算法不是简单的 base64 编码散列.这是一个故意疯狂的过程,涉及并行运行的多个哈希.
The crypt()
algorithm for SHA256/512 is not simply a base64-encoded hash. It's an intentionally crazy process which involves multiple hashes running in parallel.
相关文章