Class AES

java.lang.Object
de.qytera.qtaf.security.aes.AES

public class AES extends Object
Class that provides methods for encryption and decryption with the AES algorithm
  • Method Details

    • encrypt

      public static String encrypt(String plainText, String key) throws GeneralSecurityException
      Encrypts string content using the provided passphrase.
      Parameters:
      plainText - the plaintext that should be encrypted
      key - the AES secret key
      Returns:
      the encrypted ciphertext
      Throws:
      GeneralSecurityException - whenever encryption fails
    • encrypt

      public static String encrypt(String plainText, String key, byte[] salt) throws GeneralSecurityException
      Encrypts string content using the provided passphrase.
      Parameters:
      plainText - the plaintext that should be encrypted
      key - the AES secret key
      salt - the salt
      Returns:
      the encrypted ciphertext
      Throws:
      GeneralSecurityException - whenever encryption fails
    • decrypt

      public static String decrypt(String ciphertext, String key) throws GeneralSecurityException
      Decrypts an AES-encrypted ciphertext using the provided passphrase.
      Parameters:
      ciphertext - the AES ciphertext
      key - the AES secret key
      Returns:
      the decrypted plaintext
      Throws:
      GeneralSecurityException - whenever decryption fails
    • createAESKey

      public static SecretKeySpec createAESKey(char[] passphrase, byte[] salt) throws NoSuchAlgorithmException, InvalidKeySpecException
      Creates a secret cryptographic AES key from a given passphrase and a salt.
      Parameters:
      passphrase - the passphrase to base the key on
      salt - the salt to use
      Returns:
      a corresponding, secret AES key
      Throws:
      NoSuchAlgorithmException - if the factory used for creating the key does not know the PBE algorithm
      InvalidKeySpecException - if the given key specification is inappropriate for this secret-key factory to produce a secret key