Package com.ibm.websphere.crypto
Class PasswordUtil
- java.lang.Object
-
- com.ibm.websphere.crypto.PasswordUtil
-
public class PasswordUtil extends java.lang.Object
Password related utilities.
-
-
Field Summary
Fields Modifier and Type Field 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 Summary
Constructors Constructor Description PasswordUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
decode(java.lang.String encoded_string)
Decode the provided string.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.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
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_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 propertiesstatic 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.
-
-
-
Field Detail
-
PROPERTY_CRYPTO_KEY
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.
- See Also:
- Constant Field Values
-
PROPERTY_NO_TRIM
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.
- See Also:
- Constant Field Values
-
PROPERTY_HASH_ALGORITHM
public static final java.lang.String PROPERTY_HASH_ALGORITHM
Reserved for future use.
- See Also:
- Constant Field Values
-
PROPERTY_HASH_ITERATION
public static final java.lang.String PROPERTY_HASH_ITERATION
Reserved for future use.
- See Also:
- Constant Field Values
-
PROPERTY_HASH_SALT
public static final java.lang.String PROPERTY_HASH_SALT
Reserved for future use.
- See Also:
- Constant Field Values
-
PROPERTY_HASH_ENCODED
public static final java.lang.String PROPERTY_HASH_ENCODED
Reserved for future use.
- See Also:
- Constant Field Values
-
PROPERTY_HASH_LENGTH
public static final java.lang.String PROPERTY_HASH_LENGTH
Reserved for future use.
- See Also:
- Constant Field Values
-
-
Method Detail
-
getDefaultEncoding
public static final java.lang.String getDefaultEncoding()
Return the default algorithm for the encoding or decoding.- Returns:
- The default algorithm.
-
decode
public static java.lang.String decode(java.lang.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.
-
encode
public static java.lang.String encode(java.lang.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.
-
encode
public static java.lang.String encode(java.lang.String decoded_string, java.lang.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.
-
encode
public static java.lang.String encode(java.lang.String decoded_string, java.lang.String crypto_algorithm, java.lang.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.
-
encode
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
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. 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.
-
getCryptoAlgorithm
public static java.lang.String getCryptoAlgorithm(java.lang.String password)
Return 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.
-
getCryptoAlgorithmTag
public static java.lang.String getCryptoAlgorithmTag(java.lang.String password)
Return 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.
-
isEncrypted
public static boolean isEncrypted(java.lang.String encoded_string)
Check 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.
-
isValidCryptoAlgorithm
public static boolean isValidCryptoAlgorithm(java.lang.String crypto_algorithm)
Determine 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.
-
isValidCryptoAlgorithmTag
public static boolean isValidCryptoAlgorithmTag(java.lang.String tag)
Determine 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.
-
isHashed
public static boolean isHashed(java.lang.String encoded_string)
Determine 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.
-
passwordDecode
public static java.lang.String passwordDecode(java.lang.String encoded_string)
Decode 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.
-
passwordEncode
public static java.lang.String passwordEncode(java.lang.String decoded_string)
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=.- 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
-
passwordEncode
public static java.lang.String passwordEncode(java.lang.String decoded_string, java.lang.String crypto_algorithm)
Encode 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
-
removeCryptoAlgorithmTag
public static java.lang.String removeCryptoAlgorithmTag(java.lang.String password)
Remove 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_password
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)
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
-
-