public class PasswordUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
PROPERTY_CRYPTO_KEY
Constant that holds the name of the property for specifying the encryption algorithm for the encode and encode_password method.
|
static java.lang.String |
PROPERTY_HASH_ALGORITHM
Reserved for future use.
|
static java.lang.String |
PROPERTY_HASH_ENCODED
Reserved for future use.
|
static java.lang.String |
PROPERTY_HASH_ITERATION
Reserved for future use.
|
static java.lang.String |
PROPERTY_HASH_LENGTH
Reserved for future use.
|
static java.lang.String |
PROPERTY_HASH_SALT
Reserved for future use.
|
static java.lang.String |
PROPERTY_NO_TRIM
Constant that holds the name of the property for specifying whether the leading and trailing whitespace omitted
from the string for the encode and encode_password method.
|
Constructor and Description |
---|
PasswordUtil() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
decode(java.lang.String encoded_string)
Decode the provided string.
|
static java.lang.String |
encode_password(java.lang.String decoded_string,
java.lang.String crypto_algorithm,
java.util.Map<java.lang.String,java.lang.String> properties)
Encode the provided string by using the specified encoding algorithm and properties
|
static java.lang.String |
encode(java.lang.String decoded_string)
Encode the provided password by using the default encoding algorithm.
|
static java.lang.String |
encode(java.lang.String decoded_string,
java.lang.String crypto_algorithm)
Encode the provided password by using the specified encoding algorithm.
|
static java.lang.String |
encode(java.lang.String decoded_string,
java.lang.String crypto_algorithm,
java.util.Map<java.lang.String,java.lang.String> properties)
Encode the provided string with the specified algorithm and the properties
If the decoded_string is already encoded, the string will be decoded and then encoded by using the specified crypto algorithm.
|
static java.lang.String |
encode(java.lang.String decoded_string,
java.lang.String crypto_algorithm,
java.lang.String crypto_key)
Encode the provided string with the specified algorithm and the crypto key
If the decoded_string is already encoded, the string will be decoded and then encoded by using the specified crypto algorithm.
|
static java.lang.String |
getCryptoAlgorithm(java.lang.String password)
Return the crypto algorithm of the provided password.
|
static java.lang.String |
getCryptoAlgorithmTag(java.lang.String password)
Return the algorithm tag of the provided string.
|
static java.lang.String |
getDefaultEncoding()
Return the default algorithm for the encoding or decoding.
|
static boolean |
isEncrypted(java.lang.String encoded_string)
Check whether the encoded string contains a valid crypto algorithm.
|
static boolean |
isHashed(java.lang.String encoded_string)
Determine if the provided string is hashed by examining the algorithm tag.
|
static boolean |
isValidCryptoAlgorithm(java.lang.String crypto_algorithm)
Determine if the provided algorithm string is valid.
|
static boolean |
isValidCryptoAlgorithmTag(java.lang.String tag)
Determine if the provided algorithm tag is valid.
|
static java.lang.String |
passwordDecode(java.lang.String encoded_string)
Decode the provided string.
|
static java.lang.String |
passwordEncode(java.lang.String decoded_string)
Encode the provided password by using the default encoding algorithm.
|
static java.lang.String |
passwordEncode(java.lang.String decoded_string,
java.lang.String crypto_algorithm)
Encode the provided password with the algorithm.
|
static java.lang.String |
removeCryptoAlgorithmTag(java.lang.String password)
Remove the algorithm tag from the input encoded password.
|
public static final java.lang.String PROPERTY_CRYPTO_KEY
Constant that holds the name of the property for specifying the encryption algorithm for the encode and encode_password method.
public static final java.lang.String PROPERTY_NO_TRIM
Constant that holds the name of the property for specifying whether the leading and trailing whitespace omitted from the string for the encode and encode_password method. When the value is true, the whitespace will not be omitted. Otherwise, the whitespace will be omitted. The default value is false.
public static final java.lang.String PROPERTY_HASH_ALGORITHM
Reserved for future use.
public static final java.lang.String PROPERTY_HASH_ITERATION
Reserved for future use.
public static final java.lang.String PROPERTY_HASH_SALT
Reserved for future use.
public static final java.lang.String PROPERTY_HASH_ENCODED
Reserved for future use.
public static final java.lang.String PROPERTY_HASH_LENGTH
Reserved for future use.
public static final java.lang.String getDefaultEncoding()
public static java.lang.String decode(java.lang.String encoded_string) throws InvalidPasswordDecodingException, UnsupportedCryptoAlgorithmException
An empty algorithm "{}" is treated as not encoded. However, a missing algorithm will trigger the InvalidPasswordDecodingException.
encoded_string
- the string to be decoded.InvalidPasswordDecodingException
- If the encoded_string is null or invalid. Or the decoded_string is null.UnsupportedCryptoAlgorithmException
- If the specified algorithm is not supported for decoding.public static java.lang.String encode(java.lang.String decoded_string) throws InvalidPasswordEncodingException, UnsupportedCryptoAlgorithmException
decoded_string
- the string to be encoded.InvalidPasswordEncodingException
- If the decoded_string is null or invalid. Or the encoded_string is null.UnsupportedCryptoAlgorithmException
- If the algorithm is not supported.public static java.lang.String encode(java.lang.String decoded_string, java.lang.String crypto_algorithm) throws InvalidPasswordEncodingException, UnsupportedCryptoAlgorithmException
decoded_string
- the string to be encoded.crypto_algorithm
- the algorithm to be used for encoding. The supported values are xor, aes, or hash.InvalidPasswordEncodingException
- If the decoded_string is null or invalid. Or the encoded_string is null.UnsupportedCryptoAlgorithmException
- If the algorithm is not supported.public static java.lang.String encode(java.lang.String decoded_string, java.lang.String crypto_algorithm, java.lang.String crypto_key) throws InvalidPasswordEncodingException, UnsupportedCryptoAlgorithmException
decoded_string
- the string to be encoded.crypto_algorithm
- the algorithm to be used for encoding.crypto_key
- the key for the encryption. This value is only valid for aes algorithm.InvalidPasswordEncodingException
- If the decoded_string is null or invalid. Or the encoded_string is null.UnsupportedCryptoAlgorithmException
- If the algorithm is not supported.public static java.lang.String encode(java.lang.String decoded_string, java.lang.String crypto_algorithm, java.util.Map<java.lang.String,java.lang.String> properties) throws InvalidPasswordEncodingException, UnsupportedCryptoAlgorithmException
decoded_string
- the string to be encoded.crypto_algorithm
- the algorithm to be used for encoding. The supported values are xor, aes, or hash.properties
- the properties for the encryption.InvalidPasswordEncodingException
- If the decoded_string is null or invalid. Or the encoded_string is null.UnsupportedCryptoAlgorithmException
- If the algorithm is not supported.public static java.lang.String getCryptoAlgorithm(java.lang.String password)
password
- the encoded string with encoding algorithm.public static java.lang.String getCryptoAlgorithmTag(java.lang.String password)
password
- the encoded string with encoding algorithm.public static boolean isEncrypted(java.lang.String encoded_string)
encoded_string
- the encoded string.public static boolean isValidCryptoAlgorithm(java.lang.String crypto_algorithm)
crypto_algorithm
- the string of algorithm.public static boolean isValidCryptoAlgorithmTag(java.lang.String tag)
tag
- the string of algorithm tag to be examined.public static boolean isHashed(java.lang.String encoded_string)
encoded_string
- the string with the encoded algorithm tag.public static java.lang.String passwordDecode(java.lang.String encoded_string)
encoded_string
- the string to be decoded.public static java.lang.String passwordEncode(java.lang.String decoded_string)
decoded_string
- the string to be encoded.public static java.lang.String passwordEncode(java.lang.String decoded_string, java.lang.String crypto_algorithm)
decoded_string
- the string to be encoded, or the encoded string.crypto_algorithm
- the algorithm to be used for encoding. The supported values are xor, aes, or hash.public static java.lang.String removeCryptoAlgorithmTag(java.lang.String password)
password
- the string which contains the crypto algorithm tag.public static java.lang.String encode_password(java.lang.String decoded_string, java.lang.String crypto_algorithm, java.util.Map<java.lang.String,java.lang.String> properties)
decoded_string
- the string to be encoded.crypto_algorithm
- the algorithm to be used for encoding. The supported values are xor, aes, or hash.properties
- the properties for the encryption.