Class EncryptedProperties

All Implemented Interfaces:
Serializable, Cloneable, Map<Object,Object>

public class EncryptedProperties extends Properties
Encrypted Properties.
If a value starts with a ~ (tilde), the remainder of the string is considered to be encrypted by the application-specific Cryptor. If an unencrypted value starts with a ~, it must be escaped with a backslash.
See Also:
  • Constructor Details

    • EncryptedProperties

      public EncryptedProperties()
      Creates an empty property list with no default values.
    • EncryptedProperties

      public EncryptedProperties(int initialCapacity)
      Creates an empty property list with no default values, and with an initial size accommodating the specified number of elements without the need to dynamically resize.
      Parameters:
      initialCapacity - the EncryptedProperties will be sized to accommodate this many elements
      Throws:
      IllegalArgumentException - if the initial capacity is less than zero.
    • EncryptedProperties

      public EncryptedProperties(Properties defaults)
      Creates an empty property list with the specified defaults.
      Parameters:
      defaults - the defaults.
  • Method Details

    • clone

      public EncryptedProperties clone()
      Overrides:
      clone in class Properties
    • getName

      public String getName()
      Gets the optional name of the properties.
      Returns:
      the name
    • setName

      public void setName(String name)
      Sets the optional name of the properties.
      The name can be used to express the source, for example the name of a properties file.
      Parameters:
      name - the name
    • getKeyPrefix

      public String getKeyPrefix()
      Gets the key prefix.
      Returns:
      the prefix, null if none (default)
    • setKeyPrefix

      public void setKeyPrefix(String keyPrefix)
      Sets a key prefix.
      The prefix is prepended to the key for getProperty(String) and alike. This allows merging the properties with others (such as spring's application.properties) and avoid duplicates.
      Notice that all low-level methods of Hashtable dealing with objects rather than strings ignore the prefix.
      Parameters:
      keyPrefix - the prefix, null if none
    • getProperty

      public String getProperty(String key)
      Searches for the property with the specified key in this property list.
      If the key is not found in this property list, the default property list, and its defaults, recursively, are then checked. The method returns null if the property is not found.

      If the property is encrypted, it will be returned decrypted.

      Overrides:
      getProperty in class Properties
      Parameters:
      key - the property key
      Returns:
      the value in this property list with the specified key value
      See Also:
    • setProperty

      public Object setProperty(String key, String value)
      Overrides:
      setProperty in class Properties
    • stringPropertyNames

      public Set<String> stringPropertyNames()
      Same as Properties.stringPropertyNames() but returns only those keys that belong to the keyPrefix space, if set.
      Overrides:
      stringPropertyNames in class Properties
      Returns:
      unmodifiable set of keys
    • getPropertyBlunt

      public String getPropertyBlunt(String key)
      Gets the original value of the property.
      If the value is encrypted, the encrypted value will be returned.
      Parameters:
      key - the property key
      Returns:
      the value, null if no such key
    • getPropertyAsChars

      public char[] getPropertyAsChars(String key)
      Gets the property as a character array.
      Same as getProperty(String), but returns an array. In case the value was encrypted, the decrypted array can be erased by the application after use.
      Parameters:
      key - the property key
      Returns:
      the value as a character array or null if no such key
    • getPropertyAsChars

      public char[] getPropertyAsChars(String key, char[] defaults)
      Gets the property as a character array with a default value.
      Parameters:
      key - the property key
      defaults - the default value
      Returns:
      the value as a character array or null if no such key
    • setEncryptedProperty

      public void setEncryptedProperty(String key, String value)
      Sets the property string and stores it encrypted, if a Cryptor is available.
      Parameters:
      key - the property key
      value - the unencrypted value
    • setEncryptedProperty

      public void setEncryptedProperty(String key, char[] value)
      Sets the property char array and stores it encrypted, if a Cryptor is available.
      Parameters:
      key - the property key
      value - the unencrypted value