HElib icon indicating copy to clipboard operation
HElib copied to clipboard

Write Context to stringstream and readfrom stringstream but the generated seckey cannot be used in decryption

Open DylanWangWQF opened this issue 3 years ago • 0 comments

Hi, I have a question, when I generate a new context by reading from stringstream, these two context should be equal. But if I encrypt the vector using the oldContext.publickey, then decrypt it using the newContext.seckey. It failed due to different context. @dubek @fionser @faberga Could you give me some suggestions?

context.writeTo(ss);
Context newContext = Context::readFrom(ss);

SecKey secret_key(newContext);
secret_key.GenSecKey();
addSome1DMatrices(secret_key);
const PubKey& public_key = secret_key;
const helib::EncryptedArray& newEa = newContext.getEA();

vector<long> inputtest(256);
    for (long i = 0; i< 256; i++) {
        inputtest[i] = i;
    }
    
cout << inputtest << endl;
Ctxt inputCtxt(meta.data->publicKey);
ea.encrypt(inputCtxt, meta.data->publicKey, inputtest);
    
vector<long> outputtest1;
newEa.decrypt(inputCtxt, secret_key, outputtest1); // error: cannot decrypt due to different context

DylanWangWQF avatar Jun 24 '21 12:06 DylanWangWQF