A simple and extensible Spring Core project demonstrating how to dynamically switch between different encryption algorithms using FactoryBean, Java Configuration, and Strategy Pattern principles.
-
🔄 Dynamic encryption selection via configuration
-
🏭 Uses Spring FactoryBean for object creation
-
🧩 Supports multiple encryption strategies:
- AES Encryption
- RSA Encryption
- SHA Hashing
-
⚙️ Externalized configuration using
application.properties -
📦 Clean layered package structure
- Spring Core (Annotation-based configuration)
- FactoryBean pattern
- Strategy Design Pattern
- Dependency Injection (DI)
- Loose coupling & extensibility
com.nit
│
├── config
│ └── AppConfig.java
│
├── factoryBean
│ └── EncryptionServiceFactoryBean.java
│
├── main
│ └── TestApp.java
│
├── properties
│ └── application.properties
│
└── sbeans
├── EncryptionService.java
├── AESEncryption.java
├── RSAEncryption.java
└── SHAHashing.java
Set the encryption type in:
application.properties
Example:
encryption=aesYou can change values to:
aesrsasha
The factory decides which encryption strategy to return at runtime.
📄 EncryptionServiceFactoryBean.java
Loads property and injects it into FactoryBean.
📄 AppConfig.java
Common contract for all encryption types.
📄 EncryptionService.java
- AES Encryption →
- RSA Encryption →
- SHA Hashing →
Runs the application using Spring context.
📄 TestApp.java
- Clone the repository
git clone https://github.com/your-username/encryption-service.git-
Open in IDE (IntelliJ / Eclipse)
-
Set encryption type in
application.properties -
Run:
TestApp.javaAESEncryption successfull.
AESDecryption successfull.
(Change property to see different outputs)
There is a small bug in EncryptionServiceFactoryBean:
else if("aes".equalsIgnoreCase(encryptionType))This condition is duplicated.
👉 Fix it to:
else if("rsa".equalsIgnoreCase(encryptionType))- Add real encryption logic instead of print statements
- Support additional algorithms (Blowfish, DES, etc.)
- Convert into Spring Boot application
- Add REST API layer
- Add unit testing with JUnit
Pull requests are welcome. For major changes, open an issue first to discuss what you'd like to change.
This project is open-source and free to use.
Developed as a learning project to demonstrate Spring FactoryBean and dynamic bean creation.
⭐ If this helped you, drop a star on the repo!