如何转换PHP crypt函数(SHA512)红宝石? [英] How to convert php crypt function (SHA512) to ruby?
问题描述
注意:我不是在寻找解决办法,我要寻找一个简单的解决方案,红宝石
这个问题是类似于此<一个href=\"http://stackoverflow.com/questions/5171487/using-ruby-to-generate-sha512-crypt-style-hashes-formatted-for-etc-shadow\">question,但它不answerd,它只是一个解决方法,以壳突击队在那里。
我想生成一个SHA512加密字符串这与Debian的/ etc / shadow文件格式不兼容。
下面创建一个正确的字符串 PHP :
$盐='fGn9LR75';
$哈希=隐窝('测试','$ 6 $'$盐);
//哈希:
// $ 6 $ $ fGn9LR75 YPI / vJHjEhvrYp5 / eUSRinpiXdMthCxFWSEo0ktFNUaRBsA7pCWYzzmQptmnfyHno9YEJFNHYuESj3nAQmSzc1
据我知道这样一个正常的,咸的base64 EN codeD字符串。沙代法的规范是这里
IRB(主):001:0&GT;盐='fGn9LR75';
IRB(主):002:0 *哈希='test'.crypt('$ 6 $'+盐);
IRB(主):003:0 *哈希
= GT; $ 6 $ $ fGn9LR75 YPI / vJHjEhvrYp5 / eUSRinpiXdMthCxFWSEo0ktFNUaRBsA7pCWYzzmQptmnfyHno9YEJFNHYuESj3nAQmSzc1
的 /的crypt()
算法SHA256 512的不的只是一个base64-CN codeD哈希值。这是一个疯狂的故意的过程,涉及到多个散列并行运行。
note: i am not looking for workaround, i am looking for a plain ruby solution!
this question is the similar to this question, but it isn't answerd, its just a workaround to a shell commando there.
i want to generate a sha512 encrypted string which is compatible with the format in debian /etc/shadow.
the following create a correct string with php:
$salt = 'fGn9LR75';
$hash = crypt('test', '$6$'.$salt);
// hash is:
// $6$fGn9LR75$YpI/vJHjEhvrYp5/eUSRinpiXdMthCxFWSEo0ktFNUaRBsA7pCWYzzmQptmnfyHno9YEJFNHYuESj3nAQmSzc1
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"
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.
这篇关于如何转换PHP crypt函数(SHA512)红宝石?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!