This project implements a production-grade encryption and key management system written in Go. It offers:
- AES-256 encryption and decryption of data
- RESTful APIs for key lifecycle management
- In-memory key storage with thread-safe operations
- Swagger-based REST API documentation hosted on GitHub Pages
- Unit test coverage for critical components
- Docker support for containerized deployment
+-------------+ POST/PUT/DELETE +-------------------+
| | <----------------------> | |
| Client | | Golang REST API |
| | ----------------------> | |
+-------------+ Encrypt/Decrypt +-------------------+
| |
v v
+---------------+ +---------------+
| Key Manager | | Encryptor |
| (internal) | | (internal) |
+---------------+ +---------------+
.
├── cmd/ # Main application entrypoint
├── internal/
│ ├── api/ # REST handlers and routes
│ ├── encryption/ # AES encryption logic
│ └── keymanager/ # Key lifecycle (create/delete/reset)
├── docs/
│ ├── index.html # Swagger UI for GitHub Pages
│ └── openapi.yaml # OpenAPI spec
├── test/ # Unit tests
├── Dockerfile # Docker setup
├── go.mod / go.sum # Go module definitions
Method | Endpoint | Description |
---|---|---|
POST | /api/key |
Create new key |
DELETE | /api/key/{id} |
Delete key by ID |
PUT | /api/key/{id}/reset |
Reset key by ID |
POST | /api/encrypt |
Encrypt data |
POST | /api/decrypt |
Decrypt data |
{
"key_id": "abc123",
"data": "Hello, World!"
}
git clone https://github.com/aditya-bhuyan/go-encryption-service.git
cd go-encryption-service
go run cmd/main.go
docker build -t go-encryption-service .
docker run -p 8080:8080 go-encryption-service
go test ./...
This project includes a Makefile
to streamline local development and CI integration:
Command | Description |
---|---|
make build |
Build the server binary |
make server |
Run the server locally |
make client |
Run the Go-based API client |
make test |
Run all unit tests |
make coverage |
Generate test coverage report |
make docker-build |
Build the Docker image |
make docker-run |
Run the Docker container (port 8080) |
To run all unit tests with coverage:
make test
make coverage
You can also run manually:
go test -v -coverprofile=coverage.out ./...
go tool cover -func=coverage.out
To build and run the project in a container:
make docker-build
make docker-run
- Swagger UI: https://aditya-bhuyan.github.io/go-encryption-service
- OpenAPI Spec:
docs/openapi.yaml
This project is licensed under the GNU GPLv3 License.
Aditya Pratap Bhuyan
GitHub: @aditya-bhuyan
LinkedIn: Aditya Bhuyan