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.
# Build the project
mvn clean package
# Run all tests
mvn test
# Run a specific test class
mvn test -Dtest=TosanEncryptorUTest
# Run a specific test method
mvn test -Dtest=TosanEncryptorUTest#testEncryptionProcess_encryptWithDefaultAlgorithm_encrypted
# Generate Javadoc
mvn javadoc:javadoc
# Install to local Maven repository
mvn installThe library is organized into four main packages:
com.tosan.tools.tencryptor.encryptor: Entry point for encryption/decryption operations
Encryptor(interface): Defines the contract for encryption operationsTosanEncryptor: Main implementation supporting multiple algorithms via strategy pattern
com.tosan.tools.tencryptor.algorithm: Encryption algorithm implementations (strategy pattern)
AlgorithmEncryption(interface): Contract for algorithm implementationsDefaultAlgorithmEncryption: PKCS5 padding implementationDynamicAlgorithmEncryptionWithIV: PKCS7 padding with dynamic IVGenericAlgorithmEncryption: Generic algorithm support
com.tosan.tools.tencryptor.util: Utility classes for common operations
EncryptionUtil: AES encryption/decryption, ECDH operations, and hash generationHashUtil: SHA-2 hashing with salt and HMAC generation using Bouncy CastleECDHEncryptionUtil: Elliptic Curve Diffie-Hellman encryptionEncryptionStringUtil: String manipulation utilities for encryption
com.tosan.tools.tencryptor.exception: Custom exceptions
EncryptionException: Base exception for encryption errorsInvalidKeyException: Thrown for invalid encryption keysInvalidAlgorithmException: Thrown for unsupported algorithmsInvalidValueException: Thrown for invalid input values
Strategy Pattern: TosanEncryptor delegates to AlgorithmEncryption implementations based on the algorithm specified at construction time. The algorithm map is populated in the constructor.
Algorithm Selection: Algorithms are selected at instantiation:
- Default:
PKCS5_ALGORITHM("AES/CBC/PKCS5Padding") → usesDefaultAlgorithmEncryption PKCS7_ALGORITHM("AES/CBC/PKCS7Padding") → usesDynamicAlgorithmEncryptionWithIV- Other algorithms → uses
GenericAlgorithmEncryption
- User creates
TosanEncryptorwith key and optional algorithm - Constructor creates
SecretKeySpecand selects appropriateAlgorithmEncryptionimplementation encryptText()delegates to the algorithm implementation, then Base64 encodes resultdecryptText()Base64 decodes, then delegates to algorithm implementation
The project uses maven-release-plugin with the following configuration:
- Tag format:
v{project.version}(e.g., v1.0.0) - Release profile for GitHub Packages deployment
- Build profile for Maven Central with GPG signing
- Target Java version: 8
- Uses Bouncy Castle
bcprov-jdk18on - Tests use JUnit Jupiter
- Default encryption algorithm is AES/CBC/PKCS5Padding with 128-bit keys