|
1 | 1 | # tencryptor |
| 2 | + |
| 3 | +## Project Overview |
| 4 | + |
| 5 | +Tosan Encryptor is a Java library providing basic encryption utilities. It uses Bouncy Castle for cryptographic operations and supports multiple encryption algorithms including AES with PKCS5/PKCS7 padding, and ECDH encryption. |
| 6 | + |
| 7 | +## Build and Test Commands |
| 8 | + |
| 9 | +```bash |
| 10 | +# Build the project |
| 11 | +mvn clean package |
| 12 | + |
| 13 | +# Run all tests |
| 14 | +mvn test |
| 15 | + |
| 16 | +# Run a specific test class |
| 17 | +mvn test -Dtest=TosanEncryptorUTest |
| 18 | + |
| 19 | +# Run a specific test method |
| 20 | +mvn test -Dtest=TosanEncryptorUTest#testEncryptionProcess_encryptWithDefaultAlgorithm_encrypted |
| 21 | + |
| 22 | +# Generate Javadoc |
| 23 | +mvn javadoc:javadoc |
| 24 | + |
| 25 | +# Install to local Maven repository |
| 26 | +mvn install |
| 27 | +``` |
| 28 | + |
| 29 | +## Architecture |
| 30 | + |
| 31 | +### Core Components |
| 32 | + |
| 33 | +The library is organized into four main packages: |
| 34 | + |
| 35 | +**`com.tosan.tools.tencryptor.encryptor`**: Entry point for encryption/decryption operations |
| 36 | +- `Encryptor` (interface): Defines the contract for encryption operations |
| 37 | +- `TosanEncryptor`: Main implementation supporting multiple algorithms via strategy pattern |
| 38 | + |
| 39 | +**`com.tosan.tools.tencryptor.algorithm`**: Encryption algorithm implementations (strategy pattern) |
| 40 | +- `AlgorithmEncryption` (interface): Contract for algorithm implementations |
| 41 | +- `DefaultAlgorithmEncryption`: PKCS5 padding implementation |
| 42 | +- `DynamicAlgorithmEncryptionWithIV`: PKCS7 padding with dynamic IV |
| 43 | +- `GenericAlgorithmEncryption`: Generic algorithm support |
| 44 | + |
| 45 | +**`com.tosan.tools.tencryptor.util`**: Utility classes for common operations |
| 46 | +- `EncryptionUtil`: AES encryption/decryption, ECDH operations, and hash generation |
| 47 | +- `HashUtil`: SHA-2 hashing with salt and HMAC generation using Bouncy Castle |
| 48 | +- `ECDHEncryptionUtil`: Elliptic Curve Diffie-Hellman encryption |
| 49 | +- `EncryptionStringUtil`: String manipulation utilities for encryption |
| 50 | + |
| 51 | +**`com.tosan.tools.tencryptor.exception`**: Custom exceptions |
| 52 | +- `EncryptionException`: Base exception for encryption errors |
| 53 | +- `InvalidKeyException`: Thrown for invalid encryption keys |
| 54 | +- `InvalidAlgorithmException`: Thrown for unsupported algorithms |
| 55 | +- `InvalidValueException`: Thrown for invalid input values |
| 56 | + |
| 57 | +### Key Design Patterns |
| 58 | + |
| 59 | +**Strategy Pattern**: `TosanEncryptor` delegates to `AlgorithmEncryption` implementations based on the algorithm specified at construction time. The algorithm map is populated in the constructor. |
| 60 | + |
| 61 | +**Algorithm Selection**: Algorithms are selected at instantiation: |
| 62 | +- Default: `PKCS5_ALGORITHM` ("AES/CBC/PKCS5Padding") → uses `DefaultAlgorithmEncryption` |
| 63 | +- `PKCS7_ALGORITHM` ("AES/CBC/PKCS7Padding") → uses `DynamicAlgorithmEncryptionWithIV` |
| 64 | +- Other algorithms → uses `GenericAlgorithmEncryption` |
| 65 | + |
| 66 | +### Encryption Flow |
| 67 | + |
| 68 | +1. User creates `TosanEncryptor` with key and optional algorithm |
| 69 | +2. Constructor creates `SecretKeySpec` and selects appropriate `AlgorithmEncryption` implementation |
| 70 | +3. `encryptText()` delegates to the algorithm implementation, then Base64 encodes result |
| 71 | +4. `decryptText()` Base64 decodes, then delegates to algorithm implementation |
| 72 | + |
| 73 | +## Release Process |
| 74 | + |
| 75 | +The project uses maven-release-plugin with the following configuration: |
| 76 | +- Tag format: `v{project.version}` (e.g., v1.0.0) |
| 77 | +- Release profile for GitHub Packages deployment |
| 78 | +- Build profile for Maven Central with GPG signing |
| 79 | + |
| 80 | + |
| 81 | +## Important Notes |
| 82 | + |
| 83 | +- Target Java version: 8 |
| 84 | +- Uses Bouncy Castle `bcprov-jdk18on` |
| 85 | +- Tests use JUnit Jupiter |
| 86 | +- Default encryption algorithm is AES/CBC/PKCS5Padding with 128-bit keys |
0 commit comments