Download the PHP package philiprehberger/php-crypt without Composer
On this page you can find all versions of the php package philiprehberger/php-crypt. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download philiprehberger/php-crypt
More information about philiprehberger/php-crypt
Files in philiprehberger/php-crypt
Download philiprehberger/php-crypt
More information about philiprehberger/php-crypt
Files in philiprehberger/php-crypt
Vendor philiprehberger
Package php-crypt
Short Description Secure-by-default encryption with AES-256-GCM and key rotation
License MIT
Homepage https://github.com/philiprehberger/php-crypt
Package php-crypt
Short Description Secure-by-default encryption with AES-256-GCM and key rotation
License MIT
Homepage https://github.com/philiprehberger/php-crypt
Please rate this library. Is it a good library?
Informations about the package php-crypt
PHP Crypt
Secure-by-default encryption with AES-256-GCM and key rotation.
Requirements
- PHP 8.2+
- ext-openssl
Installation
Usage
Basic Encryption
Additional Authenticated Data (AAD)
Bind ciphertext to a context so it cannot be used elsewhere:
Key Rotation
Re-encrypt data when rotating keys:
Array Encryption
Encrypt and decrypt arrays (serialized as JSON):
JSON Encryption
Encrypt and decrypt any JSON-serializable value:
Key Validation
Check the strength of an encryption key:
KeyChain (Multi-Key Management)
Manage key rotation transparently — encrypts with the current key, decrypts with any known key:
API
Crypt (Static)
| Method | Description |
|---|---|
generateKey(): string |
Generate a random base64-encoded 32-byte key |
encrypt(string $data, string $key, ?string $aad = null): string |
Encrypt data with AES-256-GCM |
decrypt(string $encrypted, string $key, ?string $aad = null): string |
Decrypt AES-256-GCM ciphertext |
rotate(string $encrypted, string $oldKey, string $newKey): string |
Re-encrypt data with a new key |
encryptArray(array $data, string $key): string |
Encrypt an array as JSON |
decryptArray(string $encrypted, string $key): array |
Decrypt a JSON-encoded array |
encryptJson(mixed $data, string $key): string |
JSON-encode any value then encrypt |
decryptJson(string $encrypted, string $key): mixed |
Decrypt then JSON-decode |
validateKeyStrength(string $key): array |
Check key bit length and strength |
KeyChain
| Method | Description |
|---|---|
__construct(string $currentKey, string ...$previousKeys) |
Create a key chain |
encrypt(string $data): string |
Encrypt with the current key |
decrypt(string $encrypted): string |
Decrypt with any key in the chain |
rotateAll(array $ciphertexts): array |
Re-encrypt all ciphertexts with the current key |
Exceptions
| Exception | When |
|---|---|
InvalidKeyException |
Key is not a valid base64-encoded 32-byte string |
DecryptionException |
Decryption fails (wrong key, tampered data, invalid ciphertext) |
Development
Support
If you find this project useful:
License
MIT
All versions of php-crypt with dependencies
PHP Build Version
Package Version
Requires
php Version
^8.2
ext-openssl Version *
ext-openssl Version *
The package philiprehberger/php-crypt contains the following files
Loading the files please wait ...