PHP code example of legatus / crypto

1. Go to this page and download the library: Download legatus/crypto library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

legatus / crypto example snippets




use Legatus\Support\LegatusCipher;
use Legatus\Support\SodiumKey;

$secret = SodiumKey::generate()->getBytes();
$cipher = new LegatusCipher($secret);

$encrypted = $cipher->encrypt('message');

// You can optionally pass a ttl for verification
try {
    $message = $cipher->decrypt($encrypted, 3600);
    echo $message; // Writes: "message"
} catch (Legatus\Support\ExpiredCipher $e) {
    // The encrypted message has passed the ttl
} catch (Legatus\Support\InvalidCipher $e) {
    // The encrypted message is invalid
}