Class AesEncryptor

java.lang.Object
org.jivesoftware.util.AesEncryptor
All Implemented Interfaces:
Encryptor

public class AesEncryptor extends Object implements Encryptor
Utility class providing symmetric AES encryption/decryption. To strengthen the encrypted result, use the setKey(byte[]) method to provide a custom key prior to invoking the encrypt(java.lang.String) or decrypt(java.lang.String) methods.
Author:
Tom Evans
  • Constructor Details

    • AesEncryptor

      public AesEncryptor()
      Default constructor
    • AesEncryptor

      public AesEncryptor(String key)
      Custom key constructor
      Parameters:
      key - the custom key
  • Method Details

    • encrypt

      public String encrypt(String value)
      Description copied from interface: Encryptor
      Encrypt a clear text String.
      Specified by:
      encrypt in interface Encryptor
      Parameters:
      value - The clear text attribute
      Returns:
      The encrypted attribute, or null
    • encrypt

      public String encrypt(String value, byte[] iv)
      Description copied from interface: Encryptor
      Encrypt a clear text String.
      Specified by:
      encrypt in interface Encryptor
      Parameters:
      value - The clear text attribute
      iv - The IV to use, or null for the default IV
      Returns:
      The encrypted attribute, or null
    • decrypt

      public String decrypt(String value)
      Description copied from interface: Encryptor
      Decrypt an encrypted String.
      Specified by:
      decrypt in interface Encryptor
      Parameters:
      value - The encrypted attribute in Base64 encoding
      Returns:
      The clear text attribute, or null
    • decrypt

      public String decrypt(String value, byte[] iv)
      Description copied from interface: Encryptor
      Decrypt an encrypted String.
      Specified by:
      decrypt in interface Encryptor
      Parameters:
      value - The encrypted attribute in Base64 encoding
      iv - The IV to use, or null for the default IV
      Returns:
      The clear text attribute, or null
    • setKey

      public void setKey(String key)
      Description copied from interface: Encryptor
      Set the encryption key. This will apply the user-defined key, truncated or filled (via the default key) as needed to meet the key length specifications.
      Specified by:
      setKey in interface Encryptor
      Parameters:
      key - The encryption key