Package org.bhn.promotion.core.service
Class EncryptionService
java.lang.Object
org.bhn.promotion.core.service.EncryptionService
The class contains methods for Encryption and Decryption.
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
EncryptionService
public EncryptionService()
-
-
Method Details
-
encrypt
Encrypts the provided plain text using the specified encryption algorithm.This method uses a
SecretKeySpecgenerated bygetKey()to initialize aCipherin encryption mode. The plain text is then encrypted and encoded in Base64 for safe storage or transmission.- Parameters:
plainText- the text to be encrypted- Returns:
- the encrypted text, encoded in Base64; returns the plain text if encryption fails
-
decrypt
Decrypts the provided encrypted text using the specified encryption algorithm.This method first decodes the Base64-encoded encrypted text and then uses a
SecretKeySpecgenerated bygetKey()to initialize aCipherin decryption mode. The decrypted bytes are converted back into a UTF-8 encoded string and returned as the original plain text.- Parameters:
encryptedText- the Base64-encoded encrypted text to be decrypted- Returns:
- the decrypted plain text; returns the original encrypted text if decryption fails
-