Golang Encryption and Key Management Service
π Overview
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
π§± Architecture
+-------------+ POST/PUT/DELETE +-------------------+
| | <----------------------> | |
| Client | | Golang REST API |
| | ----------------------> | |
+-------------+ Encrypt/Decrypt +-------------------+
| |
v v
+---------------+ +---------------+
| Key Manager | | Encryptor |
| (internal) | | (internal) |
+---------------+ +---------------+
π Project Structure
.
βββ 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
π¦ API Endpoints
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!"
}
β
Running the Application
Locally (with Go)
git clone https://github.com/aditya-bhuyan/go-encryption-service.git
cd go-encryption-service
go run cmd/main.go
With Docker
docker build -t go-encryption-service .
docker run -p 8080:8080 go-encryption-service
π§ͺ Running Unit Tests
go test ./...
π οΈ Makefile Usage
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) |
π§ͺ Test and Coverage
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
π³ Docker Build & Deploy
To build and run the project in a container:
make docker-build
make docker-run
π API Documentation
π License
This project is licensed under the GNU GPLv3 License.
π€ Author
Aditya Pratap Bhuyan
GitHub: @aditya-bhuyan
LinkedIn: Aditya Bhuyan