A free, reliable, and easy-to-use PHP library for encrypting and decrypting strings with advanced cipher methods.
- Overview
- Features
- Installation
- Usage
- Available Cipher Methods
- Security Considerations
- Requirements
- Contributing
- License
SecureCipher is a robust PHP library designed to help you enhance your application's security by providing easy-to-use encryption and decryption capabilities. Whether you need to protect sensitive user data or secure system-level information, SecureCipher offers a straightforward API with flexible cipher method options.
- Multiple Cipher Methods: Support for various AES encryption algorithms
- User-Level Encryption: Customize encryption with user-specific keys
- System-Wide Base Key: Set a system base key for additional security layer
- Simple API: Intuitive methods for encryption and decryption
- Type-Safe: Utilizes PHP enumerations for cipher method selection
- Well-Tested: Comprehensive test coverage
Install SecureCipher via Composer:
composer require snipershady/securecipher<?php
use SecureCipher\Service\SecureCipher;
// Initialize with a system-wide base key
$baseKey = "your-secure-base-key";
$userKey = "user-specific-key";
$sc = new SecureCipher($baseKey);
// Original data to encrypt
$data = "ForzaNapoli";
// Encrypt the data with the user's personal key
$encryptedData = $sc->encrypt($data, $userKey);
// Store $encryptedData in your database or file system
// Later, retrieve and decrypt the data
$decryptedData = $sc->decrypt($encryptedData, $userKey);
// Verify the decryption
assert($data === $decryptedData); // trueThe default cipher method is AES_256_CBC, but you can select a different method using the CipherMethod enumeration:
<?php
use SecureCipher\Service\SecureCipher;
use SecureCipher\Enum\CipherMethod;
$baseKey = "your-secure-base-key";
$userKey = "user-specific-key";
$sc = new SecureCipher($baseKey);
$data = "Sensitive Information";
// Encrypt with AES-128-CBC
$encryptedData = $sc->encrypt($data, $userKey, CipherMethod::AES_128_CBC);
// Decrypt with the same cipher method
$decryptedData = $sc->decrypt($encryptedData, $userKey, CipherMethod::AES_128_CBC);
// ⚠️ Important: The cipher method must be the same for both encryption and decryptionSecureCipher supports multiple cipher methods through the CipherMethod enumeration:
AES_256_CBC(default) - Advanced Encryption Standard with 256-bit keyAES_128_CBC- Advanced Encryption Standard with 128-bit keyAES_192_CBC- Advanced Encryption Standard with 192-bit key- Additional methods available in the
CipherMethodenum
Check the CipherMethod enum class for the complete list of supported encryption algorithms.
- Key Management: Store your base keys and user keys securely. Never commit them to version control.
- Key Strength: Use strong, randomly generated keys for both base and user keys.
- Cipher Method Consistency: Always use the same cipher method for encryption and decryption.
- HTTPS: Transmit encrypted data over secure connections (HTTPS) when applicable.
- Regular Updates: Keep the library updated to benefit from security patches and improvements.
- PHP 8.3 or higher
- OpenSSL extension enabled
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the GPL-3.0 License - see the LICENSE file for details.
Made with ❤️ by snipershady