Package com.norconex.commons.lang.encrypt

# Class EncryptionUtil

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

public class EncryptionUtil extends Object

Simplified encryption and decryption methods using the Advanced Encryption Standard (AES) (since 1.15.0) with a supplied encryption key (which you can also think of as a passphrase, or password).

The "salt" and iteration count used by this class are hard-coded. To use a different encryption or have more control over its creation, you should rely on another implementation or create your own.

To use on the command prompt, use the following command to print usage options:

     java -cp norconex-commons-lang-[version].jar com.norconex.commons.lang.encrypt.EncryptionUtil

For example, to use a encryption key store in a file to encrypt some text, add the following arguments to the above command:

     <above_command> encrypt -f "/path/to/key.txt" "Encrypt this text"

As of 1.13.0, you can also use the `encrypt.[sh|bat]` and `decrypt.[sh|bat]` files distributed with this library.

Since:
  1.9.0

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static String`
  `decrypt(String encryptedText, EncryptionKey encryptionKey)`
  Decrypts the given encrypted text with the encryption key supplied.
  `static String`
  `decryptPassword(Credentials credentials)`
  Decrypts the given credentials password.
  `static String`
  `encrypt(String textToEncrypt, EncryptionKey encryptionKey)`
  Encrypts the given text with the encryption key supplied.
  `static void`
  `main(String[] args)`

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

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### main

    public static void main(String[] args)

  - ### encrypt

    public static String encrypt(String textToEncrypt, EncryptionKey encryptionKey)

    Encrypts the given text with the encryption key supplied. If the encryption key is `null` or resolves to blank key, the text to encrypt will be returned unmodified.

    Parameters:
      `textToEncrypt` - text to be encrypted
      `encryptionKey` - encryption key which must resolve to the same value to encrypt and decrypt the supplied text.
    Returns:
      encrypted text or `null` if `textToEncrypt` is `null`.

  - ### decryptPassword

    public static String decryptPassword(Credentials credentials)

    Decrypts the given credentials password.

    Parameters:
      `credentials` - credentials from which to decrypt the password
    Returns:
      decrypted password.

  - ### decrypt

    public static String decrypt(String encryptedText, EncryptionKey encryptionKey)

    Decrypts the given encrypted text with the encryption key supplied.

    Parameters:
      `encryptedText` - text to be decrypted
      `encryptionKey` - encryption key which must resolve to the same value to encrypt and decrypt the supplied text.
    Returns:
      decrypted text or `null` if one of `encryptedText` or `key` is `null`.