PHP code example of smoren / encryption-tools
1. Go to this page and download the library: Download smoren/encryption-tools 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/ */
smoren / encryption-tools example snippets
use Smoren\EncryptionTools\Helpers\SymmetricEncryptionHelper;
$data = ["some", "data" => "to", "encrypt"];
$secretKey = uniqid();
$dataEncrypted = SymmetricEncryptionHelper::encrypt($data, $secretKey);
$dataDecrypted = SymmetricEncryptionHelper::decrypt($dataEncrypted, $secretKey);
print_r($dataDecrypted);
$dataEncrypted = SymmetricEncryptionHelper::encrypt($data, $secretKey, 'camellia-256-ofb');
$dataDecrypted = SymmetricEncryptionHelper::decrypt($dataEncrypted, $secretKey, 'camellia-256-ofb');
print_r($dataDecrypted);
use Smoren\EncryptionTools\Helpers\AsymmetricEncryptionHelper;
$data = ["some", "data" => "to", "encrypt"];
[$privateKey, $publicKey] = AsymmetricEncryptionHelper::generateKeyPair();
$dataEncrypted = AsymmetricEncryptionHelper::encryptByPrivateKey($data, $privateKey);
$dataDecrypted = AsymmetricEncryptionHelper::decryptByPublicKey($dataEncrypted, $publicKey);
print_r($dataDecrypted);
$dataEncrypted = AsymmetricEncryptionHelper::encryptByPublicKey($data, $publicKey);
$dataDecrypted = AsymmetricEncryptionHelper::decryptByPrivateKey($dataEncrypted, $privateKey);
print_r($dataDecrypted);
use Smoren\EncryptionTools\Helpers\AsymmetricEncryptionHelper;
use Smoren\EncryptionTools\Exceptions\AsymmetricEncryptionException;
$data = ["some", "data" => "to", "encrypt"];
[$privateKey, $publicKey] = AsymmetricEncryptionHelper::generateKeyPair();
$signature = AsymmetricEncryptionHelper::sign($data, $privateKey);
try {
AsymmetricEncryptionHelper::verify($data, $signature, $publicKey);
} catch(AsymmetricEncryptionException $e) {
// ... handling exception if cannot verify signature
}
use Smoren\EncryptionTools\Helpers\AsymmetricLargeDataEncryptionHelper;
$data = file_get_contents('file_with_large_data.txt');
[$privateKey, $publicKey] = AsymmetricLargeDataEncryptionHelper::generateKeyPair();
$dataEncrypted = AsymmetricLargeDataEncryptionHelper::encryptByPrivateKey($data, $privateKey);
$dataDecrypted = AsymmetricLargeDataEncryptionHelper::decryptByPublicKey($dataEncrypted, $publicKey);
print_r($dataDecrypted);
$dataEncrypted = AsymmetricLargeDataEncryptionHelper::encryptByPublicKey($data, $publicKey);
$dataDecrypted = AsymmetricLargeDataEncryptionHelper::decryptByPrivateKey($dataEncrypted, $privateKey);
print_r($dataDecrypted);