From 9d16171dcac2bc3fb96706eef02e8fe6db1a3029 Mon Sep 17 00:00:00 2001 From: Kato Twofold Date: Sun, 28 Feb 2021 11:08:22 +0200 Subject: [PATCH] * Updated README with apropiate example --- README.md | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 06a858b..7b83d38 100644 --- a/README.md +++ b/README.md @@ -7,22 +7,46 @@ The Project is a simple php encryption wrapper, not even a library, the whole po Simply use the provided functions from the lib.php file, you can simply import it into any project using that file. ```php -require_once("/path/to/the/file/kpcrypt/lib.php") +require_once("./lib.php"); +@require_once("./config.inc.php"); -$input = "Super secret string!"; -$key = "My key to encrypt the string with"; +// Check if the config succesfully loaded, or if the mandatory config fields are missing. +if ( empty($config) || empty($config['key']) || empty($config['input']) ) { + echo "Please copy the config.sample.inc.php to config.inc.php and change the configuration to match your needs."; + exit(1); +} -// Encrypt the data, the cipher can be easily changed, the integrity_check is recommended to be left to TRUE even if it takes some extra time to decrypt and check. -$encryptedData = encryptData($input, $key, 'AES-256-CBC', TRUE); +ini_set('memory_limit','1G'); -// Echo out the encrypted values to check them +function limitStringSize($str, $amount = 20) { + if (strlen($str) > $amount) + $str = substr($str, 0, $amount) . '...'; + return $str; +} -echo "Encrypted: " . $encryptedData; +$kpc = new kpcrypt($config['key']); + +echo "Key: " . $kpc->getKey() . " \n"; + +// Echo out the results +$encryptedData = $kpc->encryptData($config['input'], 'AES-256-CBC', TRUE); + +echo "Encrypted: " . limitStringSize($encryptedData); echo "\n"; -echo "Decrypted: " . decryptData($encryptedData, $key); +echo "Decrypted: " . limitStringSize($kpc->decryptData($encryptedData)); echo "\n"; -echo "Peak Memory: " . memory_get_peak_usage() / 1024 . "Kb"; // Check the memory in kb +echo "Peak Memory: " . memory_get_peak_usage() / 1024 / 1024 . "Mb"; // Check the memory in kb +echo "\n\n"; +// Calculate the string size increse +$inputSize = strlen($config['input']); // Bytes +$outputSize = strlen($encryptedData); // Bytes + +// Echo out sizing information +echo "Sizeof input: " . strlen($config['input']) . "\n"; // Bytes +echo "Sizeof output:" . strlen($encryptedData) . "\n"; // Bytes + +echo "\n"; ``` ## License