public class Sha2Crypt extends Object
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.
Constructor and Description |
---|
Sha2Crypt() |
Modifier and Type | Method and 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 |
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.
|
public static String sha256Crypt(byte[] keyBytes)
See Crypt.crypt(String, String)
for details.
keyBytes
- plaintext to hashRuntimeException
- when a NoSuchAlgorithmException
is caught.public static String sha256Crypt(byte[] keyBytes, String salt)
See Crypt.crypt(String, String)
for details.
keyBytes
- plaintext to hashsalt
- real salt value without prefix or "rounds="IllegalArgumentException
- if the salt does not match the allowed patternRuntimeException
- when a NoSuchAlgorithmException
is caught.public static String sha512Crypt(byte[] keyBytes)
See Crypt.crypt(String, String)
for details.
keyBytes
- plaintext to hashRuntimeException
- when a NoSuchAlgorithmException
is caught.public static String sha512Crypt(byte[] keyBytes, String salt)
See Crypt.crypt(String, String)
for details.
keyBytes
- plaintext to hashsalt
- real salt value without prefix or "rounds="IllegalArgumentException
- if the salt does not match the allowed patternRuntimeException
- when a NoSuchAlgorithmException
is caught.Copyright © 2002–2017 The Apache Software Foundation. All rights reserved.