Class PasswordUtil
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringConstant that holds the name of the property for specifying the encryption algorithm for the encode and encode_password method.static final StringReserved for future use.static final StringReserved for future use.static final StringReserved for future use.static final StringReserved for future use.static final StringReserved for future use.static final StringConstant that holds the name of the property for specifying the label for the encryption key stored in the keyring.static final StringConstant that holds the name of the property for specifying keyring where the encryption key is stored.static final StringConstant that holds the name of the property for secifying the type of the keyring where the encryption key is stored.static final StringConstant 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 SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic StringDecode the provided string.static StringEncode the provided password by using the default encoding algorithm.static StringEncode the provided password by using the specified encoding algorithm.static StringEncode 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 StringEncode 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 StringEncode the provided string by using the specified encoding algorithm and propertiesstatic StringgetCryptoAlgorithm(String password) Return the crypto algorithm of the provided password.static StringgetCryptoAlgorithmTag(String password) Return the algorithm tag of the provided string.static final StringReturn the default algorithm for the encoding or decoding.static booleanisEncrypted(String encoded_string) Check whether the encoded string contains a valid crypto algorithm.static booleanDetermine if the provided string is hashed by examining the algorithm tag.static booleanisValidCryptoAlgorithm(String crypto_algorithm) Determine if the provided algorithm string is valid.static booleanDetermine if the provided algorithm tag is valid.static StringpasswordDecode(String encoded_string) Decode the provided string.static StringpasswordEncode(String decoded_string) Encode the provided password by using the default encoding algorithm.static StringpasswordEncode(String decoded_string, String crypto_algorithm) Encode the provided password with the algorithm.static StringremoveCryptoAlgorithmTag(String password) Remove the algorithm tag from the input encoded password.
- 
Field Details- 
PROPERTY_CRYPTO_KEYConstant that holds the name of the property for specifying the encryption algorithm for the encode and encode_password method. - See Also:
 
- 
PROPERTY_NO_TRIMConstant 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. - See Also:
 
- 
PROPERTY_HASH_ALGORITHMReserved for future use. - See Also:
 
- 
PROPERTY_HASH_ITERATIONReserved for future use. - See Also:
 
- 
PROPERTY_HASH_SALTReserved for future use. - See Also:
 
- 
PROPERTY_HASH_ENCODEDReserved for future use. - See Also:
 
- 
PROPERTY_HASH_LENGTHReserved for future use. - See Also:
 
- 
PROPERTY_KEYRINGConstant that holds the name of the property for specifying keyring where the encryption key is stored. - See Also:
 
- 
PROPERTY_KEYRING_TYPEConstant that holds the name of the property for secifying the type of the keyring where the encryption key is stored. - See Also:
 
- 
PROPERTY_KEY_LABELConstant that holds the name of the property for specifying the label for the encryption key stored in the keyring. - See Also:
 
 
- 
- 
Constructor Details- 
PasswordUtilpublic PasswordUtil()
 
- 
- 
Method Details- 
getDefaultEncodingReturn the default algorithm for the encoding or decoding.- Returns:
- The default algorithm.
 
- 
decodepublic static String decode(String encoded_string) throws InvalidPasswordDecodingException, UnsupportedCryptoAlgorithmException Decode the provided string. The string should consist of the algorithm to be used for decoding and encoded string. For example, {xor}CDo9Hgw=. Use this method unless the encryption key needs to be specified for the AES encryption.An empty algorithm "{}" is treated as not encoded. However, a missing algorithm will trigger the InvalidPasswordDecodingException. - Parameters:
- encoded_string- the string to be decoded.
- Returns:
- The decoded string
- Throws:
- 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.
 
- 
encodepublic static String encode(String decoded_string) throws InvalidPasswordEncodingException, UnsupportedCryptoAlgorithmException Encode the provided password by using the default encoding algorithm. The encoded string consists of the algorithm of the encoding and the encoded value. For example, {xor}CDo9Hgw=. If the decoded_string is already encoded, the string will be decoded and then encoded by using the default encoding algorithm. Use this method for encoding the string by using the default encoding algorithm.- Parameters:
- decoded_string- the string to be encoded.
- Returns:
- The encoded string.
- Throws:
- InvalidPasswordEncodingException- If the decoded_string is null or invalid. Or the encoded_string is null.
- UnsupportedCryptoAlgorithmException- If the algorithm is not supported.
 
- 
encodepublic static String encode(String decoded_string, String crypto_algorithm) throws InvalidPasswordEncodingException, UnsupportedCryptoAlgorithmException Encode the provided password by using the specified encoding algorithm. The encoded string consistes of the algorithm of the encoding and the encoded value. If the decoded_string is already encoded, the string will be decoded and then encoded by using the specified crypto algorithm. Use this method for encoding the string by using specific encoding algorithm. Use securityUtility encode --listCustom command line utility to see if any additional custom encryptions are supported.- Parameters:
- decoded_string- the string to be encoded.
- crypto_algorithm- the algorithm to be used for encoding. The supported values are xor, aes, or hash.
- Returns:
- The encoded string.
- Throws:
- InvalidPasswordEncodingException- If the decoded_string is null or invalid. Or the encoded_string is null.
- UnsupportedCryptoAlgorithmException- If the algorithm is not supported.
 
- 
encodepublic static String encode(String decoded_string, String crypto_algorithm, String crypto_key) throws InvalidPasswordEncodingException, UnsupportedCryptoAlgorithmException 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. Use this method for encoding the string by using the AES encryption with the specific crypto key. Note that this method is only avaiable for the Liberty profile.- Parameters:
- 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.
- Returns:
- The encoded string.
- Throws:
- InvalidPasswordEncodingException- If the decoded_string is null or invalid. Or the encoded_string is null.
- UnsupportedCryptoAlgorithmException- If the algorithm is not supported.
 
- 
encodepublic static String encode(String decoded_string, String crypto_algorithm, Map<String, String> properties) throws InvalidPasswordEncodingException, UnsupportedCryptoAlgorithmExceptionEncode 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. Note that this method is only avaiable for the Liberty profile.- Parameters:
- 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.
- Returns:
- The encoded string.
- Throws:
- InvalidPasswordEncodingException- If the decoded_string is null or invalid. Or the encoded_string is null.
- UnsupportedCryptoAlgorithmException- If the algorithm is not supported.
 
- 
getCryptoAlgorithmReturn the crypto algorithm of the provided password. For example, if the password is {xor}CDo9Hgw=, "xor" will be returned.- Parameters:
- password- the encoded string with encoding algorithm.
- Returns:
- The encoding algorithm. Null if not present.
 
- 
getCryptoAlgorithmTagReturn the algorithm tag of the provided string. For example, if the password is {xor}CDo9Hgw=, "{xor}" will be returned.- Parameters:
- password- the encoded string with encoding algorithm.
- Returns:
- The encoding algorithm with algorithm tags. Null if not present.
 
- 
isEncryptedCheck whether the encoded string contains a valid crypto algorithm. For example, "{xor}CDo9Hgw=" returns true, while "{unknown}CDo9Hgw=" or "CDo9Hgw=" returns false.- Parameters:
- encoded_string- the encoded string.
- Returns:
- true if the encoding algorithm is supported.
 
- 
isValidCryptoAlgorithmDetermine if the provided algorithm string is valid. The valid values are xor, aes, or hash. Use securityUtility encode --listCustom command line utility to see if any additional custom encryptions are supported.- Parameters:
- crypto_algorithm- the string of algorithm.
- Returns:
- true if the algorithm is supported. false otherwise.
 
- 
isValidCryptoAlgorithmTagDetermine if the provided algorithm tag is valid. the algorithm tag consists of "{}" such as "{xor}". The valid values are {xor}, {aes}, or {hash}. Use securityUtility encode --listCustom command line utility to see if any additional custom encryptions are supported. - Parameters:
- tag- the string of algorithm tag to be examined.
- Returns:
- true if the algorithm is supported. false otherwise.
 
- 
isHashedDetermine if the provided string is hashed by examining the algorithm tag. Note that this method is only avaiable for the Liberty profile.- Parameters:
- encoded_string- the string with the encoded algorithm tag.
- Returns:
- true if the encoded algorithm is hash. false otherwise.
 
- 
passwordDecodeDecode the provided string. The string should consist of the algorithm to be used for decoding and encoded string. For example, {xor}CDo9Hgw=.- Parameters:
- encoded_string- the string to be decoded.
- Returns:
- The decoded string, null if there is any failure during decoding, or invalid or null encoded_string.
 
- 
passwordEncodeEncode the provided password by using the default encoding algorithm. The encoded string consists of the algorithm of the encoding and the encoded value. For example, {xor}CDo9Hgw=.- Parameters:
- decoded_string- the string to be encoded.
- Returns:
- The encoded string. null if there is any failure during encoding, or invalid or null decoded_string
 
- 
passwordEncodeEncode the provided password with the algorithm. If another algorithm is already applied, it will be removed and replaced with the new algorithm.- Parameters:
- 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.
- Returns:
- The encoded string. Null if there is any failure during encoding, or invalid or null decoded_string
 
- 
removeCryptoAlgorithmTagRemove the algorithm tag from the input encoded password.- Parameters:
- password- the string which contains the crypto algorithm tag.
- Returns:
- The string which the crypto algorithm tag is removed.
 
- 
encode_passwordpublic static String encode_password(String decoded_string, String crypto_algorithm, Map<String, String> properties) Encode the provided string by using the specified encoding algorithm and properties- Parameters:
- 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.
- Returns:
- The encoded string. null if there is any failure during encoding, or invalid or null decoded_string
 
 
-