Class EncryptionService

java.lang.Object
org.bhn.promotion.core.service.EncryptionService

@Service public class EncryptionService extends Object

The class contains methods for Encryption and Decryption.

  • Constructor Details

    • EncryptionService

      public EncryptionService()
  • Method Details

    • encrypt

      public String encrypt(String plainText)
      Encrypts the provided plain text using the specified encryption algorithm.

      This method uses a SecretKeySpec generated by getKey() to initialize a Cipher in 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

      public String decrypt(String encryptedText)
      Decrypts the provided encrypted text using the specified encryption algorithm.

      This method first decodes the Base64-encoded encrypted text and then uses a SecretKeySpec generated by getKey() to initialize a Cipher in 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