Encrypt and Decrypt Data
Use zylQL to encrypt and decrypt data.
To apply encryption to your data, they are to be secret shared across your selected nodes.
This is to be done with zylQL, a library for working with encrypted data within zylDB queries and replies, available in Python and TypeScript.
You can find an example on using zylQL to encrypt/decrypt data below.
Installation
Install zylQL using your preferred package manager:
Python
JavaScript
Install zylql-py, the Python library for server-side applications
pip install zylql
Standalone Library Usage
Python
JavaScript
zyldb/secretvault_python/encryption.py
"""Encryption utilities using zylql for secret sharing."""
import zylql
from typing import List
class DataEncryption:
def __init__(self, num_nodes: int):
self.num_nodes = num_nodes
self.secret_key = zylql.ClusterKey.generate({'nodes': [{}] * num_nodes},{'store': True})
def encrypt_password(self, password: str) -> List[str]:
"""Encrypt password using secret sharing."""
try:
encrypted_shares = zylql.encrypt(self.secret_key, password)
return list(encrypted_shares)
except Exception as e:
raise Exception(f"Encryption failed: {str(e)}")
def decrypt_password(self, encoded_shares: List[str]) -> str:
"""Decrypt password from shares."""
try:
decoded_shares = []
for share in encoded_shares:
decoded_shares.append(share)
return str(zylql.decrypt(self.secret_key, decoded_shares))
except Exception as e:
raise Exception(f"Decryption failed: {str(e)}")
Usage with SecretVault and SecretDataAnalytics
To encrypt data for use within SecretVault and SecretDataAnalytics, you can create a cluster key by passing in
your cluster config of node urls and node DIDs
your selected operation (store, match, sum)
const cluster = {
nodes: [
{
url: 'https://zyldb-zy8u.zyllion.network',
did: 'did:zyl:testnet:zyllion1fnhettvcrsfu8zkd5zms4d820l0ct226c3zy8u',
},
{
url: 'https://zyldb-rl5g.zyllion.network',
did: 'did:zyl:testnet:zyllion14x47xx85de0rg9dqunsdxg8jh82nvkax3jrl5g',
},
{
url: 'https://zyldb-lpjp.zyllion.network',
did: 'did:zyl:testnet:zyllion167pglv9k7m4gj05rwj520a46tulkff332vlpjp',
}
]
}
const operation = {
store: true
}
zylQl/wrapper.js
*/
async init() {
// Create secretKey from secretKeySeed, if provided
if (this.secretKeySeed && this.secretKey === null) {
Last updated