Package org.apache.commons.codec.digest
Class Sha2Crypt
java.lang.Object
org.apache.commons.codec.digest.Sha2Crypt
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
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic Stringsha256Crypt(byte[] keyBytes) Generates a libc crypt() compatible "$5$" hash value with random salt.static Stringsha256Crypt(byte[] keyBytes, String salt) Generates a libc6 crypt() compatible "$5$" hash value.static Stringsha256Crypt(byte[] keyBytes, String salt, Random random) Generates a libc6 crypt() compatible "$5$" hash value.static Stringsha512Crypt(byte[] keyBytes) Generates a libc crypt() compatible "$6$" hash value with random salt.static Stringsha512Crypt(byte[] keyBytes, String salt) Generates a libc6 crypt() compatible "$6$" hash value.static Stringsha512Crypt(byte[] keyBytes, String salt, Random random) Generates a libc6 crypt() compatible "$6$" hash value.
- 
Constructor Details- 
Sha2CryptDeprecated.Will be private in the next major version.Consider private.
 
- 
- 
Method Details- 
sha256CryptGenerates a libc crypt() compatible "$5$" hash value with random salt.See Crypt.crypt(String, String)for details.A salt is generated for you using SecureRandom.- Parameters:
- keyBytes- plaintext to hash. Each array element is set to- 0before returning.
- Returns:
- complete hash value
- Throws:
- IllegalArgumentException- when a- NoSuchAlgorithmExceptionis caught.
 
- 
sha256CryptGenerates a libc6 crypt() compatible "$5$" hash value.See Crypt.crypt(String, String)for details.- Parameters:
- keyBytes- plaintext to hash. Each array element is set to- 0before returning.
- salt- real salt value without prefix or "rounds=". The salt may be null, in which case a salt is generated for you using- SecureRandom. If one does not want to use- SecureRandom, you can pass your own- Randomin- sha256Crypt(byte[], String, Random).
- Returns:
- complete hash value including salt
- Throws:
- IllegalArgumentException- if the salt does not match the allowed pattern
- IllegalArgumentException- when a- NoSuchAlgorithmExceptionis caught.
 
- 
sha256CryptGenerates a libc6 crypt() compatible "$5$" hash value.See Crypt.crypt(String, String)for details.- Parameters:
- keyBytes- plaintext to hash. Each array element is set to- 0before returning.
- salt- real salt value without prefix or "rounds=".
- random- the instance of- Randomto use for generating the salt. Consider using- SecureRandomfor more secure salts.
- Returns:
- complete hash value including salt
- Throws:
- IllegalArgumentException- if the salt does not match the allowed pattern
- IllegalArgumentException- when a- NoSuchAlgorithmExceptionis caught.
- Since:
- 1.12
 
- 
sha512CryptGenerates a libc crypt() compatible "$6$" hash value with random salt.See Crypt.crypt(String, String)for details.A salt is generated for you using SecureRandom- Parameters:
- keyBytes- plaintext to hash. Each array element is set to- 0before returning.
- Returns:
- complete hash value
- Throws:
- IllegalArgumentException- when a- NoSuchAlgorithmExceptionis caught.
 
- 
sha512CryptGenerates a libc6 crypt() compatible "$6$" hash value.See Crypt.crypt(String, String)for details.- Parameters:
- keyBytes- plaintext to hash. Each array element is set to- 0before returning.
- salt- real salt value without prefix or "rounds=". The salt may be null, in which case a salt is generated for you using- SecureRandom; if you want to use a- Randomobject other than- SecureRandomthen we suggest you provide it using- sha512Crypt(byte[], String, Random).
- Returns:
- complete hash value including salt
- Throws:
- IllegalArgumentException- if the salt does not match the allowed pattern
- IllegalArgumentException- when a- NoSuchAlgorithmExceptionis caught.
 
- 
sha512CryptGenerates a libc6 crypt() compatible "$6$" hash value.See Crypt.crypt(String, String)for details.- Parameters:
- keyBytes- plaintext to hash. Each array element is set to- 0before returning.
- salt- real salt value without prefix or "rounds=". The salt may be null, in which case a salt is generated for you using- SecureRandom.
- random- the instance of- Randomto use for generating the salt. Consider using- SecureRandomfor more secure salts.
- Returns:
- complete hash value including salt
- Throws:
- IllegalArgumentException- if the salt does not match the allowed pattern
- IllegalArgumentException- when a- NoSuchAlgorithmExceptionis caught.
- Since:
- 1.12
 
 
-