public class DefaultEncryptedProperties extends Object implements EncryptedProperties
EncryptedProperties
interface. This
implementation wraps a normal properties file, and creates surrogates for the
getProperty
and setProperty
methods that perform encryption
and decryption based on Encryptor
.
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.
EncryptedProperties
,
ReferenceEncryptedProperties
Constructor and Description |
---|
DefaultEncryptedProperties()
Instantiates a new encrypted properties.
|
Modifier and Type | Method and Description |
---|---|
String |
getProperty(String key)
Gets the property value from the encrypted store, decrypts it, and
returns the plaintext value to the caller.
|
Set<?> |
keySet()
Returns a
Set view of properties. |
void |
load(InputStream in)
Reads a property list (key and element pairs) from the input stream.
|
static void |
main(String[] args)
Deprecated.
Use
EncryptedPropertiesUtils instead, which allows creating, reading,
and writing encrypted properties. main method will be removed in a
future release. |
String |
setProperty(String key,
String value)
Encrypts the plaintext property value and stores the ciphertext value
in the encrypted store.
|
void |
store(OutputStream out,
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.
|
public DefaultEncryptedProperties()
public String getProperty(String key) throws EncryptionException
getProperty
in interface EncryptedProperties
key
- the name of the property to getEncryptionException
- if the property could not be decryptedpublic String setProperty(String key, String value) throws EncryptionException
setProperty
in interface EncryptedProperties
key
- the name of the property to setvalue
- the value of the property to setnull
if it did not have one.EncryptionException
- if the property could not be encryptedpublic Set<?> keySet()
Set
view of properties. The Set
is backed by a
java.util.Hashtable
, so changes to the Hashtable
are
reflected in the Set
, and vice-versa. The Set
supports element
removal (which removes the corresponding entry from the Hashtable
,
but not element addition.keySet
in interface EncryptedProperties
public void load(InputStream in) throws IOException
load
in interface EncryptedProperties
in
- the input stream that contains the properties fileIOException
- Signals that an I/O exception has occurred.public void store(OutputStream out, String comments) throws IOException
store
in interface EncryptedProperties
out
- the output stream that contains the properties filecomments
- a description of the property list (ex. "Encrypted Properties File").IOException
- Signals that an I/O exception has occurred.@Deprecated public static void main(String[] args) throws Exception
EncryptedPropertiesUtils
instead, which allows creating, reading,
and writing encrypted properties. main
method will be removed in a
future release.args
- the location of the properties file to load and write toException
- Any exception thrownCopyright © 2022 The Open Web Application Security Project (OWASP). All rights reserved.