Class Sha256Crypt
- java.lang.Object
-
- com.identity4j.util.unix.Sha256Crypt
-
public final class Sha256Crypt extends Object
This class defines a method,
Sha256_crypt(), which takes a password and a salt string and generates a Sha256 encrypted password entry.This class implements the new generation, scalable, SHA256-based Unix 'crypt' algorithm developed by a group of engineers from Red Hat, Sun, IBM, and HP for common use in the Unix and Linux /etc/shadow files.
The Linux glibc library (starting at version 2.7) includes support for validating passwords hashed using this algorithm.
The algorithm itself was released into the Public Domain by Ulrich Drepper <drepper@redhat.com>. A discussion of the rationale and development of this algorithm is at
http://people.redhat.com/drepper/sha-crypt.html
and the specification and a sample C language implementation is at
http://people.redhat.com/drepper/SHA-crypt.txt
-
-
Constructor Summary
Constructors Constructor Description Sha256Crypt()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidmain(String[] arg)Test rigstatic StringSha256_crypt(String keyStr, String saltStr, int roundsCount)This method actually generates an Sha256 crypted password hash from a plaintext password and a salt.static booleanverifyHashTextFormat(String sha256CryptText)Returns true if sha256CryptText is a valid Sha256Crypt hashtext, false if not.static booleanverifyPassword(String plaintextPass, String sha256CryptText)This method tests a plaintext password against a SHA256 Unix Crypt'ed hash and returns true if the password matches the hash.
-
-
-
Method Detail
-
Sha256_crypt
public static final String Sha256_crypt(String keyStr, String saltStr, int roundsCount)
This method actually generates an Sha256 crypted password hash from a plaintext password and a salt.
The resulting string will be in the form '$5$<rounds=n>$<salt>$<hashed mess>
- Parameters:
keyStr- Plaintext passwordsaltStr- An encoded salt/roundes which will be consulted to determine the salt and round count, if not nullroundsCount- If this value is not 0, this many rounds will used to generate the hash text.- Returns:
- The Sha256 Unix Crypt hash text for the keyStr
-
verifyPassword
public static final boolean verifyPassword(String plaintextPass, String sha256CryptText)
This method tests a plaintext password against a SHA256 Unix Crypt'ed hash and returns true if the password matches the hash.
- Parameters:
plaintextPass- The plaintext password text to test.sha256CryptText- The hash text we're testing against. We'll extract the salt and the round count from this String.
-
verifyHashTextFormat
public static final boolean verifyHashTextFormat(String sha256CryptText)
Returns true if sha256CryptText is a valid Sha256Crypt hashtext, false if not.
-
main
public static void main(String[] arg)
Test rig
-
-