PHP code example of zetwypro / zetoken

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

    

zetwypro / zetoken example snippets


use Zetwypro\Zetoken\Zetoken;

$zetoken = new Zetoken();

// Encode using KeyID, Secret, & Iterations from .env
$token =$zetoken->encode("Secret Message");

// Decode and perfectly restore to original text
$original = $zetoken->decode($token);


use Zetwypro\Zetoken\Zetoken;

$zetoken = new Zetoken();

$userId = "USER-9921";
$data = "Exam Passed";

// SIGN: Locks the token using a combination of Master Access Key + $userId + Master Secret Key
$token =$zetoken->sign($data,$userId);

// VERIFY: The token can only be opened and its integrity verified if the User ID is an exact match
$result =$zetoken->verifySign($token,$userId);

if ($result === false) {
    echo "Fake token, manipulated, or incorrect KeyID!";
}


use Zetwypro\Zetoken\Zetoken;

$zetoken = new Zetoken();

// 1. ENCODE WITH EXPIRATION
// Add the $ttl parameter (in seconds). E.g., 300 seconds = 5 minutes.
// Parameters: encode($text,$keyId, $secretKey,$ttl)
$token = $zetoken->encode("Self-destructing message", ttl: 300);

// You can also use TTL with the Sign feature:
// Parameters: sign($text,$keyId, $secretKey,$ttl)
// $token =$zetoken->sign("Exam Passed", "USER-9921", null, 300);


// 2. DECODE WITH AUTOMATIC TIME VALIDATION
// When decoding, Zetoken automatically checks the time. 
// It