From 531229e8b7e1fb6ed4d7d1ca0aee71e9db096f58 Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Mon, 7 Apr 2025 12:05:06 +0900 Subject: [PATCH] Add DB Encryption tests --- www/admin/class_test.db.encryption.php | 125 +++++++++++++++++++++++++ www/admin/class_test.php | 1 + 2 files changed, 126 insertions(+) create mode 100644 www/admin/class_test.db.encryption.php diff --git a/www/admin/class_test.db.encryption.php b/www/admin/class_test.db.encryption.php new file mode 100644 index 00000000..6d7701e2 --- /dev/null +++ b/www/admin/class_test.db.encryption.php @@ -0,0 +1,125 @@ + BASE . LOG, + 'log_file_id' => $LOG_FILE_ID, + 'log_per_date' => true, +]); +// db connection and attach logger +$db = new CoreLibs\DB\IO(DB_CONFIG, $log); +$db->log->debug('START', '=============================>'); + +$PAGE_NAME = 'TEST CLASS: DB QUERY ENCRYPTION'; +print ""; +print "" . $PAGE_NAME . ""; +print ""; +print '
Class Test Master
'; +print '

' . $PAGE_NAME . '

'; + +// encryption key +$key = CreateKey::generateRandomKey(); +print "Secret Key: " . $key . "
"; + +// test text +$text_string = "I a some deep secret"; +// +$crypt = new SymmetricEncryption($key); +$encrypted = $crypt->encrypt($text_string); +$string_hashed = Hash::hashStd($text_string); +$string_hmac = Hash::hashHmac($text_string, $key); +$decrypted = $crypt->decrypt($encrypted); + +print "String: " . $text_string . "
"; +print "Encrypted: " . $encrypted . "
"; +print "Hashed: " . $string_hashed . "
"; +print "Hmac: " . $string_hmac . "
"; + +$db->dbExecParams( + <<dbGetReturningExt('cuuid'); +print "INSERTED: $cuuid
"; +print "LAST ERROR: " . $db->dbGetLastError(true) . "
"; + +// read back +$res = $db->dbReturnRowParams( + <<" . Support::prAr($res) . "
"; + +// do compare + +print ""; + +// __END__ diff --git a/www/admin/class_test.php b/www/admin/class_test.php index 8772e07b..0e2d6ad4 100644 --- a/www/admin/class_test.php +++ b/www/admin/class_test.php @@ -95,6 +95,7 @@ $test_files = [ 'class_test.db.dbReturn.php' => 'Class Test: DB dbReturn', 'class_test.db.single.php' => 'Class Test: DB single query tests', 'class_test.db.convert-placeholder.php' => 'Class Test: DB convert placeholder', + 'class_test.db.encryption.php' => 'Class Test: DB pgcrypto', 'class_test.convert.colors.php' => 'Class Test: CONVERT COLORS', 'class_test.check.colors.php' => 'Class Test: CHECK COLORS', 'class_test.mime.php' => 'Class Test: MIME',