PHP code example of oittaa / aes-gcm

1. Go to this page and download the library: Download oittaa/aes-gcm 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/ */

    

oittaa / aes-gcm example snippets




ESGCM\AESGCM;

// Base64 encoded data returned
$encrypted = AESGCM::encrypt('my data', 'my secret password');
var_dump($encrypted);
$decrypted = AESGCM::decrypt($encrypted, 'my secret password');
var_dump($decrypted);

// False returned
$decrypted = AESGCM::decrypt($encrypted, 'WRONG password');
var_dump($decrypted);

// Raw binary data returned
$encrypted = AESGCM::encrypt('my data', 'my secret password', true);
var_dump($encrypted);
$decrypted = AESGCM::decrypt($encrypted, 'my secret password', true);
var_dump($decrypted);

// Additional authenticated data (AAD)
$encrypted = AESGCM::encrypt('my data', 'my secret password', aad: 'additional data');
var_dump($encrypted);
$decrypted = AESGCM::decrypt($encrypted, 'my secret password', aad: 'additional data');
var_dump($decrypted);