diff --git a/src/mockup/controllers/app/enc_ctrl.php b/src/mockup/controllers/app/enc_ctrl.php index cae8c78..8fc4e53 100644 --- a/src/mockup/controllers/app/enc_ctrl.php +++ b/src/mockup/controllers/app/enc_ctrl.php @@ -12,6 +12,21 @@ namespace prj\mockup\controllers\app; class enc_ctrl { public $page_output; + + private function get_roles(): string { + $roles = ['roles'=>'admin, super, rw', 'name'=>'Bob']; + return json_encode($roles); + } + + private function show_roles(bool|string $in): void { + echo "
" . PHP_EOL; + if ($in === false) { + echo "Invalid cypher text"; + } else { + var_dump(json_decode($in, true)); + } + echo "
" . PHP_EOL; + } private function time_enc(array $levels): void { $enc = new \tts\services\encryption(); @@ -24,13 +39,13 @@ class enc_ctrl { echo "KEY Used: $key
" . PHP_EOL; $startTime = microtime(true); - $data = $enc->encrypt($key, "Hello, World!"); + $data = $enc->encrypt($key, $this->get_roles()); echo "
$data
" . PHP_EOL; echo "Encrypt Time: " . number_format(( microtime(true) - $startTime), 4) . " Seconds\n"; $startTime = microtime(true); $decoded = $enc->decrypt($key, $data); - echo "
$decoded
" . PHP_EOL; + $this->show_roles($decoded); echo "Decrypt Time: " . number_format(( microtime(true) - $startTime), 4) . " Seconds\n"; echo "

".PHP_EOL; } @@ -59,7 +74,7 @@ class enc_ctrl { $key = "oH5LUubQXkUgC2sXkxahLnzgcZokVFANyxAew+kOvuk="; $startTime = microtime(true); - $data = $crypto->safe_encrypt("Hello, World!", $key, $crypto::single_key); + $data = $crypto->safe_encrypt($this->get_roles(), $key, $crypto::single_key); echo "
$data
" . PHP_EOL; echo "Encrypt Time: " . number_format(( microtime(true) - $startTime), 4) . " Seconds\n"; @@ -67,11 +82,34 @@ class enc_ctrl { $startTime = microtime(true); $decoded = $crypto->safe_decrypt($data, $key, $crypto::single_key); - echo "
$decoded
" . PHP_EOL; + $this->show_roles($decoded); + echo "Decrypt Time: " . number_format(( microtime(true) - $startTime), 4) . " Seconds\n"; echo "

".PHP_EOL; } + public function storage() { + $key = "78a5011b9997cd03a28a3412c66565b7c32715b35e055d7abfc228236308d3b2"; + $sc = new \tts\services\paragon_crypto\sodium_storage($key); + + $startTime = microtime(true); + $encoded = $sc->encode("admin", $this->get_roles()); + echo "
$encoded
" . PHP_EOL; + echo "Encrypt Time: " . number_format(( microtime(true) - $startTime), 4) . " Seconds\n"; + + try { + $startTime = microtime(true); + $plain_text = $sc->decode("admin", $encoded); + + $this->show_roles($plain_text); + echo "Decrypt Time: " . number_format(( microtime(true) - $startTime), 4) . " Seconds\n"; + echo "

".PHP_EOL; + } catch (Exception $ex) { + // Handle the exception here + echo $ex->getMessage(); + } + } + public function sodium_pwd_test() { // 0.1233 Seconds $startTime = microtime(true); $c = new \tts\services\paragon_crypto\password_storage();