Package de.qytera.qtaf.security.aes
Class AES
java.lang.Object
de.qytera.qtaf.security.aes.AES
Class that provides methods for encryption and decryption with the AES algorithm
-
Method Summary
Modifier and TypeMethodDescriptionstatic SecretKeySpeccreateAESKey(char[] passphrase, byte[] salt) Creates a secret cryptographic AES key from a given passphrase and a salt.static StringDecrypts an AES-encrypted ciphertext using the provided passphrase.static StringEncrypts string content using the provided passphrase.static StringEncrypts string content using the provided passphrase.
-
Method Details
-
encrypt
Encrypts string content using the provided passphrase.- Parameters:
plainText- the plaintext that should be encryptedkey- 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 encryptedkey- the AES secret keysalt- the salt- Returns:
- the encrypted ciphertext
- Throws:
GeneralSecurityException- whenever encryption fails
-
decrypt
Decrypts an AES-encrypted ciphertext using the provided passphrase.- Parameters:
ciphertext- the AES ciphertextkey- 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 onsalt- 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 algorithmInvalidKeySpecException- if the given key specification is inappropriate for this secret-key factory to produce a secret key
-