Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql pqxx byteA和二进制字符串数据读取_Postgresql_Libpqxx_Bytea - Fatal编程技术网

Postgresql pqxx byteA和二进制字符串数据读取

Postgresql pqxx byteA和二进制字符串数据读取,postgresql,libpqxx,bytea,Postgresql,Libpqxx,Bytea,我在PostGreSQL数据库和加密数据方面遇到了一些问题。我用一个河豚算法加密字符串,得到二进制数据作为回报。此二进制文件可以包含\0和一些其他scape序列 我以这种方式存储数据: `pqxx::binarystring destinatary(encryptedData);` 然后我这样读: pqxx::binarystring bsmsg(r[0]["message"]); encryptedData =bsmsg.get(); 问题是,有时数据会完美地返回,但在其他情况下,数据会在

我在PostGreSQL数据库和加密数据方面遇到了一些问题。我用一个河豚算法加密字符串,得到二进制数据作为回报。此二进制文件可以包含\0和一些其他scape序列

我以这种方式存储数据:

`pqxx::binarystring destinatary(encryptedData);`
然后我这样读:

pqxx::binarystring bsmsg(r[0]["message"]);
encryptedData =bsmsg.get();
问题是,有时数据会完美地返回,但在其他情况下,数据会在返回后正确地返回,并带有一些垃圾。关于我应该修改写入/读取的方向以避免将这种奇怪的数据添加到加密字符串中,有什么线索吗

我做的另一个尝试是以这种方式存储数据:

pqxx::binarystring msg(testMsg,testMsgsize);
同样的结果

编辑:根据要求,进行了一些日志研究: 我在研究这个价值观:

std::string encryptedData;
    bf.Encrypt(&encryptedData, ""); // THIS IS $4
    const void * testMsg = encryptedData.c_str();
    size_t testMsgsize = encryptedData.size();
    pqxx::binarystring msg(testMsg,testMsgsize);
    bf.Encrypt(&encryptedData, "yo"); //$5
    pqxx::binarystring destinatary(encryptedData);
    bf.Encrypt(&encryptedData, "yomaaaaaaaaaaaaaaaaslargo");//$6
    pqxx::binarystring owner(encryptedData);
    bf.Encrypt(&encryptedData, "123A@u");//$7
    pqxx::binarystring key(encryptedData);
让他们和其他人一起进入

execute addUnconfirmedInvitation: INSERT INTO friendnotices (ownerserver, type, daterecieved, message, destinatary, owner, internaldata, state, internaldataaux) VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9)
2014-08-11 17:12:32 CEST DETAIL:  parameters: $1 = 'invite.server()', $2 = 'invitation', $3 = '2014-08-11', $4 = '_(\351\204\376L\036Z', $5 = 'yo\002\002', $6 = 'p\010\224\254m\243\370\177R\222\314\022e/\005*;~\254\2075\205\363\375o\001', $7 = '\375\271\305v\272\036_\377\006\006\006\006', $8 = 'f', $9 = '\372f'' :w\037\312\005\005'
奇怪的是。。通过再次创建相同的变量,使用$5和$6进行搜索,我得到了正确的行

2014-08-11 17:22:35 CEST LOG:  execute searchUnconfirmedInvitation: SELECT * FROM friendnotices WHERE (destinatary=$1) AND (owner = $2) AND (type = $3) AND (ownerserver = $4)
2014-08-11 17:22:35 CEST DETAIL:  parameters: $1 = 'yo\002\002', $2 = 'p\010\224\254m\243\370\177R\222\314\022e/\005*;~\254\2075\205\363\375o\001', $3 = 'invitation', $4 = 'invite.server()'
但如果我尝试打印我之前显示的字符串:

pqxx::binarystring bsmsg(r[0]["message"]);
        encryptedData =bsmsg.get();
        bf.Decrypt(&clearData, encryptedData);
        pqxx::binarystring bskey(r[0]["internaldata"]);
        encryptedData =bskey.get();
        bf.Decrypt(&clearData, encryptedData);
        pqxx::binarystring des(r[0]["destinatary"]);
        encryptedData =des.get();
        bf.Decrypt(&clearData, encryptedData);
        pqxx::binarystring own(r[0]["owner"]);
        encryptedData =own.get();
        bf.Decrypt(&clearData, encryptedData);
这是我得到的(3次尝试):


随着更多的尝试,一切都在继续改变。我最终可以在第一个属性中获得正确的“”。第一次尝试时正确显示的属性将始终正确显示。

好的,我想我已经解决了这个问题。似乎pqxx::binarystring::get没有在读取结束时设置\0,这导致了随机行为。通过将binaryString::get替换为binaryString::str似乎可以解决这个问题。您可以使用方法str()而不是get():


如果您可以让库执行底层SQL,这将非常有用—在这里启用
log\u语句='all'
通常很有用。(虽然我不会说
libpqxx
,所以我不确定我能帮上什么忙)。谢谢你的回复。只是花了一些时间来配置postgresql server和尝试一些事情。日志没有显示对我有用的东西。编辑了这篇文章,提供了更多关于u所说的日志和一些测试用例的信息。
"���"       //this shouls be ""
"123A@u"    //this is right
"yo"        //this is right   
"yomaaaaaaaaaaaaaaaaslargoy" //i used this as search criteria.. but the last y isnt correct! 
"���"    //second try
"123A@u" 
"yo" 
"yomaaaaaaaaaaaaaaaaslargo1" //wow... now is a 1
"���"  //third try
"123A@u" 
"yo" 
"yomaaaaaaaaaaaaaaaaslargo"  //this time this is correct :?
encryptedData =bsmsg.get();
-> encryptedData =bsmsg.str();