Package vaultWeb.security
Class EncryptionUtil
java.lang.Object
vaultWeb.security.EncryptionUtil
Utility class for AES-GCM encryption and decryption of strings.
Provides methods to encrypt plaintext into a Base64-encoded ciphertext along with a randomly generated initialization vector (IV), and to decrypt it back to the original text. Uses AES encryption with Galois/Counter Mode (GCM) for authenticated encryption.
The constructor accepts a Base64-encoded secret key used as the master key for encryption and decryption.
Example usage:
EncryptionUtil util = new EncryptionUtil(base64Key);
EncryptionUtil.EncryptResult result = util.encrypt("Hello World");
String decrypted = util.decrypt(result.cipherTextBase64, result.ivBase64);
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classResult object for the encryption operation. -
Constructor Summary
ConstructorsConstructorDescriptionEncryptionUtil(String base64Key) Creates an EncryptionUtil instance with a given Base64-encoded AES key. -
Method Summary
-
Constructor Details
-
EncryptionUtil
Creates an EncryptionUtil instance with a given Base64-encoded AES key.- Parameters:
base64Key- Base64-encoded secret key used for AES-GCM encryption/decryption
-
-
Method Details
-
encrypt
Encrypts a plaintext string using AES-GCM with a randomly generated IV.- Parameters:
plaintext- the plaintext string to encrypt- Returns:
- an
EncryptionUtil.EncryptResultcontaining Base64-encoded ciphertext and IV - Throws:
Exception- if encryption fails
-
decrypt
Decrypts a Base64-encoded ciphertext using the provided Base64-encoded IV.- Parameters:
base64CipherText- the Base64-encoded ciphertextbase64Iv- the Base64-encoded initialization vector used during encryption- Returns:
- the original plaintext string
- Throws:
Exception- if decryption fails
-