PHP code example of blazemv / cryptx

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

    

blazemv / cryptx example snippets


//anywhere in your app
$encrypted = \Cryptx::encrypt("My Secret String");
$decrypted = \Cryptx::decrypt($encrypted);



laze\Cryptx\Cryptx;

// generate keys
$privateKeyPath = 'private.pem';
$publicKeyPath = 'public.pem';

if (!file_exists($publicKeyPath)) {
    $tempCryptx = new Cryptx();
    $keyPair = $tempCryptx->generateKeyPair();
    $privateKey = $tempCryptx->extractPrivateKey($keyPair);
    $publicKey = $tempCryptx->extractPublicKey($keyPair);

    file_put_contents($privateKeyPath, $privateKey);
    file_put_contents($publicKeyPath, $publicKey);
}

// usage
$cryptx = new Cryptx($privateKeyPath, $publicKeyPath);
$cryptx = new Cryptx($privateKeyPath, $publicKeyPath);
$encrypted = $cryptx->encrypt("My Secret String");
$decrypted = $cryptx->decrypt($encrypted);
echo "encrypted => $encrypted\r\n";
echo "decrypted => $decrypted\r\n";