【问题标题】:DataStax C/C++ Driver for Apache Cassandra: Blob Conversion (GCrypt Crypto Key) Issue适用于 Apache Cassandra 的 DataStax C/C++ 驱动程序:Blob 转换(GCrypt 加密密钥)问题
【发布时间】:2014-11-11 23:37:48
【问题描述】:

我成功地将 GCrypt 加密密钥 (0x135aa10) 作为 CassBytes 结构添加到 Cassandra 集群。请参阅 Cassandra C++ 包括:https://github.com/datastax/cpp-driver/blob/1.0/include/cassandra.h

// Create PSK Blob
CassBytes pskey_blob;
pskey_blob = cass_bytes_init((const cass_byte_t*) pskey, sizeof(pskey));

// Check that key BLOBED correctly
gcry_sexp_t tmpkey = (gcry_sexp_t)pskey_blob.data; //This correctly returns GCrypt Crypto Key (0x135aa10)

// Bind PSK Blob & Execute Statment
cass_statement_bind_bytes(statement, 0, pskey_blob);
future = cass_session_execute(session, statement);
cass_future_wait(future);

然后我从 Cassandra 检索 GCrypt 加密密钥,如下所示:

// Get Payload Secret Key
CassBytes pskey_blob;
cass_value_get_bytes(cass_row_get_column(row, 0), &pskey_blob);

if (pskey_blob.size != 0) {
  pskey = (gcry_sexp_t)pskey_blob.data;
  std::cout << "pskey: " << pskey << std::endl;
}

blob 数据在 CassBytes 结构 (pskey_blob.data) 中返回为 0x7f7fb00028a4,正确大小为 8 (pskey_blob.size)。似乎 Cassandra 将我的原始 unit8_t 类型 GCrypt 加密密钥 (0x135aa10) 的 HEX 表示形式返回为 HEX (0x7f7fb00028a4)。

有谁知道如何将其从 Cassandra 字节表示形式转换为 GCrypt 加密密钥?

【问题讨论】:

    标签: c++ cassandra blob driver


    【解决方案1】:

    在上面的代码中,您似乎只是将 pskey 的地址复制到 Cassandra,而不是密钥的内容。

    我只是粗略地查看了 GCrypt 文档,但看起来您可以使用 gcry_sexp_sprint()gcry_sexp_new()gcry_sexp_create()gcry_sexp_scan() 之一将 GCrypt S-Expr 打印/扫描到字符串缓冲区.

    在此处找到的文档:https://www.gnupg.org/documentation/manuals/gcrypt/Working-with-S_002dexpressions.html#Working-with-S_002dexpressions

    免责声明:我尚未编译或测试此代码。这只是可能可行的粗略概述。

    插入键可能如下所示:

    size_t length = gcry_sexp_sprint(pskey, GCRYSEXP_FMT_DEFAULT, NULL, 0); // Needed to get the length
    char* buffer = (char*)malloc(length);
    gcry_sexp_sprint(pskey, GCRYSEXP_FMT_DEFAULT, buffer, length);
    
    cass_statement_bind_string(statement, 0, cass_string_init2(buffer, length));
    future = cass_session_execute(session, statement);
    cass_future_wait(future);
    
    free(buffer);
    

    要 SELECT 键可能如下所示:

    CassString pskey_blob;
    cass_value_get_string(cass_row_get_column(row, 0), &pskey_blob);
    gcry_sexp_new(&pskey, pskey_blob.data, pskey_blog.length, 1); // Need to check the error here
    

    【讨论】:

      猜你喜欢
      • 2018-04-29
      • 2017-08-08
      • 2017-10-04
      • 2015-08-07
      • 2022-12-11
      • 2017-08-04
      • 2019-08-01
      • 2014-03-27
      • 2016-03-01
      相关资源
      最近更新 更多