parent
f61cc7bba2
commit
cce2c58fc3
@ -0,0 +1,94 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
declare(strict_types=1); |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Robert Strutts <Robert@TryingToScale.com> |
||||||
|
* @copyright Copyright (c) 2022, Robert Strutts. |
||||||
|
* @license https://mit-license.org/ |
||||||
|
*/ |
||||||
|
|
||||||
|
namespace prj\mockup\controllers\app; |
||||||
|
|
||||||
|
class enc_ctrl { |
||||||
|
public $page_output; |
||||||
|
|
||||||
|
private function time_enc(array $levels): void { |
||||||
|
$enc = new \tts\services\encryption(); |
||||||
|
foreach($levels as $level) { |
||||||
|
echo "ENC: Level = $level <br>" . PHP_EOL; |
||||||
|
$enc->change_security_level($level); |
||||||
|
|
||||||
|
// $key = $enc->generate_valid_key(); |
||||||
|
$key = "51623a064210f9d3d5162d0885621f53"; |
||||||
|
echo "KEY Used: $key <br>" . PHP_EOL; |
||||||
|
|
||||||
|
$startTime = microtime(true); |
||||||
|
$data = $enc->encrypt($key, "Hello, World!"); |
||||||
|
echo "<br> $data <br>" . PHP_EOL; |
||||||
|
echo "Encrypt Time: " . number_format(( microtime(true) - $startTime), 4) . " Seconds\n"; |
||||||
|
|
||||||
|
$startTime = microtime(true); |
||||||
|
$decoded = $enc->decrypt($key, $data); |
||||||
|
echo "<br> $decoded <br>" . PHP_EOL; |
||||||
|
echo "Decrypt Time: " . number_format(( microtime(true) - $startTime), 4) . " Seconds\n"; |
||||||
|
echo "<hr><br>".PHP_EOL; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/* |
||||||
|
* Let's test the in-secure, Quicker encryption methods |
||||||
|
* These methods are good engough to make sure |
||||||
|
* data was not tampered with and hide it's contents |
||||||
|
* from spying eyes. |
||||||
|
*/ |
||||||
|
public function index() { |
||||||
|
$levels = ['lighting','blaze','quick','good']; |
||||||
|
$this->time_enc($levels); |
||||||
|
} |
||||||
|
|
||||||
|
// Let's test the secure encryption methods. |
||||||
|
public function slow() { |
||||||
|
$levels = ['good','normal','paranoid']; |
||||||
|
$this->time_enc($levels); |
||||||
|
} |
||||||
|
|
||||||
|
public function sodium() { // 0.0041 Seconds |
||||||
|
$crypto = new \tts\services\paragon_crypto\crypto(); |
||||||
|
// echo $crypto->a_single_key_maker(); |
||||||
|
$key = "oH5LUubQXkUgC2sXkxahLnzgcZokVFANyxAew+kOvuk="; |
||||||
|
|
||||||
|
$startTime = microtime(true); |
||||||
|
$data = $crypto->safe_encrypt("Hello, World!", $key, $crypto::single_key); |
||||||
|
echo "<br> $data <br>" . PHP_EOL; |
||||||
|
echo "Encrypt Time: " . number_format(( microtime(true) - $startTime), 4) . " Seconds\n"; |
||||||
|
|
||||||
|
// $data = "sJWIPEasG1W8ModZJKU8jOR78/i1qUZDl6nX5ew21ceOdEZHNDGwqCA1lD70GuIHP4DJEMQ="; |
||||||
|
|
||||||
|
$startTime = microtime(true); |
||||||
|
$decoded = $crypto->safe_decrypt($data, $key, $crypto::single_key); |
||||||
|
echo "<br> $decoded <br>" . PHP_EOL; |
||||||
|
echo "Decrypt Time: " . number_format(( microtime(true) - $startTime), 4) . " Seconds\n"; |
||||||
|
echo "<hr><br>".PHP_EOL; |
||||||
|
} |
||||||
|
|
||||||
|
public function sodium_pwd_test() { // 0.1233 Seconds |
||||||
|
$startTime = microtime(true); |
||||||
|
$c = new \tts\services\paragon_crypto\password_storage(); |
||||||
|
// $key = $c->generate_a_key(); |
||||||
|
$key = "9054695cc0f4080c15865de470f63ee993478b14c357eb910c815a4e0a1d4401"; |
||||||
|
|
||||||
|
$h = $c->hash("HelpMe", $key); |
||||||
|
var_dump( $c->verify("HelpMe", $h, $key) ); |
||||||
|
echo "Hashed PWD and Verified it: " . number_format(( microtime(true) - $startTime), 4) . " Seconds\n"; |
||||||
|
} |
||||||
|
|
||||||
|
public function pwd_test() { // 0.9281 Seconds |
||||||
|
$startTime = microtime(true); |
||||||
|
$db_hash = \tts\security::do_password_hash("HelpMe"); |
||||||
|
var_dump( \tts\security::do_password_verify("HelpMe", $db_hash) ); |
||||||
|
echo "Hashed PWD and Verified it: " . number_format(( microtime(true) - $startTime), 4) . " Seconds\n"; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
Loading…
Reference in new issue