Package utils
Class EncryptionUtils
java.lang.Object
utils.EncryptionUtils
Utility class for encryption and decryption using AES algorithm. Provides methods for key
generation, encryption, and decryption of text.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic SecretKeybase64ToKey(String base64Key) Converts a Base64 encoded string key to a SecretKey object.static StringDecrypts an encrypted string using AES decryption.static StringEncrypts a plain text string using AES encryption.static StringGenerates a new AES key and returns it as a Base64 encoded string.static voidMain method for demonstrating encryption/decryption functionality.
-
Constructor Details
-
EncryptionUtils
public EncryptionUtils()
-
-
Method Details
-
generateKey
Generates a new AES key and returns it as a Base64 encoded string.- Returns:
- Base64 encoded string representation of the generated key
- Throws:
NoSuchAlgorithmException- if the AES algorithm is not available
-
base64ToKey
Converts a Base64 encoded string key to a SecretKey object.- Parameters:
base64Key- the Base64 encoded key string- Returns:
- a SecretKey object for use with AES encryption/decryption
-
encrypt
Encrypts a plain text string using AES encryption.- Parameters:
plainText- the text to encryptbase64Key- the Base64 encoded encryption key- Returns:
- Base64 encoded encrypted string, or null if encryption fails
-
decrypt
Decrypts an encrypted string using AES decryption.- Parameters:
encryptedText- the Base64 encoded encrypted textbase64Key- the Base64 encoded decryption key- Returns:
- the decrypted text, or null if decryption fails
-
main
Main method for demonstrating encryption/decryption functionality. Generates a key, encrypts a sample text, and decrypts it back.- Parameters:
args- command line arguments (not used)- Throws:
Exception- if any cryptographic operations fail
-