Как отправить вектор зашифрованного текста (PIRQuery) через сокеты? ⇐ C++
Как отправить вектор зашифрованного текста (PIRQuery) через сокеты?
I try to create a socket communication for the FastPIR protocol.
The client side have a PIRQuery query which is a std::vectorseal::Ciphertext type that want to send it to the server.
How can I send the query to the server ? and how the server will receive it ?
I try to serialize the query with
//serealization of the query std::vector serializedQuery; for (const auto& ciphertext : query){ // Serialize each ciphertext std::ostringstream oss; ciphertext.save(oss, seal::compr_mode_type::none); std::string ciphertextStr = oss.str(); // Convert size to bytes and append before the ciphertext uint64_t size = ciphertextStr.size(); serializedQuery.insert(serializedQuery.end(), reinterpret_cast(&size), reinterpret_cast(&size) + sizeof(uint64_t)); // Append the ciphertext serializedQuery.insert(serializedQuery.end(), ciphertextStr.begin(), ciphertextStr.end()); } and in the server side it'll deserialize
PIRQuery deserializePIRQuery(const std::vector& serializedQuery, seal::SEALContext& context) { std::vector query; size_t currentIndex = 0; while (currentIndex < serializedQuery.size()) { // Extract the size of the next ciphertext uint64_t size; std::memcpy(&size, serializedQuery.data() + currentIndex, sizeof(uint64_t)); currentIndex += sizeof(uint64_t); // Extract the ciphertext std::vector ciphertextBytes(serializedQuery.begin() + currentIndex, serializedQuery.begin() + currentIndex + size); std::istringstream iss(std::string(ciphertextBytes.begin(), ciphertextBytes.end())); seal::Ciphertext ciphertext; ciphertext.load(context, iss); query.push_back(ciphertext); currentIndex += size; } return query; } But it doesn't work.
Источник: https://stackoverflow.com/questions/781 ... ia-sockets
I try to create a socket communication for the FastPIR protocol.
The client side have a PIRQuery query which is a std::vectorseal::Ciphertext type that want to send it to the server.
How can I send the query to the server ? and how the server will receive it ?
I try to serialize the query with
//serealization of the query std::vector serializedQuery; for (const auto& ciphertext : query){ // Serialize each ciphertext std::ostringstream oss; ciphertext.save(oss, seal::compr_mode_type::none); std::string ciphertextStr = oss.str(); // Convert size to bytes and append before the ciphertext uint64_t size = ciphertextStr.size(); serializedQuery.insert(serializedQuery.end(), reinterpret_cast(&size), reinterpret_cast(&size) + sizeof(uint64_t)); // Append the ciphertext serializedQuery.insert(serializedQuery.end(), ciphertextStr.begin(), ciphertextStr.end()); } and in the server side it'll deserialize
PIRQuery deserializePIRQuery(const std::vector& serializedQuery, seal::SEALContext& context) { std::vector query; size_t currentIndex = 0; while (currentIndex < serializedQuery.size()) { // Extract the size of the next ciphertext uint64_t size; std::memcpy(&size, serializedQuery.data() + currentIndex, sizeof(uint64_t)); currentIndex += sizeof(uint64_t); // Extract the ciphertext std::vector ciphertextBytes(serializedQuery.begin() + currentIndex, serializedQuery.begin() + currentIndex + size); std::istringstream iss(std::string(ciphertextBytes.begin(), ciphertextBytes.end())); seal::Ciphertext ciphertext; ciphertext.load(context, iss); query.push_back(ciphertext); currentIndex += size; } return query; } But it doesn't work.
Источник: https://stackoverflow.com/questions/781 ... ia-sockets
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Расхождение между выводом зашифрованного текста в C# и Python с использованием режима AES ECB
Anonymous » » в форуме C# - 0 Ответы
- 19 Просмотры
-
Последнее сообщение Anonymous
-