Class ModularCrypt
- java.lang.Object
-
- org.wildfly.security.password.util.ModularCrypt
-
public final class ModularCrypt extends Object
Helper utility methods for operation on passwords based on the Modular Crypt Format(MCF).- Author:
- Juraci Paixão Kröhling, David M. Lloyd
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
ModularCrypt.ModCryptBase64Alphabet
-
Field Summary
Fields Modifier and Type Field Description private static int
A_APACHE_HTDIGEST
private static int
A_BCRYPT
private static int
A_BSD_CRYPT_DES
private static int
A_BSD_NT_HASH
private static int
A_CRYPT_DES
private static int
A_CRYPT_MD5
private static int
A_CRYPT_SHA_256
private static int
A_CRYPT_SHA_512
private static int
A_MASKED
private static int
A_SUN_CRYPT_MD5
private static int
A_SUN_CRYPT_MD5_BARE_SALT
(package private) static org.wildfly.common.codec.Base64Alphabet
BCRYPT
The BCrypt alphabet.private static int[]
MD5_IDX
private static int[]
MD5_IDX_REV
(package private) static org.wildfly.common.codec.Base64Alphabet
MOD_CRYPT
The modular crypt alphabet, used in various modular crypt password types.(package private) static org.wildfly.common.codec.Base64Alphabet
MOD_CRYPT_LE
The modular crypt alphabet, used in various modular crypt password types.private static int[]
SHA_256_IDX
private static int[]
SHA_256_IDX_REV
private static int[]
SHA_512_IDX
private static int[]
SHA_512_IDX_REV
-
Constructor Summary
Constructors Modifier Constructor Description private
ModularCrypt()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static void
composeBsdCryptBasedPassword(ByteArrayOutputStream out, BSDUnixDESCryptPassword password)
private static void
composeCryptBasedPassword(ByteArrayOutputStream out, UnixDESCryptPassword password)
static void
composePassword(ByteArrayOutputStream out, Password password)
private static Password
createBsdCryptBasedPassword(byte[] userPassword)
private static Password
createCryptBasedPassword(byte[] userPassword)
static Password
createPassword(byte[] password, String algorithm)
static Password
decode(char[] cryptString)
Decode the given char array and creates aPassword
instance.static Password
decode(String cryptString)
Decode the given string and creates aPassword
instance.private static int
doIdentifyAlgorithm(char[] chars)
static char[]
encode(Password password)
Encode the givenPassword
to a char array.static String
encodeAsString(Password password)
Encode the givenPassword
to a string.private static String
getAlgorithmNameString(int id)
private static StringBuilder
getCryptStringToBuilder(Password password)
static String
identifyAlgorithm(char[] chars)
Attempt to identify the algorithm used by the given crypt string password.private static int[]
inverse(int[] orig)
private static int
lastIndexOf(char[] chars, char c)
private static Password
parseBCryptPasswordString(char[] cryptString)
private static Password
parseBSDUnixDESCryptPasswordString(char[] cryptString)
private static Password
parseMaskedPasswordString(char[] chars)
private static int
parseModCryptIterationCount(org.wildfly.common.iteration.CodePointIterator reader, int minIterations, int maxIterations, int defaultIterations)
private static Password
parseSunUnixMD5CryptPasswordString(String algorithm, char[] cryptString)
private static Password
parseUnixDESCryptPasswordString(char[] cryptString)
private static Password
parseUnixMD5CryptPasswordString(char[] cryptString)
private static Password
parseUnixSHA256CryptPasswordString(char[] cryptString)
private static Password
parseUnixSHA512CryptPasswordString(char[] cryptString)
private static Password
parseUnixSHACryptPassword(char[] cryptString, int[] table, String algorithm)
-
-
-
Field Detail
-
A_CRYPT_MD5
private static final int A_CRYPT_MD5
- See Also:
- Constant Field Values
-
A_BCRYPT
private static final int A_BCRYPT
- See Also:
- Constant Field Values
-
A_BSD_NT_HASH
private static final int A_BSD_NT_HASH
- See Also:
- Constant Field Values
-
A_CRYPT_SHA_256
private static final int A_CRYPT_SHA_256
- See Also:
- Constant Field Values
-
A_CRYPT_SHA_512
private static final int A_CRYPT_SHA_512
- See Also:
- Constant Field Values
-
A_SUN_CRYPT_MD5
private static final int A_SUN_CRYPT_MD5
- See Also:
- Constant Field Values
-
A_APACHE_HTDIGEST
private static final int A_APACHE_HTDIGEST
- See Also:
- Constant Field Values
-
A_BSD_CRYPT_DES
private static final int A_BSD_CRYPT_DES
- See Also:
- Constant Field Values
-
A_CRYPT_DES
private static final int A_CRYPT_DES
- See Also:
- Constant Field Values
-
A_SUN_CRYPT_MD5_BARE_SALT
private static final int A_SUN_CRYPT_MD5_BARE_SALT
- See Also:
- Constant Field Values
-
A_MASKED
private static final int A_MASKED
- See Also:
- Constant Field Values
-
MD5_IDX
private static final int[] MD5_IDX
-
MD5_IDX_REV
private static final int[] MD5_IDX_REV
-
SHA_256_IDX
private static final int[] SHA_256_IDX
-
SHA_256_IDX_REV
private static final int[] SHA_256_IDX_REV
-
SHA_512_IDX
private static final int[] SHA_512_IDX
-
SHA_512_IDX_REV
private static final int[] SHA_512_IDX_REV
-
MOD_CRYPT
static final org.wildfly.common.codec.Base64Alphabet MOD_CRYPT
The modular crypt alphabet, used in various modular crypt password types.
-
MOD_CRYPT_LE
static final org.wildfly.common.codec.Base64Alphabet MOD_CRYPT_LE
The modular crypt alphabet, used in various modular crypt password types.
-
BCRYPT
static final org.wildfly.common.codec.Base64Alphabet BCRYPT
The BCrypt alphabet.
-
-
Method Detail
-
doIdentifyAlgorithm
private static int doIdentifyAlgorithm(char[] chars)
-
identifyAlgorithm
public static String identifyAlgorithm(char[] chars)
Attempt to identify the algorithm used by the given crypt string password.- Parameters:
chars
- the password crypt string characters- Returns:
- the algorithm name, or
null
if no algorithm could be guessed
-
getAlgorithmNameString
private static String getAlgorithmNameString(int id)
-
encode
public static char[] encode(Password password) throws InvalidKeySpecException
Encode the givenPassword
to a char array.- Parameters:
password
- the password to encode- Returns:
- a char array representing the encoded password
- Throws:
InvalidKeySpecException
- if the given password is not supported or could be encoded
-
encodeAsString
public static String encodeAsString(Password password) throws InvalidKeySpecException
Encode the givenPassword
to a string.- Parameters:
password
- the password to encode- Returns:
- a string representing the encoded password
- Throws:
InvalidKeySpecException
- if the given password is not supported or could be encoded
-
getCryptStringToBuilder
private static StringBuilder getCryptStringToBuilder(Password password) throws InvalidKeySpecException
- Throws:
InvalidKeySpecException
-
decode
public static Password decode(String cryptString) throws InvalidKeySpecException
Decode the given string and creates aPassword
instance.- Parameters:
cryptString
- the string representing the encoded format of the password- Returns:
- a
Password
instance created from the given string - Throws:
InvalidKeySpecException
- if the given password is not supported or could be decoded
-
decode
public static Password decode(char[] cryptString) throws InvalidKeySpecException
Decode the given char array and creates aPassword
instance.- Parameters:
cryptString
- the char array representing the encoded format of the password- Returns:
- a
Password
instance created from the given string - Throws:
InvalidKeySpecException
- if the given password is not supported or could be decoded
-
createPassword
public static Password createPassword(byte[] password, String algorithm) throws InvalidKeySpecException
- Throws:
InvalidKeySpecException
-
composePassword
public static void composePassword(ByteArrayOutputStream out, Password password) throws IOException
- Throws:
IOException
-
parseModCryptIterationCount
private static int parseModCryptIterationCount(org.wildfly.common.iteration.CodePointIterator reader, int minIterations, int maxIterations, int defaultIterations) throws InvalidKeySpecException
- Throws:
InvalidKeySpecException
-
inverse
private static int[] inverse(int[] orig)
-
parseUnixSHA256CryptPasswordString
private static Password parseUnixSHA256CryptPasswordString(char[] cryptString) throws InvalidKeySpecException
- Throws:
InvalidKeySpecException
-
parseUnixSHA512CryptPasswordString
private static Password parseUnixSHA512CryptPasswordString(char[] cryptString) throws InvalidKeySpecException
- Throws:
InvalidKeySpecException
-
parseUnixSHACryptPassword
private static Password parseUnixSHACryptPassword(char[] cryptString, int[] table, String algorithm) throws InvalidKeySpecException
- Throws:
InvalidKeySpecException
-
parseUnixMD5CryptPasswordString
private static Password parseUnixMD5CryptPasswordString(char[] cryptString) throws InvalidKeySpecException
- Throws:
InvalidKeySpecException
-
parseSunUnixMD5CryptPasswordString
private static Password parseSunUnixMD5CryptPasswordString(String algorithm, char[] cryptString) throws InvalidKeySpecException
- Throws:
InvalidKeySpecException
-
parseBCryptPasswordString
private static Password parseBCryptPasswordString(char[] cryptString) throws InvalidKeySpecException
- Throws:
InvalidKeySpecException
-
parseUnixDESCryptPasswordString
private static Password parseUnixDESCryptPasswordString(char[] cryptString) throws InvalidKeySpecException
- Throws:
InvalidKeySpecException
-
parseBSDUnixDESCryptPasswordString
private static Password parseBSDUnixDESCryptPasswordString(char[] cryptString) throws InvalidKeySpecException
- Throws:
InvalidKeySpecException
-
parseMaskedPasswordString
private static Password parseMaskedPasswordString(char[] chars) throws InvalidKeySpecException
- Throws:
InvalidKeySpecException
-
lastIndexOf
private static int lastIndexOf(char[] chars, char c)
-
createCryptBasedPassword
private static Password createCryptBasedPassword(byte[] userPassword) throws InvalidKeySpecException
- Throws:
InvalidKeySpecException
-
createBsdCryptBasedPassword
private static Password createBsdCryptBasedPassword(byte[] userPassword) throws InvalidKeySpecException
- Throws:
InvalidKeySpecException
-
composeCryptBasedPassword
private static void composeCryptBasedPassword(ByteArrayOutputStream out, UnixDESCryptPassword password) throws IOException
- Throws:
IOException
-
composeBsdCryptBasedPassword
private static void composeBsdCryptBasedPassword(ByteArrayOutputStream out, BSDUnixDESCryptPassword password) throws IOException
- Throws:
IOException
-
-