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); // 32 bytes SecretBox::decrypt($ciphertext, $key);

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

$plaintext = SecretBox::decrypt($ciphertext, [
    $oldKey,
    $newKey,
]);

try {
    $plaintext = SecretBox::decrypt($ciphertext, $key);
} catch (\SodiumException $e) {
    // Handle decryption failure
}