PHP code example of castelnuovo / laravel-age

1. Go to this page and download the library: Download castelnuovo/laravel-age 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/ */

    

castelnuovo / laravel-age example snippets


use Castelnuovo\LaravelAge\Age;

$message = 'Hello World!';

$age = Age::generateKeypair();
$privateKey = $age->getPrivateKey();
$publicKey = $age->getPublicKey();

$age2 = new Age(publicKey: $publicKey);
$encrypted_message = $age2->encrypt($message);

$age3 = new Age(privateKey: $privateKey);
$decrypted_message = $age3->decrypt($encrypted_message);

echo $message === $decrypted_message ? 'Success' : 'Failed';