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 classModularCrypt.ModCryptBase64Alphabet
-
Field Summary
Fields Modifier and Type Field Description private static intA_APACHE_HTDIGESTprivate static intA_BCRYPTprivate static intA_BSD_CRYPT_DESprivate static intA_BSD_NT_HASHprivate static intA_CRYPT_DESprivate static intA_CRYPT_MD5private static intA_CRYPT_SHA_256private static intA_CRYPT_SHA_512private static intA_MASKEDprivate static intA_SUN_CRYPT_MD5private static intA_SUN_CRYPT_MD5_BARE_SALT(package private) static org.wildfly.common.codec.Base64AlphabetBCRYPTThe BCrypt alphabet.private static int[]MD5_IDXprivate static int[]MD5_IDX_REV(package private) static org.wildfly.common.codec.Base64AlphabetMOD_CRYPTThe modular crypt alphabet, used in various modular crypt password types.(package private) static org.wildfly.common.codec.Base64AlphabetMOD_CRYPT_LEThe modular crypt alphabet, used in various modular crypt password types.private static int[]SHA_256_IDXprivate static int[]SHA_256_IDX_REVprivate static int[]SHA_512_IDXprivate static int[]SHA_512_IDX_REV
-
Constructor Summary
Constructors Modifier Constructor Description privateModularCrypt()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static voidcomposeBsdCryptBasedPassword(ByteArrayOutputStream out, BSDUnixDESCryptPassword password)private static voidcomposeCryptBasedPassword(ByteArrayOutputStream out, UnixDESCryptPassword password)static voidcomposePassword(ByteArrayOutputStream out, Password password)private static PasswordcreateBsdCryptBasedPassword(byte[] userPassword)private static PasswordcreateCryptBasedPassword(byte[] userPassword)static PasswordcreatePassword(byte[] password, String algorithm)static Passworddecode(char[] cryptString)Decode the given char array and creates aPasswordinstance.static Passworddecode(String cryptString)Decode the given string and creates aPasswordinstance.private static intdoIdentifyAlgorithm(char[] chars)static char[]encode(Password password)Encode the givenPasswordto a char array.static StringencodeAsString(Password password)Encode the givenPasswordto a string.private static StringgetAlgorithmNameString(int id)private static StringBuildergetCryptStringToBuilder(Password password)static StringidentifyAlgorithm(char[] chars)Attempt to identify the algorithm used by the given crypt string password.private static int[]inverse(int[] orig)private static intlastIndexOf(char[] chars, char c)private static PasswordparseBCryptPasswordString(char[] cryptString)private static PasswordparseBSDUnixDESCryptPasswordString(char[] cryptString)private static PasswordparseMaskedPasswordString(char[] chars)private static intparseModCryptIterationCount(org.wildfly.common.iteration.CodePointIterator reader, int minIterations, int maxIterations, int defaultIterations)private static PasswordparseSunUnixMD5CryptPasswordString(String algorithm, char[] cryptString)private static PasswordparseUnixDESCryptPasswordString(char[] cryptString)private static PasswordparseUnixMD5CryptPasswordString(char[] cryptString)private static PasswordparseUnixSHA256CryptPasswordString(char[] cryptString)private static PasswordparseUnixSHA512CryptPasswordString(char[] cryptString)private static PasswordparseUnixSHACryptPassword(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
nullif no algorithm could be guessed
-
getAlgorithmNameString
private static String getAlgorithmNameString(int id)
-
encode
public static char[] encode(Password password) throws InvalidKeySpecException
Encode the givenPasswordto 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 givenPasswordto 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 aPasswordinstance.- Parameters:
cryptString- the string representing the encoded format of the password- Returns:
- a
Passwordinstance 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 aPasswordinstance.- Parameters:
cryptString- the char array representing the encoded format of the password- Returns:
- a
Passwordinstance 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
-
-