talentrydev / cryptography
PHP library for encryption
2.0.0
2024-05-31 13:26 UTC
Requires
- php: ^8.3
- talentrydev/error-handling: ^3.0.0
Requires (Dev)
- phpunit/phpunit: ^11
- squizlabs/php_codesniffer: ^3.7
README
This is a thin library for encrypting and decrypting strings and generating hashes.
Installing
- Run:
composer require talentrydev/cryptography
Usage example
Encryption / decryption
$factory = new \Talentry\Cryptography\Factory\EncryptionServiceFactory();
$encryptionKey = $factory->generateEncryptionKey();
$service = $factory->generateEncryptionService($encryptionKey);
$encryptedString = $service->encrypt('secret');
$decryptedString = $service->decrypt($encryptedString);
WARNING: encrypt
method is not idempotent. Calling it multiple times with the same input will return different outputs.
The only guarantee is that decrypting the encrypted string will always return the original (unencrypted) string.
Generate hash
$factory = new \Talentry\Cryptography\Factory\HashGeneratorFactory();
$hash = $factory->generate('input');
Development
- Install dependencies:
make deps
- Run tests:
make test