Package org.owasp.esapi.reference.crypto
Class DefaultEncryptedProperties
- java.lang.Object
-
- org.owasp.esapi.reference.crypto.DefaultEncryptedProperties
-
- All Implemented Interfaces:
EncryptedProperties
public class DefaultEncryptedProperties extends java.lang.Object implements EncryptedProperties
Reference implementation of theEncryptedProperties
interface. This implementation wraps a normal properties file, and creates surrogates for thegetProperty
andsetProperty
methods that perform encryption and decryption based onEncryptor
.A very simple main program is provided that can be used to create an encrypted properties file. A better approach would be to allow unencrypted properties in the file and to encrypt them the first time the file is accessed.
- Since:
- June 1, 2007
- Author:
- Jeff Williams (jeff.williams .at. aspectsecurity.com) Aspect Security, kevin.w.wall@gmail.com
- See Also:
EncryptedProperties
,ReferenceEncryptedProperties
-
-
Constructor Summary
Constructors Constructor Description DefaultEncryptedProperties()
Instantiates a new encrypted properties.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.lang.String
getProperty(java.lang.String key)
Gets the property value from the encrypted store, decrypts it, and returns the plaintext value to the caller.java.util.Set<?>
keySet()
Returns aSet
view of properties.void
load(java.io.InputStream in)
Reads a property list (key and element pairs) from the input stream.static void
main(java.lang.String[] args)
Deprecated.UseEncryptedPropertiesUtils
instead, which allows creating, reading, and writing encrypted properties.java.lang.String
setProperty(java.lang.String key, java.lang.String value)
Encrypts the plaintext property value and stores the ciphertext value in the encrypted store.void
store(java.io.OutputStream out, java.lang.String comments)
Writes this property list (key and element pairs) in this Properties table to the output stream in a format suitable for loading into a Properties table using the load method.
-
-
-
Method Detail
-
getProperty
public java.lang.String getProperty(java.lang.String key) throws EncryptionException
Gets the property value from the encrypted store, decrypts it, and returns the plaintext value to the caller.- Specified by:
getProperty
in interfaceEncryptedProperties
- Parameters:
key
- the name of the property to get- Returns:
- The decrypted property value. null if the key is not set.
- Throws:
EncryptionException
- if the property could not be decrypted
-
setProperty
public java.lang.String setProperty(java.lang.String key, java.lang.String value) throws EncryptionException
Encrypts the plaintext property value and stores the ciphertext value in the encrypted store.- Specified by:
setProperty
in interfaceEncryptedProperties
- Parameters:
key
- the name of the property to setvalue
- the value of the property to set- Returns:
- the previously encrypted property value for the specified key, or
null
if it did not have one. - Throws:
EncryptionException
- if the property could not be encrypted
-
keySet
public java.util.Set<?> keySet()
Returns aSet
view of properties. TheSet
is backed by ajava.util.Hashtable
, so changes to theHashtable
are reflected in theSet
, and vice-versa. TheSet
supports element removal (which removes the corresponding entry from theHashtable
, but not element addition.- Specified by:
keySet
in interfaceEncryptedProperties
- Returns:
- a set view of the properties contained in this map.
-
load
public void load(java.io.InputStream in) throws java.io.IOException
Reads a property list (key and element pairs) from the input stream.- Specified by:
load
in interfaceEncryptedProperties
- Parameters:
in
- the input stream that contains the properties file- Throws:
java.io.IOException
- Signals that an I/O exception has occurred.
-
store
public void store(java.io.OutputStream out, java.lang.String comments) throws java.io.IOException
Writes this property list (key and element pairs) in this Properties table to the output stream in a format suitable for loading into a Properties table using the load method.- Specified by:
store
in interfaceEncryptedProperties
- Parameters:
out
- the output stream that contains the properties filecomments
- a description of the property list (ex. "Encrypted Properties File").- Throws:
java.io.IOException
- Signals that an I/O exception has occurred.
-
main
@Deprecated public static void main(java.lang.String[] args) throws java.lang.Exception
Deprecated.UseEncryptedPropertiesUtils
instead, which allows creating, reading, and writing encrypted properties.main
method will be removed in a future release.Loads encrypted properties file based on the location passed in args then prompts the user to input key-value pairs. When the user enters a null or blank key, the values are stored to the properties file.- Parameters:
args
- the location of the properties file to load and write to- Throws:
java.lang.Exception
- Any exception thrown
-
-