How-To: Decrypt Output Data
After receiving the encrypted output from a query request, the end-user must decrypt the message using their Secret Key. This guide explains how to perform the decryption process.
Prerequisites
import lattica_common.app_api as agent_app
# Notice your query token expires in 30 days
query_token = "the_query_token_you_got_using_the_generate_user_token"
# user_data is a tuple of:
# (serialized_context, serialized_secret_key, serialized_homseq)
# which you need for encrypting the query and querying the model
user_data = agent_app.user.query_offline_phase(query_token)
dataset = pd.read_csv('data/mnist_data.csv').values / 255
data = torch.tensor(dataset[0])
serialized_ct = agent_app.user.encrypt(user_data, dataset)
serialized_ct_res = agent_app.user.apply_hom_pipeline(serialized_ct)
serialized_pt = agent_app.user.decrypt(serialized_ct_res)import { LatticaQueryClient } from 'lattica-query-client';
const client = new LatticaQueryClient('your-jwt-query-token');
// Uploaded the EK
const initialized = await client.init();
if (!initialized) {
console.error('Initialization failed: The EK was not successfully uploaded.');
throw new Error('EK upload failed.');
}
console.log('EK uploaded successfully.');
// The data you want to encrypt
const inputTensor = ....;
// Encrypt the provided input
const ct = await client.encrypt(pt);
// Send your encrypted query to and get a resopnse
const ct_res = await latticaClient.apply_query(ct);
// Decrypt your query result
const pt_res = await latticaClient.decrypt(ct_res);Last updated