Skip to content

DurgeshOnStack/FactoryBean_02Encryption_Algorithm_Factory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

🔐 Spring Encryption Service (FactoryBean Based)

A simple and extensible Spring Core project demonstrating how to dynamically switch between different encryption algorithms using FactoryBean, Java Configuration, and Strategy Pattern principles.


🚀 Features

  • 🔄 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


🧠 Concept Used

  • Spring Core (Annotation-based configuration)
  • FactoryBean pattern
  • Strategy Design Pattern
  • Dependency Injection (DI)
  • Loose coupling & extensibility

📁 Project Structure

com.nit
│
├── config
│   └── AppConfig.java
│
├── factoryBean
│   └── EncryptionServiceFactoryBean.java
│
├── main
│   └── TestApp.java
│
├── properties
│   └── application.properties
│
└── sbeans
    ├── EncryptionService.java
    ├── AESEncryption.java
    ├── RSAEncryption.java
    └── SHAHashing.java

⚙️ Configuration

Set the encryption type in:

application.properties

Example:

encryption=aes

You can change values to:

  • aes
  • rsa
  • sha

🏗️ Core Implementation

🔹 FactoryBean Implementation

The factory decides which encryption strategy to return at runtime.

📄 EncryptionServiceFactoryBean.java


🔹 Configuration Class

Loads property and injects it into FactoryBean.

📄 AppConfig.java


🔹 Service Interface

Common contract for all encryption types.

📄 EncryptionService.java


🔹 Implementations

  • AES Encryption →
  • RSA Encryption →
  • SHA Hashing →

🔹 Main Class

Runs the application using Spring context.

📄 TestApp.java


▶️ How to Run

  1. Clone the repository
git clone https://github.com/your-username/encryption-service.git
  1. Open in IDE (IntelliJ / Eclipse)

  2. Set encryption type in application.properties

  3. Run:

TestApp.java

💡 Sample Output

AESEncryption successfull.
AESDecryption successfull.

(Change property to see different outputs)


⚠️ Known Issue

There is a small bug in EncryptionServiceFactoryBean:

else if("aes".equalsIgnoreCase(encryptionType))

This condition is duplicated.

👉 Fix it to:

else if("rsa".equalsIgnoreCase(encryptionType))

🔮 Future Enhancements

  • 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

🤝 Contributing

Pull requests are welcome. For major changes, open an issue first to discuss what you'd like to change.


📜 License

This project is open-source and free to use.


👨‍💻 Author

Developed as a learning project to demonstrate Spring FactoryBean and dynamic bean creation.


⭐ If this helped you, drop a star on the repo!

About

A Spring Core project that dynamically selects encryption algorithms (AES, RSA, SHA) using the FactoryBean pattern and external configuration. It demonstrates clean design principles like dependency injection and strategy-based architecture for flexible, scalable encryption handling.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages