public class Md5Crypt
extends java.lang.Object
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.
| Modifier and Type | Field and Description |
|---|---|
(package private) static java.lang.String |
APR1_PREFIX
The Identifier of the Apache variant.
|
private static int |
BLOCKSIZE
The number of bytes of the final hash.
|
(package private) static java.lang.String |
MD5_PREFIX
The Identifier of this crypt() variant.
|
private static int |
ROUNDS
The number of rounds of the big loop.
|
| Constructor and Description |
|---|
Md5Crypt() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
apr1Crypt(byte[] keyBytes)
See
apr1Crypt(String, String) for details. |
static java.lang.String |
apr1Crypt(byte[] keyBytes,
java.lang.String salt)
See
apr1Crypt(String, String) for details. |
static java.lang.String |
apr1Crypt(java.lang.String keyBytes)
See
apr1Crypt(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.
|
static final java.lang.String APR1_PREFIX
private static final int BLOCKSIZE
static final java.lang.String MD5_PREFIX
private static final int ROUNDS
public static java.lang.String apr1Crypt(byte[] keyBytes)
apr1Crypt(String, String) for details.keyBytes - plaintext string to hash.java.lang.RuntimeException - when a NoSuchAlgorithmException is caught. *public static java.lang.String apr1Crypt(byte[] keyBytes,
java.lang.String salt)
apr1Crypt(String, String) for details.keyBytes - plaintext string to hash.salt - An APR1 salt.java.lang.IllegalArgumentException - if the salt does not match the allowed patternjava.lang.RuntimeException - when a NoSuchAlgorithmException is caught.public static java.lang.String apr1Crypt(java.lang.String keyBytes)
apr1Crypt(String, String) for details.keyBytes - plaintext string to hash.java.lang.RuntimeException - when a NoSuchAlgorithmException is caught.public static java.lang.String apr1Crypt(java.lang.String keyBytes,
java.lang.String salt)
The algorithm is identical to the crypt(3) "$1$" one but produces different outputs due to the different salt prefix.
keyBytes - plaintext string to hash.salt - salt string including the prefix and optionally garbage at the end. Will be generated randomly if
null.java.lang.IllegalArgumentException - if the salt does not match the allowed patternjava.lang.RuntimeException - when a NoSuchAlgorithmException is caught.public static java.lang.String md5Crypt(byte[] keyBytes)
See Crypt.crypt(String, String) for details.
keyBytes - plaintext string to hash.java.lang.RuntimeException - when a NoSuchAlgorithmException is caught.public static java.lang.String md5Crypt(byte[] keyBytes,
java.lang.String salt)
See Crypt.crypt(String, String) for details.
keyBytes - plaintext string to hash.salt - salt string including the prefix and optionally garbage at the end. Will be generated randomly if
null.java.lang.IllegalArgumentException - if the salt does not match the allowed patternjava.lang.RuntimeException - when a NoSuchAlgorithmException is caught.public static java.lang.String md5Crypt(byte[] keyBytes,
java.lang.String salt,
java.lang.String prefix)
See Crypt.crypt(String, String) or apr1Crypt(String, String) for details.
keyBytes - plaintext string to hash.salt - May be null.prefix - salt prefixjava.lang.IllegalArgumentException - if the salt does not match the allowed patternjava.lang.RuntimeException - when a NoSuchAlgorithmException is caught.commons-codec version 1.10-SNAPSHOT - Copyright © 2002-2015 - Apache Software Foundation