PHP code example of june / data_security

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

    

june / data_security example snippets


use june\DataSecurity\Config;
use june\DataSecurity\Openssl;

$data = "Data that needs to be encrypted";

$config = new Config([
    "key"   => "your key",
    "iv"    => 'iv',
    "aad"   => 'aad'
]);
$openssl = new Openssl($config);
$ciphertext = $openssl->encrypted($data);
echo $ciphertext;

$data = $openssl->decryption($ciphertext);
echo $data;

use june\DataSecurity\Config;
use june\DataSecurity\Openssl;

$data = "Data that needs to be encrypted";

$config = new Config([
    "privateKey" => "",
    "privateKeyFilePath" => "",
    "publicKey" => "",
    "publicKeyFilePath" => "",
]);
$openssl = new Openssl($config);

// Public key encryption
$ciphertext = $openssl->publicEncrypt($data);
echo $ciphertext;
$data = $openssl->privateDecrypt($ciphertext);
echo $data;

// Private key encryption
$ciphertext = $openssl->privateEncrypt($data);
echo $ciphertext;
$data = $openssl->publicDecrypt($ciphertext);
echo $data;

use june\DataSecurity\Config;
use june\DataSecurity\Signature;

$data = [
    "name" => 'june'
];
$config = new Config([
    "appId"      => "your appId",
    "key"        => "your key"
]);
$signature = new Signature($config);
$sign = $signature->sign($data);
echo $sign;

$result = $signature->validate($sign, $data);
echo $result;

$config = new Config([
    "privateKey" => "",
    "privateKeyFilePath" => "",
    "publicKey" => "",
    "publicKeyFilePath" => "",
]);
$signature = new Signature($config);
$sign = $signature->opensslSign($data);
echo $sign;

$result = $signature->opensslVerify($sign, $data);
echo $result;