dev-fighters/php-crypter

1.0.8 2023-10-17 08:47 UTC

This package is auto-updated.

Last update: 2024-05-17 10:16:12 UTC


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

  1. Generate a key : the key needs to be saved, or you can't decrypt further.
    $key = Crypter::generateKey()
  1. Encrypt
    $key = **KEY_GENERATED**
    $text = **TEXT_TO_ENCRYPT**
    $crypter = new Crypter($key);
    $encryptedText = $crypter->encrypt($text);
  1. 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;