Class Sha2Crypt

java.lang.Object
org.apache.commons.codec.digest.Sha2Crypt

public class Sha2Crypt extends Object
SHA2-based Unix crypt implementation.

Based on the C implementation released into the Public Domain by Ulrich Drepper <drepper@redhat.com> http://www.akkadia.org/drepper/SHA-crypt.txt

Conversion to Kotlin and from there to Java in 2012 by Christian Hammers <ch@lathspell.de> and likewise put into the Public Domain.

This class is immutable and thread-safe.

Since:
1.7
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final int
    Default number of rounds if not explicitly specified.
    private static final int
    Maximum number of rounds.
    private static final int
    Minimum number of rounds.
    private static final String
    Prefix for optional rounds specification.
    private static final Pattern
    The pattern to match valid salt values.
    private static final int
    The number of bytes the final hash value will have (SHA-256 variant).
    (package private) static final String
    The prefixes that can be used to identify this crypt() variant (SHA-256).
    private static final int
    The number of bytes the final hash value will have (SHA-512 variant).
    (package private) static final String
    The prefixes that can be used to identify this crypt() variant (SHA-512).
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    sha256Crypt(byte[] keyBytes)
    Generates a libc crypt() compatible "$5$" hash value with random salt.
    static String
    sha256Crypt(byte[] keyBytes, String salt)
    Generates a libc6 crypt() compatible "$5$" hash value.
    static String
    sha256Crypt(byte[] keyBytes, String salt, Random random)
    Generates a libc6 crypt() compatible "$5$" hash value.
    private static String
    sha2Crypt(byte[] keyBytes, String salt, String saltPrefix, int blocksize, String algorithm)
    Generates a libc6 crypt() compatible "$5$" or "$6$" SHA2 based hash value.
    static String
    sha512Crypt(byte[] keyBytes)
    Generates a libc crypt() compatible "$6$" hash value with random salt.
    static String
    sha512Crypt(byte[] keyBytes, String salt)
    Generates a libc6 crypt() compatible "$6$" hash value.
    static String
    sha512Crypt(byte[] keyBytes, String salt, Random random)
    Generates a libc6 crypt() compatible "$6$" hash value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait