Worked some more on the example, still wanna add a % increse in size and clean the lib to feature a memory cleaning of all of the variables that it doesn't need

This commit is contained in:
Daniel Legt 2021-02-27 14:14:26 +02:00
parent 5051a2596e
commit a1833a238c
1 changed files with 26 additions and 1 deletions

View File

@ -8,5 +8,30 @@ if ( empty($config) || empty($config['key']) || empty($config['input']) ) {
exit(1); exit(1);
} }
ini_set('memory_limit','1G');
function limitStringSize($str, $amount = 20) {
if (strlen($str) > $amount)
$str = substr($str, 0, $amount) . '...';
return $str;
}
// Echo out the results // Echo out the results
echo $encryptedData = encryptData($config['input'], $config['key'], 'AES-256-CBC', TRUE); $encryptedData = encryptData($config['input'], $config['key'], 'AES-256-CBC', TRUE);
echo "Encrypted: " . limitStringSize($encryptedData);
echo "\n";
echo "Decrypted: " . limitStringSize(decryptData($encryptedData, $config['key']));
echo "\n";
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";