Package com.norconex.commons.lang.encrypt

# Class EncryptionKey

java.lang.Object
com.norconex.commons.lang.encrypt.EncryptionKey

All Implemented Interfaces:
  `Serializable`

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.

Since:
  1.9.0
See Also:
  - `EncryptionUtil`
  - `Credentials`
  - Serialized Form

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static enum`
  `EncryptionKey.Source`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `DEFAULT_KEY_SIZE`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `EncryptionKey(String value)`
  Creates a new encryption key where the value is the actual 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.
  `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.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `equals(Object o)`
  `int`
  `getSize()`
  Gets the size in bits of the encryption key.
  `EncryptionKey.Source`
  `getSource()`
  A pointer to the encryption key location, returned by `getValue()`.
  `String`
  `getValue()`
  The actual encryption key (when "source" is KEY) or a reference to the encryption key location (when "source" is something other than KEY).
  `int`
  `hashCode()`
  `String`
  `resolve()`
  Locate the key according to its value type and return it.
  `String`
  `toString()`

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### DEFAULT_KEY_SIZE

    public static final int DEFAULT_KEY_SIZE
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### EncryptionKey

    public EncryptionKey(String value, EncryptionKey.Source source, int size)
    Creates a new reference to an encryption key. The reference can either be the key itself, or a pointer to a file or environment variable containing the key (as defined by the supplied value type). The actual value can be any sort of string, and it is converted to an encryption key of length size using cryptographic algorithms. If the size is specified, it must be supported by your version of Java.
    Parameters:
      `value` - the encryption key
      `source` - the type of value
      `size` - the size in bits of the encryption key

  - ### EncryptionKey

    public EncryptionKey(String value, EncryptionKey.Source source)
    Creates a new reference to an encryption key. The reference can either be the key itself, or a pointer to a file or environment variable containing the key (as defined by the supplied value type).
    Parameters:
      `value` - the encryption key
      `source` - the type of value

  - ### EncryptionKey

    public 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.
    Parameters:
      `value` - the encrption key
      `size` - the encryption key size in bits

  - ### EncryptionKey

    public EncryptionKey(String value)
    Creates a new encryption key where the value is the actual key.
    Parameters:
      `value` - the encryption key

- ## Method Details

  - ### getValue

    public String getValue()
    The actual encryption key (when "source" is KEY) or a reference to the encryption key location (when "source" is something other than KEY).
    Returns:
      the encryption key or reference it

  - ### getSource

    public EncryptionKey.Source getSource()
    A pointer to the encryption key location, returned by `getValue()`.
    Returns:
      key source

  - ### getSize

    public int getSize()
    Gets the size in bits of the encryption key. Default is 256.
    Returns:
      size in bits of the encryption key
    Since:
      1.15.0

  - ### resolve

    public String resolve()
    Locate the key according to its value type and return it. This method will always resolve the value each type it is invoked and never caches the key, unless the key value specified at construction time is the actual key.
    Returns:
      encryption key or `null` if the key does not exist for the specified type

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`

  - ### equals

    public boolean equals(Object o)
    Overrides:
      `equals` in class `Object`

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Object`