PHP code example of zeyon / cryptastic

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

    

zeyon / cryptastic example snippets


$pass = 'the password';
$salt = 'the password salt';
$msg  = 'This is the secret message.';

/**********************************************************************************************************************/

// EXAMPLE #1 USING STRING AS MESSAGE

$cryptastic = new cryptastic;

$key = $cryptastic->pbkdf2($pass, $salt, 1000, 32) or
	die("Failed to generate secret key.");

$encrypted = $cryptastic->encrypt($msg, $key) or
	die("Failed to complete encryption.");

$decrypted = $cryptastic->decrypt($encrypted, $key) or
	die("Failed to complete decryption");

echo $decrypted . "<br /><br />\n";

/**********************************************************************************************************************/

// EXAMPLE #2 USING ARRAY AS MESSAGE

$msg        = array('message' => $msg);
$encrypted  = $cryptastic->encrypt($msg, $key);
$decrypted  = $cryptastic->decrypt($encrypted, $key);

echo $decrypted['message'];