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_new = CreateKey::generateRandomKey(); print "Secret Key NEW: " . $key_new . "
"; // for reproducable test results $key = 'e475c19b9a3c8363feb06b51f5b73f1dc9b6f20757d4ab89509bf5cc70ed30ec'; print "Secret Key: " . $key . "
"; // test text $text_string = "I a some deep secret"; $text_string = "I a some deep secret ABC"; // $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: " . print_r($cuuid, true) . "
"; print "LAST ERROR: " . $db->dbGetLastError(true) . "
"; // read back $res = $db->dbReturnRowParams( <<" . Support::prAr($res) . "
"; if ($res === false) { echo "Failed to run query
"; } else { if (hash_equals($string_hashed, $res['pg_digest_text'])) { print "libsodium and pgcrypto hash match
"; } if (hash_equals($string_hmac, $res['pg_hmac_text'])) { print "libsodium and pgcrypto hash hmac match
"; } } $encryptedMessage_template = <<getLiteralData()->getData(); print "Pg decrypted PHP: " . $decrypted . "
"; if ($decrypted == $text_string) { print "Decryption worked
"; } } catch (\Exception $e) { print "Error decrypting message: " . $e->getMessage() . "
"; } // do compare for PHP and pgcrypto settings print ""; // __END__