This project demonstrates the Chain of Responsibility Pattern in a Spring Boot application.
The goal is to resolve which hashing algorithm (e.g., MD5, SHA1, SHA256, etc.) was used to generate a given hash, based on the provided plain text.
- The API accepts a plain text and a hashed value.
- A chain of handlers (each responsible for a different algorithm) is executed.
- When a match is found, the chain returns the algorithm name.
curl --location 'http://localhost:8080/hash/resolve' \
--header 'Content-Type: application/json' \
--data '{
"text": "hello world",
"hash": "5eb63bbbe01eeed093cb22bb8f5acdc3"
}'
{
"algorithm": "MD5"
}
Each hashing algorithm is represented by a Chain Step:
- MD5HashResolveChainStep
- SHA1HashResolveChainStep
- SHA224HashResolveChainStep
- SHA256HashResolveChainStep
- SHA384HashResolveChainStep
- SHA512HashResolveChainStep
The chain is managed by the HashResolveChainHandler, which executes each step in order until a match is found.
git clone https://github.com/ercansormaz/chain-of-responsibility-pattern.git
mvn clean install
mvn spring-boot:run
You can read a detailed explanation of this project and the Chain of Responsibility Pattern in the blog post here:
👉 Read the Blog Post
Contributions are welcome! Feel free to fork the repo, submit pull requests or open issues.
This project is licensed under the MIT License.