This repository has been archived on 2024-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
Go to file
Daniel Legt defe60efb9 * Fixed an error handler 2021-02-28 14:11:28 +02:00
.gitignore + File Decryption 2021-02-28 14:10:12 +02:00
README.md Typo fix 2021-02-28 11:10:23 +02:00
config.sample.inc.php + README.md\n+ example.php\n + license 2021-02-27 13:52:14 +02:00
example-cli.php + README.md\n+ example.php\n + license 2021-02-27 13:52:14 +02:00
example-file.php + File Decryption 2021-02-28 14:10:12 +02:00
example.php + Added time to encrypt to the example.php 2021-02-28 13:56:50 +02:00
lib.php * Fixed an error handler 2021-02-28 14:11:28 +02:00
license + README.md\n+ example.php\n + license 2021-02-27 13:52:14 +02:00

README.md

About

The Project is a simple php encryption wrapper, not even a library, the whole point is that it has integrity checks on the encryption part which helps out quite a bit with errors.

Usage

Simply use the provided functions from the lib.php file, you can simply import it into any project using that file.

<?php
require_once("./lib.php");
@require_once("./config.inc.php");

// 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);
}

// The memory limit has been set so that we can pass it big strings and test how much it can/will use.
ini_set('memory_limit','1G');

function limitStringSize($str, $amount = 20) {
    if (strlen($str) > $amount)
        $str = substr($str, 0, $amount) . '...';
    return $str;
}

$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: " . limitStringSize($kpc->decryptData($encryptedData));
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";

License

The licensing of the project is the MIT license

Credit

Repository icon made by monkik from www.flaticon.com;