I'm trying to create an MD5
checksum in ruby
with salt, but I cannot find any way to do this using the standard digest/md5
package.
I know I can do this:
require 'digest/md5'
checksum = '$1$' + (Digest::MD5.new << plaintext).to_s
However, there doesn't appear to be any way to specify salt for this MD5
checksum generation using digest
, and I haven't found any other package I could use for this in ruby
.
Is this even possible in ruby
?
I found the following, and it does what I want ...
https://github.com/mogest/unix-crypt
It works like this:
require 'unix_crypt'
checksum = UnixCrypt::MD5.build(plaintext, salt)
This generates the same checksum as is used in /etc/shadow, which is what I want to use it for,