CrypticCore is a high-performance Java-based encryption engine designed for memory-efficient file transformation. It implements a decoupled architecture that separates the cryptographic logic from the data streaming process.
The engine utilizes the bitwise Exclusive OR (XOR) operation. Given that XOR is an involution, the transformation is self-inverse, allowing for identical encryption and decryption logic.
The operation is defined as:
To handle data streams where the length of the plaintext exceeds the key length, a cyclic key schedule is implemented:
To prevent unintended sign extension during the implicit promotion from byte to 32-bit int, a
bitmask of
- O(1) Space Complexity: Processes data in discrete 8 KB buffers, allowing files of arbitrary size (tested up to 5 GB) to be processed with minimal RAM footprint.
- Throughput: Optimized for high-speed I/O, achieving over 400 MB/s on standard hardware.
- Real-time Telemetry: Integrated progress bar and performance statistics (MB/s, latency).
- Atomic Writes: Utilizes a
.tmpfile staging strategy. The final output is only created via an atomicmoveoperation upon successful completion, preventing data corruption during crashes or power failures. - Memory Sanitation: The encryption key is explicitly overwritten in the JVM heap using
Arrays.fill()immediately after use to mitigate memory dump exploits. - Header Validation: Strict magic number and version checking prevents the processing of incompatible or corrupted files.
The engine is built on SOLID principles to ensure extensibility and testability:
- Single Responsibility (SRP): I/O handling, header validation, and cryptographic logic are
strictly
separated into specialized components (
HeaderHandler,FileValidator,EncryptionEngine). - Dependency Inversion (DIP): The engine does not depend on a specific UI. It communicates
progress
through a
ProgressObserverinterface, allowing for seamless integration into CLI, Web, or Cloud environments. - Interface Segregation: Cryptographic strategies are injected via the
CipherAlgorithminterface, making the engine open for future algorithms (e.g., AES) without modifying the core streaming logic.
The engine is fully containerized to ensure environment parity and security.
- Multi-Stage Docker Build: Uses a builder stage (Maven) and a hardened runtime stage (JRE Alpine) to minimize image size (~160MB) and attack surface.
- Security Hardening: The container execution is restricted to a Non-Root User.
- Orchestration: Includes a
docker-compose.ymlfor seamless integration into microservice environments.
Every encrypted file starts with a 4-byte metadata header.
| Offset | Length | Description | Value (Hex / ASCII) |
|---|---|---|---|
| 0x00 | 3 Bytes | Magic Number (CCE) | 0x43 0x43 0x45 |
| 0x03 | 1 Byte | Format Version | 0x01 |
java -jar CrypticCore.jar <mode> <input> <output> <key>docker compose run --rm engine <mode> /app/data/input.txt /app/data/output.enc <key>Parameters:
- mode:
ENCRYPTIONorDECRYPTION(Case-insensitive). - input: Path to the source file.
- output: Final destination path for the transformed file.
- key: Secret key for transformation.
The project follows a rigorous testing strategy to ensure data integrity and system stability:
The project utilizes GitHub Actions for continuous integration. Every push and pull request is automatically validated against:
- Compilation & Test Suite: Ensures 100% build stability on Java 21.
- Checkstyle (Google Java Style): Strict enforcement of the Google Java Style Guide.
- Test Coverage (JaCoCo): A quality gate is set to ensure a minimum of 85% code coverage.
- Hybrid Structured Logging: Implements environment-aware logging. The engine automatically detects its environment and switches to Structured JSON Logging when running in Docker.
- Unit Testing: Verified the involution property and edge cases (byte boundaries).
- Integration Testing: End-to-end validation of the custom
.cceformat and header integrity. - Resilience: Validation of atomic write operations and prevention of data truncation.
- End-to-End Cycle: Successful encryption and decryption of real file streams.
- Atomic Integrity: Verification of the
.tmpstaging and atomic move strategy. - Error Resilience: * Detection of truncated files (Expected vs. Actual size check).
- Prevention of in-place corruption (Same-file validation).
- Robust header and version validation.
The engine is structured into specialized packages to ensure high maintainability and separation of concerns:
at.tuwien.crypticcore.api: Functional interfaces and core contracts for algorithm strategies.at.tuwien.crypticcore.engine: The orchestration layer. Stateless execution of streaming cryptography.at.tuwien.crypticcore.io: Infrastructure layer handling format-specific headers (HeaderHandler), fail-fast validation (FileValidator), and theProgressObserverpattern.
graph TD
A[CLI / Docker] --> B[Main Controller]
B --> C[Stream Orchestrator]
C --> D[XOR Strategy]
C --> E[Buffered I/O 8KB]
subgraph Observability
B --> F[SLF4J/Logback]
F -- Local --> G[Console Text]
F -- Docker --> H[Structured JSON]
end
subgraph Infrastructure
E --> I[Header Validation]
E --> J[Atomic Write Staging]
end