LatticaAI Documentation
  • Welcome to LatticaAI
  • Conceptual Guide
  • Architecture Overview
    • Management Client
    • Query Client
  • Platform Workflows
    • Account Management
    • Model Management
    • User Access Management
    • Query Submission
    • Credit Management
    • Worker Management
  • How-To Guides
    • Client Installation
      • How-To: Install Management Client
      • How-To: Install Query Client
    • Model Lifecycle
      • How-To: Deploy AI model
      • How-To: Modify AI Model Settings
    • Access Control
      • How-To: Create User Access Token
      • How-To: Modify User Access Token Setting
      • How-To: Remove Token's Assignment
      • How-To: Assign Token to Model
      • How-To: See List of Tokens
    • Resource Management
      • How-To: Start Worker
      • How-To: Stop Worker
      • How-To: Monitor Worker Performance
    • Secure Query Processing
      • How To: Upload Evaluation Key
      • How-To: Encrypt Input Message
      • How To: Execute Query
      • How-To: Decrypt Output Data
      • How-To: Encrypt, Execute, and Decrypt in One Step
    • Account and Finance Operations
      • How-To: View Payment Transaction History
      • How-To: Update Account Information
      • How-To: View Credit Balance and Add Credit to Your Account
      • How-To: Monitor Balance and Usage
  • Demo Tutorials
    • Image Sharpening with LatticaAI Demo Tutorial
    • Sentiment Analysis with LatticaAI Demo Tutorial
    • Health Analysis with LatticaAI Demo Tutorial
    • Digit Recognition with LatticaAI Demo Tutorial
    • Zooming Into Each Step of Demo Run with LatticaAI flow
Powered by GitBook
On this page

Was this helpful?

  1. How-To Guides
  2. Secure Query Processing

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

  1. Encrypted Output: The output must be retrieved from a successful query execution.

  2. Secret Key: The user’s Secret Key is required to decrypt the message.

Use the following code snippet to decrypt the output data. Provide the User Access Token and the encrypted output message as parameters:

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);
PreviousHow To: Execute QueryNextHow-To: Encrypt, Execute, and Decrypt in One Step

Last updated 3 months ago

Was this helpful?

This step focuses on a specific part of the query process: Output message decryption. If you prefer to perform encryption, query execution, and decryption in a single command, refer to [How-To: ].

Encrypt, Execute, and Decrypt in One Step