Class EncryptableProperties

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

public final class EncryptableProperties extends Properties

Subclass of java.util.Properties which can make use of a StringEncryptor or TextEncryptor object to decrypt property values if they are encrypted in the .properties file.

A value is considered "encrypted" when it appears surrounded by ENC(...), like:

my.value=ENC(!"DGAS24FaIO$)

Decryption is performed on-the-fly when the getProperty(String) or getProperty(String, String) methods are called, and only these two methods perform decryption (note that neither get(Object) nor Properties.toString() do). Load and store operations are not affected by decryption in any manner.

Encrypted and unencrypted objects can be combined in the same properties file.

Please note that, altough objects of this class are Serializable, they cannot be serialized and then de-serialized in different classloaders or virtual machines. This is so because encryptors are not serializable themselves (they cannot, as they contain sensitive information) and so they remain in memory, and live for as long as the classloader lives.

Since:
1.4
See Also:
  • Field Details

  • Constructor Details

    • EncryptableProperties

      public EncryptableProperties(StringEncryptor stringEncryptor)

      Creates an EncryptableProperties instance which will use the passed StringEncryptor object to decrypt encrypted values.

      Parameters:
      stringEncryptor - the StringEncryptor to be used do decrypt values. It can not be null.
    • EncryptableProperties

      public EncryptableProperties(TextEncryptor textEncryptor)

      Creates an EncryptableProperties instance which will use the passed TextEncryptor object to decrypt encrypted values.

      Parameters:
      textEncryptor - the TextEncryptor to be used do decrypt values. It can not be null.
    • EncryptableProperties

      public EncryptableProperties(Properties defaults, StringEncryptor stringEncryptor)

      Creates an EncryptableProperties instance which will use the passed StringEncryptor object to decrypt encrypted values, and the passed defaults as default values (may contain encrypted values).

      Parameters:
      defaults - default values for properties (may be encrypted).
      stringEncryptor - the StringEncryptor to be used do decrypt values. It can not be null.
    • EncryptableProperties

      public EncryptableProperties(Properties defaults, TextEncryptor textEncryptor)

      Creates an EncryptableProperties instance which will use the passed TextEncryptor object to decrypt encrypted values, and the passed defaults as default values (may contain encrypted values).

      Parameters:
      defaults - default values for properties (may be encrypted).
      textEncryptor - the TextEncryptor to be used do decrypt values. It can not be null.
  • Method Details