Project

unix-crypt

0.12
No commit activity in last 3 years
No release in over 3 years
Performs the UNIX crypt(3) algorithm using DES (standard 13 character passwords), MD5 (starting with $1$), SHA256 (starting with $5$) and SHA512 (starting with $6$)
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
 Dependencies
 Project Readme

unix-crypt¶ ↑

Description¶ ↑

unix-crypt creates and checks passwords that you'd normally find in an /etc/shadow file on your UNIX box.

It's written entirely in Ruby and has no external dependencies.

It handles:

  • DES passwords (the standard 13 character password with a 2 character salt)

  • MD5 passwords (starting with $1$)

  • SHA256 passwords (starting with $5$)

  • SHA512 passwords (starting with $6$)

This library is compatible with Ruby 1.8.7 and above. Tested on Ruby 2.0.0p353.

Installation¶ ↑

gem install unix-crypt

Using the command line tool¶ ↑

An executable named mkunixcrypt allows you to generate passwords from the command line.

Usage: mkunixcrypt [options]
Encrypts password using the unix-crypt gem

Options:
    -h, --hash [HASH]                Set hash algorithm [SHA512 (default), SHA256, MD5, DES]
    -p, --password [PASSWORD]        Provide password on command line (insecure!)
    -s, --salt [SALT]                Provide hash salt
    -r, --rounds [ROUNDS]            Set number of hashing rounds (SHA256/SHA512 only)
        --help                       Show this message
    -v, --version                    Show version

Using the library¶ ↑

You can either validate a password of any type matches its hash:

>> require 'unix_crypt'
=> true
>> UnixCrypt.valid?("Hello world!", "$5$saltstring$5B8vYYiY.CVt1RlTTf8KbXBH3hsxY/GNooZaBBGWEc5")
=> true

Or you can generate a new hash, given a password and salt:

>> UnixCrypt::SHA256.build("Hello world!", "saltstring")
=> "$5$saltstring$5B8vYYiY.CVt1RlTTf8KbXBH3hsxY/GNooZaBBGWEc5"

If a salt is not specified, one will be generated using random data:

>> UnixCrypt::SHA256.build("Hello world!")
=> "$5$v.fjb6lucDCZKjcf$90gzpr9HYo0eAeaN8rubElJdUUOcVYjTnGePBRvCgt1"

There are four classes you can use, depending on which hashing algorithm you'd like:

UnixCrypt::DES
UnixCrypt::MD5
UnixCrypt::SHA256
UnixCrypt::SHA512

License¶ ↑

Licensed under the BSD license. See LICENSE file for details.

Author¶ ↑

  • Roger Nesbitt (roger@seriousorange.com)

Contributors¶ ↑

  • Patrick Wyatt (pat@codeofhonor.com)