public final class EncryptionKey extends Object implements Serializable
Pointer to the an encryption key, or the encryption key itself. An encryption key can be seen as equivalent to a secret key, passphrase or password.
Because this class is immutable, it does not implement
IXMLConfigurable
directly, but static methods
saveToXML(XML, EncryptionKey)
and
loadFromXML(XML, EncryptionKey)
can be used instead.
The usage example below is for when used embedded in a parent configuration.
<value>(The actual key or reference to it.)</value>
<source>[key|file|environment|property]</source>
<size>(Size in bits of encryption key. Default is 128.)</size>
These XML configurable options can be nested in a parent tag of any name. The expected parent tag name is defined by the consuming classes.
<sampleKey>
<value>/path/to/my.key</value>
<source>file</source>
</sampleKey>
The above example has the encryption key configuration is nested in a
<passwordKey>
tag. It uses a key stored in a file to
decrypt a password for user credentials.
EncryptionUtil
,
Credentials
,
Serialized FormModifier and Type | Class and Description |
---|---|
static class |
EncryptionKey.Source |
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_KEY_SIZE |
Constructor and Description |
---|
EncryptionKey(String value)
Creates a new encryption key where the value is the actual key.
|
EncryptionKey(String value,
EncryptionKey.Source source)
Creates a new reference to an encryption key.
|
EncryptionKey(String value,
EncryptionKey.Source source,
int size)
Creates a new reference to an encryption key.
|
EncryptionKey(String value,
int size)
Creates a new encryption key where the value is the actual key, and the
number of key bits to generate is the size.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj) |
int |
getSize()
Gets the size in bits of the encryption key.
|
EncryptionKey.Source |
getSource() |
String |
getValue() |
int |
hashCode() |
static EncryptionKey |
loadFromXML(XML xml,
EncryptionKey defaultKey)
Gets an encryption key from an existing XML.
|
String |
resolve()
Locate the key according to its value type and return it.
|
static void |
saveToXML(XML xml,
EncryptionKey key)
Adds an encryption key to an existing XML.
|
String |
toString() |
public static final int DEFAULT_KEY_SIZE
public EncryptionKey(String value, EncryptionKey.Source source, int size)
value
- the encryption keysize
- the size in bits of the encryption keysource
- the type of valuepublic EncryptionKey(String value, EncryptionKey.Source source)
value
- the encryption keysource
- the type of valuepublic EncryptionKey(String value, int size)
value
- the encrption keysize
- the encryption key size in bitspublic EncryptionKey(String value)
value
- the encryption keypublic String getValue()
public EncryptionKey.Source getSource()
public int getSize()
public String resolve()
null
if the key does not exist
for the specified typepublic static EncryptionKey loadFromXML(XML xml, EncryptionKey defaultKey)
xml
- the XML to get the key fromdefaultKey
- default encryption key if it does not exist in XMLpublic static void saveToXML(XML xml, EncryptionKey key)
xml
- the XML to add the key tokey
- encryption keyCopyright © 2008–2023 Norconex Inc.. All rights reserved.