talentrydev/cryptography

PHP library for encryption

1.0.0 2023-01-09 09:30 UTC

This package is auto-updated.

Last update: 2024-05-09 12:49:08 UTC


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