dev-fighters / php-crypter
Crypter for PHP
1.0.8
2023-10-17 08:47 UTC
Requires
- php: >=8.2
- ext-sodium: *
Requires (Dev)
- phpunit/phpunit: ^10
README
Installation
- Install with composer
composer require dev-fighters/php-crypter
- Requires PHP >= 8.2
- Encryption algorithm is AEAD XChaCha20 Poly1305 IETF
How to use
Main file is \DF\Encryption\Crypter
- Generate a key : the key needs to be saved, or you can't decrypt further.
$key = Crypter::generateKey()
- Encrypt
$key = **KEY_GENERATED** $text = **TEXT_TO_ENCRYPT** $crypter = new Crypter($key); $encryptedText = $crypter->encrypt($text);
- Decrypt
$key = **KEY_GENERATED** $textEncrypted = **TEXT_TO_DECRYPT** $crypter = new Crypter($key); $encryptedText = $crypter->decrypt($textEncrypted);
- Additional : check if a string is encrypted or not
$key = **KEY_GENERATED** $text = **TEXT_TO_DECRYPT** $crypter = new Crypter($key); $crypter->isEncrypted($text); $crypter->isNotEncrypted($text);
All functions accessible
static function generateKey() : string; function encrypt(string $textToEncrypt) : string; function decrypt(string $textEncrypted) : string; function isEncrypted(string $textEncrypted) : bool; function isNotEncrypted(string $textEncrypted) : bool;