Package org.wso2.carbon.utils
Class Secret
java.lang.Object
org.wso2.carbon.utils.Secret
This class wraps a character array to be used to handle sensitive data like passwords.
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddChars(char[] chars) Adds the given character array to the existing character array of the secretvoidclear()Clears byte and character arrays of the secret.byte[]getBytes()Returns the secret as a byte array in UTF-8 formatbyte[]Returns the secret as a byte array for the given encoding formatchar[]getChars()Returns the secret as a character arraystatic SecretReturns an instance of a Secret for the given secret type.booleanisEmpty()Check if the character array of the secret is null or emptyvoidsetChars(char[] chars) Sets the given character array as the secret and clears the previous character array
-
Method Details
-
getChars
public char[] getChars()Returns the secret as a character array- Returns:
- char[]
-
getBytes
public byte[] getBytes()Returns the secret as a byte array in UTF-8 format- Returns:
- byte[]
-
getBytes
Returns the secret as a byte array for the given encoding format- Parameters:
charset- Character encoding format- Returns:
- byte[]
-
isEmpty
public boolean isEmpty()Check if the character array of the secret is null or empty- Returns:
- true if character array is null or empty, else return false
-
setChars
public void setChars(char[] chars) Sets the given character array as the secret and clears the previous character array- Parameters:
chars- character array of the secret
-
addChars
public void addChars(char[] chars) Adds the given character array to the existing character array of the secret- Parameters:
chars- character array to be added
-
clear
public void clear()Clears byte and character arrays of the secret. For each invocation of this method the internal counter which tracks the access count of the instance is decremented. Byte and character arrays are cleared if and only if the internal counter value is less than 0. For proper operation, this method should be invoked once, per each invocation of getSecret factory method. -
getSecret
Returns an instance of a Secret for the given secret type. Given secret type should be an instance of a Secret, char[] or a String. If the given secret is of Secret type the internal counter which tracks the access count of the instance is incremented. Thus, for proper operation once the instance of Secret is retrieved from this method and used, clear() method should be invoked to clear internal char and byte arrays.- Parameters:
secret- given secret. Supports only Secret, char[] or a String types- Returns:
- an instance of Secret
- Throws:
UnsupportedSecretTypeException- thrown if the given secret is not either a Secret, char[] or String
-