Class EncryptableProperties
- All Implemented Interfaces:
Serializable, Cloneable, Map<Object,Object>
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:
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final Integerprivate static final longprivate StringEncryptorprivate TextEncryptorFields inherited from class Properties
defaults -
Constructor Summary
ConstructorsConstructorDescriptionEncryptableProperties(Properties defaults, StringEncryptor stringEncryptor) Creates an EncryptableProperties instance which will use the passedStringEncryptorobject to decrypt encrypted values, and the passed defaults as default values (may contain encrypted values).EncryptableProperties(Properties defaults, TextEncryptor textEncryptor) Creates an EncryptableProperties instance which will use the passedTextEncryptorobject to decrypt encrypted values, and the passed defaults as default values (may contain encrypted values).EncryptableProperties(StringEncryptor stringEncryptor) Creates an EncryptableProperties instance which will use the passedStringEncryptorobject to decrypt encrypted values.EncryptableProperties(TextEncryptor textEncryptor) Creates an EncryptableProperties instance which will use the passedTextEncryptorobject to decrypt encrypted values. -
Method Summary
Modifier and TypeMethodDescriptionprivate StringObtains the property value for the specified key (see), decrypting it if needed.invalid reference
Hashtable#get(Object)(package private) IntegergetIdent()getProperty(String key) Obtains the property value for the specified key (seeProperties.getProperty(String)), decrypting it if needed.getProperty(String key, String defaultValue) Obtains the property value for the specified key (seeProperties.getProperty(String)), decrypting it if needed.private voidprivate voidwriteObject(ObjectOutputStream outputStream) Methods inherited from class Properties
clear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, getOrDefault, hashCode, isEmpty, keys, keySet, list, list, load, load, loadFromXML, merge, propertyNames, put, putAll, putIfAbsent, rehash, remove, remove, replace, replace, replaceAll, save, setProperty, size, store, store, storeToXML, storeToXML, storeToXML, stringPropertyNames, toString, values
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
ident
-
stringEncryptor
-
textEncryptor
-
-
Constructor Details
-
EncryptableProperties
Creates an EncryptableProperties instance which will use the passed
StringEncryptorobject to decrypt encrypted values.- Parameters:
stringEncryptor- theStringEncryptorto be used do decrypt values. It can not be null.
-
EncryptableProperties
Creates an EncryptableProperties instance which will use the passed
TextEncryptorobject to decrypt encrypted values.- Parameters:
textEncryptor- theTextEncryptorto be used do decrypt values. It can not be null.
-
EncryptableProperties
Creates an EncryptableProperties instance which will use the passed
StringEncryptorobject 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- theStringEncryptorto be used do decrypt values. It can not be null.
-
EncryptableProperties
Creates an EncryptableProperties instance which will use the passed
TextEncryptorobject 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- theTextEncryptorto be used do decrypt values. It can not be null.
-
-
Method Details
-
getProperty
Obtains the property value for the specified key (see
Properties.getProperty(String)), decrypting it if needed.- Overrides:
getPropertyin classProperties- Parameters:
key- the property key- Returns:
- the (decrypted) value
-
getProperty
Obtains the property value for the specified key (see
Properties.getProperty(String)), decrypting it if needed.If no value is found for the specified key, the default value will be returned (decrypted if needed).
- Overrides:
getPropertyin classProperties- Parameters:
key- the property keydefaultValue- the default value to return- Returns:
- the (decrypted) value
-
get
Obtains the property value for the specified key (see
), decrypting it if needed.invalid reference
Hashtable#get(Object) -
getIdent
Integer getIdent() -
decode
-
readObject
- Throws:
IOExceptionClassNotFoundException
-
writeObject
- Throws:
IOException
-