Class EncryptionService

java.lang.Object
ai.nervemind.app.service.EncryptionService

@Service public class EncryptionService extends Object
Service for encrypting and decrypting sensitive data. Uses AES-GCM for authenticated encryption.
  • Constructor Details

    • EncryptionService

      public EncryptionService(@Value("${nervemind.encryption.key:default-dev-key-change-in-prod}") String keyString)
      Creates a new EncryptionService with the specified key.
      Parameters:
      keyString - the master key for encryption/decryption
  • Method Details

    • encrypt

      public String encrypt(String plaintext)
      Encrypts a plaintext string.
      Parameters:
      plaintext - The text to encrypt
      Returns:
      Base64-encoded ciphertext with IV prepended
    • decrypt

      public String decrypt(String ciphertext)
      Decrypts a Base64-encoded ciphertext.
      Parameters:
      ciphertext - The Base64-encoded ciphertext with IV prepended
      Returns:
      The decrypted plaintext
    • isEncrypted

      public boolean isEncrypted(String value)
      Checks if a value appears to be encrypted. Encrypted values are Base64 strings with a minimum length.
      Parameters:
      value - the string to check
      Returns:
      true if the string appears to be an encrypted ciphertext