Package org.apache.commons.codec.digest
Class Md5Crypt
- java.lang.Object
-
- org.apache.commons.codec.digest.Md5Crypt
-
public class Md5Crypt extends java.lang.Object
The libc crypt() "$1$" and Apache "$apr1$" MD5-based hash algorithm.Based on the public domain ("beer-ware") C implementation from Poul-Henning Kamp which was found at: crypt-md5.c @ freebsd.org
Source:
$FreeBSD: src/lib/libcrypt/crypt-md5.c,v 1.1 1999/01/21 13:50:09 brandon Exp $
Conversion to Kotlin and from there to Java in 2012.
The C style comments are from the original C code, the ones with "//" from the port.
This class is immutable and thread-safe.
- Since:
- 1.7
- Version:
- $Id: Md5Crypt.java 1744746 2016-05-20 14:19:43Z sebb $
-
-
Constructor Summary
Constructors Constructor Description Md5Crypt()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
apr1Crypt(byte[] keyBytes)
Seeapr1Crypt(String, String)
for details.static java.lang.String
apr1Crypt(byte[] keyBytes, java.lang.String salt)
Seeapr1Crypt(String, String)
for details.static java.lang.String
apr1Crypt(java.lang.String keyBytes)
Seeapr1Crypt(String, String)
for details.static java.lang.String
apr1Crypt(java.lang.String keyBytes, java.lang.String salt)
Generates an Apache htpasswd compatible "$apr1$" MD5 based hash value.static java.lang.String
md5Crypt(byte[] keyBytes)
Generates a libc6 crypt() compatible "$1$" hash value.static java.lang.String
md5Crypt(byte[] keyBytes, java.lang.String salt)
Generates a libc crypt() compatible "$1$" MD5 based hash value.static java.lang.String
md5Crypt(byte[] keyBytes, java.lang.String salt, java.lang.String prefix)
Generates a libc6 crypt() "$1$" or Apache htpasswd "$apr1$" hash value.
-
-
-
Constructor Detail
-
Md5Crypt
public Md5Crypt()
-
-
Method Detail
-
apr1Crypt
public static java.lang.String apr1Crypt(byte[] keyBytes)
Seeapr1Crypt(String, String)
for details.- Parameters:
keyBytes
- plaintext string to hash.- Returns:
- the hash value
- Throws:
java.lang.RuntimeException
- when aNoSuchAlgorithmException
is caught. *
-
apr1Crypt
public static java.lang.String apr1Crypt(byte[] keyBytes, java.lang.String salt)
Seeapr1Crypt(String, String)
for details.- Parameters:
keyBytes
- plaintext string to hash.salt
- An APR1 salt.- Returns:
- the hash value
- Throws:
java.lang.IllegalArgumentException
- if the salt does not match the allowed patternjava.lang.RuntimeException
- when aNoSuchAlgorithmException
is caught.
-
apr1Crypt
public static java.lang.String apr1Crypt(java.lang.String keyBytes)
Seeapr1Crypt(String, String)
for details.- Parameters:
keyBytes
- plaintext string to hash.- Returns:
- the hash value
- Throws:
java.lang.RuntimeException
- when aNoSuchAlgorithmException
is caught.
-
apr1Crypt
public static java.lang.String apr1Crypt(java.lang.String keyBytes, java.lang.String salt)
Generates an Apache htpasswd compatible "$apr1$" MD5 based hash value.The algorithm is identical to the crypt(3) "$1$" one but produces different outputs due to the different salt prefix.
- Parameters:
keyBytes
- plaintext string to hash.salt
- salt string including the prefix and optionally garbage at the end. Will be generated randomly if null.- Returns:
- the hash value
- Throws:
java.lang.IllegalArgumentException
- if the salt does not match the allowed patternjava.lang.RuntimeException
- when aNoSuchAlgorithmException
is caught.
-
md5Crypt
public static java.lang.String md5Crypt(byte[] keyBytes)
Generates a libc6 crypt() compatible "$1$" hash value.See
Crypt.crypt(String, String)
for details.- Parameters:
keyBytes
- plaintext string to hash.- Returns:
- the hash value
- Throws:
java.lang.RuntimeException
- when aNoSuchAlgorithmException
is caught.
-
md5Crypt
public static java.lang.String md5Crypt(byte[] keyBytes, java.lang.String salt)
Generates a libc crypt() compatible "$1$" MD5 based hash value.See
Crypt.crypt(String, String)
for details.- Parameters:
keyBytes
- plaintext string to hash.salt
- salt string including the prefix and optionally garbage at the end. Will be generated randomly if null.- Returns:
- the hash value
- Throws:
java.lang.IllegalArgumentException
- if the salt does not match the allowed patternjava.lang.RuntimeException
- when aNoSuchAlgorithmException
is caught.
-
md5Crypt
public static java.lang.String md5Crypt(byte[] keyBytes, java.lang.String salt, java.lang.String prefix)
Generates a libc6 crypt() "$1$" or Apache htpasswd "$apr1$" hash value.See
Crypt.crypt(String, String)
orapr1Crypt(String, String)
for details.- Parameters:
keyBytes
- plaintext string to hash.salt
- May be null.prefix
- salt prefix- Returns:
- the hash value
- Throws:
java.lang.IllegalArgumentException
- if the salt does not match the allowed patternjava.lang.RuntimeException
- when aNoSuchAlgorithmException
is caught.
-
-