Class Md5Crypt
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
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringapr1Crypt(byte[] keyBytes) Seeapr1Crypt(byte[], String)for details.static StringSeeapr1Crypt(String, String)for details.static StringSeeapr1Crypt(byte[], String)for details.static StringSeeapr1Crypt(String, String)for details.static StringGenerates an Apache htpasswd compatible "$apr1$" MD5 based hash value.static Stringmd5Crypt(byte[] keyBytes) Generates a libc6 crypt() compatible "$1$" hash value.static StringGenerates a libc crypt() compatible "$1$" MD5 based hash value.static StringGenerates a libc6 crypt() "$1$" or Apache htpasswd "$apr1$" hash value.static StringGenerates a libc6 crypt() "$1$" or Apache htpasswd "$apr1$" hash value.static StringGenerates a libc6 crypt() compatible "$1$" hash value.
-
Constructor Details
-
Md5Crypt
Deprecated.TODO Make private in 2.0.TODO Make private in 2.0.
-
-
Method Details
-
apr1Crypt
Seeapr1Crypt(byte[], String)for details.A salt is generated for you using
SecureRandom; your ownRandominapr1Crypt(byte[], Random).- Parameters:
keyBytes- plaintext string to hash. Each array element is set to0before returning.- Returns:
- the hash value
- Throws:
IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught. *- See Also:
-
apr1Crypt
Seeapr1Crypt(byte[], String)for details.A salt is generated for you using the user provided
Random.- Parameters:
keyBytes- plaintext string to hash. Each array element is set to0before returning.random- the instance ofRandomto use for generating the salt. Consider usingSecureRandomfor more secure salts.- Returns:
- the hash value
- Throws:
IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught. *- Since:
- 1.12
- See Also:
-
apr1Crypt
Seeapr1Crypt(String, String)for details.A salt is generated for you using
SecureRandom- Parameters:
keyBytes- plaintext string to hash. Each array element is set to0before returning.salt- An APR1 salt. The salt may be null, in which case a salt is generated for you usingSecureRandom- Returns:
- the hash value
- Throws:
IllegalArgumentException- if the salt does not match the allowed patternIllegalArgumentException- when aNoSuchAlgorithmExceptionis caught.
-
apr1Crypt
Seeapr1Crypt(String, String)for details.A salt is generated for you using
SecureRandom.- Parameters:
keyBytes- plaintext string to hash. Each array element is set to0before returning.- Returns:
- the hash value
- Throws:
IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught.- See Also:
-
apr1Crypt
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. Each array element is set to0before returning.salt- salt string including the prefix and optionally garbage at the end. The salt may be null, in which case a salt is generated for you usingSecureRandom.- Returns:
- the hash value
- Throws:
IllegalArgumentException- if the salt does not match the allowed patternIllegalArgumentException- when aNoSuchAlgorithmExceptionis caught.
-
md5Crypt
Generates a libc6 crypt() compatible "$1$" hash value.See
md5Crypt(byte[], String)for details.A salt is generated for you using
SecureRandom.- Parameters:
keyBytes- plaintext string to hash. Each array element is set to0before returning.- Returns:
- the hash value
- Throws:
IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught.- See Also:
-
md5Crypt
Generates a libc6 crypt() compatible "$1$" hash value.See
md5Crypt(byte[], String)for details.A salt is generated for you using the instance of
Randomyou supply.- Parameters:
keyBytes- plaintext string to hash. Each array element is set to0before returning.random- the instance ofRandomto use for generating the salt. Consider usingSecureRandomfor more secure salts.- Returns:
- the hash value
- Throws:
IllegalArgumentException- when aNoSuchAlgorithmExceptionis caught.- Since:
- 1.12
- See Also:
-
md5Crypt
Generates a libc crypt() compatible "$1$" MD5 based hash value.See
Crypt.crypt(String, String)for details. We useSecureRandomfor seed generation by default.- Parameters:
keyBytes- plaintext string to hash. Each array element is set to0before returning.salt- salt string including the prefix and optionally garbage at the end. The salt may be null, in which case a salt is generated for you usingSecureRandom.- Returns:
- the hash value
- Throws:
IllegalArgumentException- if the salt does not match the allowed patternIllegalArgumentException- when aNoSuchAlgorithmExceptionis caught.
-
md5Crypt
Generates a libc6 crypt() "$1$" or Apache htpasswd "$apr1$" hash value.See
Crypt.crypt(String, String)orapr1Crypt(String, String)for details. We useby default.- Parameters:
keyBytes- plaintext string to hash. Each array element is set to0before returning.salt- real salt value without prefix or "rounds=". The salt may be null, in which case a salt is generated for you usingSecureRandom.prefix- The salt prefix "$apr1$", "$1$".- Returns:
- the hash value
- Throws:
IllegalArgumentException- if the salt does not match the allowed patternIllegalArgumentException- when aNoSuchAlgorithmExceptionis caught.
-
md5Crypt
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. Each array element is set to0before returning.salt- real salt value without prefix or "rounds=". The salt may be null, in which case a salt is generated for you usingSecureRandom.prefix- The salt prefix "$apr1$", "$1$".random- the instance ofRandomto use for generating the salt. Consider usingSecureRandomfor more secure salts.- Returns:
- the hash value
- Throws:
IllegalArgumentException- if the salt or prefix does not match the allowed patternIllegalArgumentException- when aNoSuchAlgorithmExceptionis caught.- Since:
- 1.12
-