PHP code example of mmeyer2k / secretbox

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

    

mmeyer2k / secretbox example snippets


use \Mmeyer2k\SecretBox\SecretBox;

$key = random_bytes(32);

$enc = SecretBox::encrypt('secret message', $key);
$dec = SecretBox::decrypt($enc, $key);

$key = base64_decode("[your base64 key]");

$dec = SecretBox::decrypt($ciphertext, [
    'key 0',
    'key 1',
    'key 2',
]);

try {
    $dec = SecretBox::decrypt($ciphertext, $key);
} catch (\SodiumException) {
    # ...
}