AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-9852762

Gary's questions

Martin Hope
Gary
Asked: 2025-03-31 14:32:19 +0800 CST

有没有通过同一个类的相对位置来选择子元素的方法?[重复]

  • 5
此问题这里已有答案:
我可以将 :nth-child() 或 :nth-of-type() 与任意选择器结合使用吗? (10 个答案)
8 小时前关闭。

此示例提供了选择“subhead”类的第一个、第二个和第三个子元素的预期结果。但是,我的问题是,是否有任何选择方法可以选择“subhead”类的第一个、第二个和第三个出现,而不管其在父级中的确切子位置,以便在事先不知道这些位置时可以工作;我们可以使用位置 1,2,3 而不是 1,3,5,因为它不知道每个子标题之间有多少个兄弟元素?

谢谢。

div.scrl_can * {
  height:25px;
  border: 1px solid black;
}
.subhead:nth-of-type(1) {
  background-color: blue;
}
.subhead:nth-of-type(3) {
  background-color: green;
}
.subhead:nth-of-type(5) {
  background-color: yellow;
}
<div id="main">
  <div>
    <div>
      <div class="scrl_can">
        <div class="subhead"></div>
        <div></div>
        <div class="subhead"></div>
        <div></div>
        <div class="subhead"></div>
        <div></div>
      </div>
    </div>
  </div>
</div>

javascript
  • 1 个回答
  • 44 Views
Martin Hope
Gary
Asked: 2025-03-05 15:03:00 +0800 CST

OpenSSL aes-256-gcm tag_length 和 aad?

  • 5

在 PHP 中使用 aes-256-gcm 进行OpenSSL 加密时,是tag_length编码器选择的值还是由方法选择并像使用一样返回给指针tag?它读取的值可以在 4 到 16 之间。加密函数中输入的 tag_length 是否保证是返回的标签的长度?

此外,如何aad使用(“额外的经过验证的数据”)以及为什么要使用它?

谢谢。

openssl
  • 1 个回答
  • 82 Views
Martin Hope
Gary
Asked: 2025-02-25 13:56:35 +0800 CST

加密无法通过单个函数调用完成的大型文件的正确方法是什么?

  • 6

我一直在使用https://www.php.net/manual/en/function.openssl-encrypt.php上的加密示例(从 CLI)进行实验, 并想知道如何处理较大的文件,例如几 GB 的 SQLite 数据库文件。在同一个 PHP 页面上按照此示例操作之前,我遇到了内存分配错误。

我反应慢,但最终还是让它在 3 GB 的 SQLite 数据库上运行起来。我认为如果设置 options=0,则 base64 是默认值,我尝试使用为简单情况提供的最新示例以及为使用 OPENSSL_RAW_DATA 选项的大型文件提供旧示例。

我的问题是,这篇八年前的文章中给出的方法仍然是正确的方法吗?一些示例给出了 7.1 版本之前和之后的版本。

可以使用加密块的前 16 个字节作为下一个初始化向量吗?

每次加密/解密的块数重要吗?是否应该使用适合最大内存分配的最大大小,还是其他什么?

<?php
//$key should have been previously generated in a cryptographically safe way, like openssl_random_pseudo_bytes
$key = "abcd1234dcba4321";
$cipher = "aes-256-cbc";
$feBlocks = 10000;
$fpPlain = fopen("../Database/filename.db",'rb');
$fpEncrypt = fopen("encrypted.enc", 'wb');
if (in_array($cipher, openssl_get_cipher_methods()))
{
    $ivlen = openssl_cipher_iv_length($cipher);
    $iv = openssl_random_pseudo_bytes($ivlen);
    // Put the initialzation vector to the beginning of the file
    fwrite($fpEncrypt, $iv);
    while (!feof($fpPlain)) {
        $plaintext = fread($fpPlain, $ivlen * $feBlocks);
        $ciphertext = openssl_encrypt($plaintext, $cipher, $key, $options=OPENSSL_RAW_DATA, $iv);
        // Use the first 16 bytes of the ciphertext as the next initialization vector
        $iv = substr($ciphertext, 0, $ivlen);
        fwrite($fpEncrypt, $ciphertext);
    }
    fclose($fpPlain);
    fclose($fpEncrypt);
}

  $fpEncrypt = fopen("encrypted.enc", 'rb');
  $fpPlain = fopen("decrypted.db",'wb');
  $ivlen = openssl_cipher_iv_length($cipher);
  // Get the initialzation vector from the beginning of the file
  $iv = fread($fpEncrypt, $ivlen);
  while (!feof($fpEncrypt)) {
     // we have to read one block more for decrypting than for encrypting
     $ciphertext = fread($fpEncrypt, $ivlen * ($feBlocks+1));
     $plaintext = openssl_decrypt($ciphertext, $cipher, $key, $options=OPENSSL_RAW_DATA, $iv);
     // Use the first 16 bytes of the ciphertext as the next initialization vector
     $iv = substr($ciphertext, 0, $ivlen);
     fwrite($fpPlain, $plaintext);
  }
  fclose($fpEncrypt);
  fclose($fpPlain);
  • 1 个回答
  • 78 Views
Martin Hope
Gary
Asked: 2023-10-27 02:26:06 +0800 CST

用于准备语句缓存的“紧凑”查询字符串?

  • 5

如果 SQL 查询存储在跨多行声明的 Tcl 变量中以保持可读性,请使用:

set ::SQL::QueryName {
}

并使用执行

db eval $::SQL::QueryName

是否应该对查询字符串进行某些操作,因为它们将成为准备好的语句缓存中的键?

例如,以行继续符结束每一行\,使用append语句构建,或者在它们上运行某种类型的映射以形成没有不必要空格的单行?

之前没有考虑过它,因为缓存在 Tcl SQLite 中是自动的。

谢谢。

sqlite
  • 1 个回答
  • 27 Views
Martin Hope
Gary
Asked: 2023-10-08 09:03:42 +0800 CST

使用 incrblob 根据文本字符串中的字符位置确定 BLOB 段中的字节位置?

  • 6

我的问题涉及这种情况。我在 Tcl 接口中使用 SQLite 的增量 blob I/O 将文本存储为 BLOB。数据库中的另一个表包含指向此 BLOB 段的指针数据行。由于 Tcl 通道寻求字节位置而不是字符位置(我认为这是常见的,我不是批评 Tcl),因此我需要跟踪每个指针的 byte_start、char_start、byte_length、char_length。

传入 Tcl 的请求指示需要将现有指针(不是实际的缓冲区数据,而只是指针本身)拆分为两个指针,从某个字符位置开始。该请求来自 UI,并且该代码对字节位置一无所知,并且实际上对 BLOB 一无所知。

因此,我需要提取 BLOB 段,将其转换为文本,并确定两个新片段中至少一个的字节长度,并使用该信息来确定两个新指针的起始字节和字节长度。

我打算在 SQLite 中使用如下所示的内容,但是根据 Hipp 博士的说法,必须将整个 BLOB 读入内存才能在 BLOB 上使用 substr。

select
   octet_length(
      substr(
         cast(
            substr(
               buffer,
               byte_start,
               byte_length
            ) as text
         ),
         1,
         :len
      )
   )
from
   mem.pt_buffers
where
       doc_id = :doc_id
   and buffer_id = :buffer_id_s
;

因此,我在 Tcl 中使用 incrblob,如本示例所示。它似乎生成了正确的结果,但似乎也需要做很多工作。例如,从 BLOB 中提取内容只是为了确定分割点的字符位置的字节位置。内容不会以其他方式使用,BLOB 也不会被修改。如果不存在 UI 未知字节位置的问题,则不需要提取内容,并且操作将只是算术运算。

我的问题是:

  1. 我这样做是否很艰难?有更简单的方法吗?
  2. 可以/应该更多的工作直接在 SQLite 中完成吗?

感谢您考虑我的问题。

package require sqlite3
sqlite3 db
db eval {create table test (id integer, data blob);}
db eval {insert into test values (1, zeroblob(100));}
puts [db eval {select id, cast(data as text) from test;}]
# 1 {}

# Previously, a request had to come in to append this string
# to the BLOB; to the non-zero portion, anyway. This is re-
# quired set-up for the question.
set fdBlob [db incrblob main test data 1]
chan configure $fdBlob -translation binary -buffering none
set bindata [encoding convertto utf-8\
     {This is some הַ / נָּבִ֑יא text cast as a BLOB.}]
chan puts -nonewline $fdBlob $bindata

puts [db eval {
   select
      length(data),
      length(cast(data as text)),
      length(:bindata)
   from
      test
   ;
}]
# 100 47 57

# Pre-split pointer data:
# piece  char_start char_length byte_start byte_length
# -----  ---------- ----------- ---------- -----------
# orig        0          47           0         57

# Request comes in to split the pointer at the 27th character
# into two pointers: characters 0-26 and 27-end.

# Retrieve the segment of the BLOB. Have to retrieve the full
# piece because do not know where to split the bytes. Convert
# from binary to text. Note [chan read numChars] reads chars,
# but since channel is configured as binary, same as bytes.
chan seek $fdBlob 0 start
set data [encoding convertfrom utf-8 [chan read $fdBlob 57]]

# Split the piece. Need only one or the other, not both.
set frontEnd [string range $data 0 26]
set tailEnd [string range $data 27 end]
puts "\"$frontEnd\" \"$tailEnd\""
# "This is some הַ / נָּבִ֑יא " "text cast as a BLOB."

# Convert the substring back to binary and determine byte length.
set frontEndByteLen [string length [encoding convertto utf-8 $frontEnd]]
set tailEndByteLen [expr {57-$frontEndByteLen}]
puts "Front-end data: byte_start: 0 byte_length $frontEndByteLen"
puts "Tail-end data: byte_start: $frontEndByteLen byte_length $tailEndByteLen"
# Front-end data: byte_start: 0 byte_length 37
# Tail-end data: byte_start: 37 byte_length 20

# Test it out by seeking to the start byte and extracting the tail-end.
chan seek $fdBlob $frontEndByteLen start
set data [encoding convertfrom utf-8 [chan read $fdBlob $tailEndByteLen]]
puts $data
# text cast as a BLOB.

# Then the pointer table will have these new pieces inserted.
# piece  char_start char_length byte_start byte_length
# -----  ---------- ----------- ---------- -----------
# front       0          27           0         37
# tail       27          20          37         20

sqlite
  • 1 个回答
  • 32 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve