我以这种方式存储数据:
`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);
并将em设置为
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次尝试):
"���" //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 :?
随着更多的尝试,一切都在继续变化。我终于可以得到正确的""进入第一个属性。第一次尝试时正确显示的属性将始终正确显示。
答案 0 :(得分:0)
好的,我想我已经解决了。似乎pqxx :: binarystring :: get在读取结束时没有设置\ 0,这会导致随机行为。它似乎是通过用binaryString :: str
替换binaryString :: get来解决的答案 1 :(得分:0)
您可以使用方法str()而不是get():
encryptedData =bsmsg.get();
-> encryptedData =bsmsg.str();