How to save ckks's Ciphertext in database?

I’m working on an implementation of an encrypted database on the cloud.And I want to save the ckks ckks’s Ciphertext in postgresql.But I found that the ckks ciphertext serialization exists in the txt file. I want to ask if it is possible to transmit and store the ciphertext in the database.

1 Like

Would it be possible to get the binary/ json data directly and store that? As opposed to writing to a file and then trying to store that? And if it’s not would you not just load in the text file to get the binary/json data then write that to the DB?

To the point raised by @iquah , one can just write a serialization to a stream, e.g., a string stream. @hamm, let us know if you want us point to an example.

Let me add to my colleagues’ points @iquah and @ypolyakov. I have extensive experience with serializing OpenFHE crypto objects for interprocess communications (IPC) between heavyweight processes (lightweight threads share memory space so they don’t need serialization). Binary is always smaller, so I use that. There are samples of serialization used for IPC in the older PALISADE repo here – it is applicable as there are not many differences at the api level between that and PALISADE. In that repo we show how to serialize to a stringstream, and then use the underlying C string as a “buffer” that you can then do whatever you want with (I believe there are both file based and socket based comms examples). CEREAL is the code we use to serialize our objects automagically, and that is what requires the C++ stream I/O. So if your postgresql data base is able to accept a binary buffer, you can use that directly in your application code (sorry I am not a dB guy). The alternative is to write that buffer to disk then manipulate it from there – it all depends on your use case. Note that usually we also capture the crypto context and public keys at the same time, as a ciphertext alone is not useful unless there is a crypto context and appropriate keys on the other end.

We plan to migrate the serial examples repo to OpenFHE in the future. it just has not been high on the list.

1 Like

@hamm Do you have any directly related followup questions? If not can I mark this as solved?