2021-02-28 13:34:12 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require("./lib.php");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is a simple example of how to encrypt files with the library
|
|
|
|
* The following code will read the file in chunks instead of loading
|
|
|
|
* the whole thing in memory, trying to keep the "Peak Memory Usage"
|
|
|
|
* as low as possible.
|
|
|
|
*/
|
|
|
|
|
2021-02-28 13:55:29 +02:00
|
|
|
define("INPUT_FILE", "./test_input_file.txt");
|
2021-02-28 13:34:12 +02:00
|
|
|
define("OUTPUT_FILE", "./example.enc.php");
|
|
|
|
define("DEC_OUTPUT_FILE", "./example.dec.php");
|
|
|
|
|
2021-02-28 13:55:29 +02:00
|
|
|
|
2021-02-28 13:34:12 +02:00
|
|
|
// Initialize the class
|
|
|
|
$lib = new kpcrypt();
|
|
|
|
|
2021-02-28 13:55:29 +02:00
|
|
|
$enc_start = round(microtime(true) * 1000);
|
|
|
|
|
2021-02-28 13:34:12 +02:00
|
|
|
// Encrypt the file
|
|
|
|
$lib->encryptFile(INPUT_FILE, OUTPUT_FILE);
|
|
|
|
|
2021-02-28 13:55:29 +02:00
|
|
|
$enc_end = round(microtime(true) * 1000) - $enc_start;
|
|
|
|
|
|
|
|
$dec_start = round(microtime(true) * 1000);
|
|
|
|
|
2021-02-28 13:34:12 +02:00
|
|
|
// Decrypt the file as well
|
2021-02-28 13:55:29 +02:00
|
|
|
$lib->decryptFile(OUTPUT_FILE, DEC_OUTPUT_FILE);
|
|
|
|
|
|
|
|
$dec_end = round(microtime(true) * 1000) - $dec_start;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* NOTE: You can also compress the output using gzip
|
|
|
|
*/
|
2021-02-28 13:34:12 +02:00
|
|
|
|
2021-02-28 13:55:29 +02:00
|
|
|
echo "\n\n";
|
|
|
|
echo "Input File Size: " . filesize(INPUT_FILE) / 1024 / 1024 . "Mb";
|
|
|
|
echo "\n";
|
|
|
|
echo "Output File Size: " . filesize(OUTPUT_FILE) / 1024 / 1024 . "Mb";
|
|
|
|
echo "\n";
|
|
|
|
echo "Peak Memory: " . memory_get_peak_usage() / 1024 / 1024 . "Mb"; // Check the memory in kb
|
|
|
|
echo "\n";
|
|
|
|
echo "Encryption Time: $enc_end ms\n"; // 9700k = ~210ms
|
|
|
|
echo "\n";
|
|
|
|
echo "Decryption Time: $dec_end ms\n";
|
|
|
|
echo "\n\n";
|
|
|
|
$errors = $lib->getErrors();
|
|
|
|
echo "Errors: " . ( !empty($errors) ? "\n" . json_encode($errors, JSON_PRETTY_PRINT) : "No Errors!");
|