* Updated README with apropiate example

This commit is contained in:
Daniel Legt 2021-02-28 11:08:22 +02:00
parent e5f7264803
commit 9d16171dca
1 changed files with 33 additions and 9 deletions

View File

@ -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