How to convert php crypt (SHA512) function to ruby?

note: I'm not looking for a workaround, I'm looking for a simple ruby โ€‹โ€‹solution!

this question is similar to this question , but this is not the answer, its just a workaround to the shell there.

I want to create an encrypted sha512 string that is compatible with the format in debian / etc / shadow.

create the correct line with php :

$salt = 'fGn9LR75'; $hash = crypt('test', '$6$'.$salt); // hash is: // $6$fGn9LR75$YpI/vJHjEhvrYp5/eUSRinpiXdMthCxFWSEo0ktFNUaRBsA7pCWYzzmQptmnfyHno9YEJFNHYuESj3nAQmSzc1 

as far as i know this is a normal, salty base64 encoded string. sha generation method specification here

+1
ruby php base64 sha512
source share
1 answer
 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 just a base64 based hash code. This is an intentionally crazy process that involves several hashes running in parallel.

+2
source share

All Articles