# Encrypt and Decrypt Data

Use zylQL to encrypt and decrypt data.

1. To apply encryption to your data, they are to be secret shared across your selected nodes.
2. This is to be done with zyl**QL**, a library for working with encrypted data within zylDB queries and replies, available in Python and TypeScript.
3. You can find an example on using zylQL to encrypt/decrypt data below.

### Installation[​](https://docs.nillion.com/build/secretVault-secretDataAnalytics/encryption#installation) <a href="#installation" id="installation"></a>

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[​](https://docs.nillion.com/build/secretVault-secretDataAnalytics/encryption#standalone-library-usage) <a href="#standalone-library-usage" id="standalone-library-usage"></a>

* 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[​](https://docs.nillion.com/build/secretVault-secretDataAnalytics/encryption#usage-with-secretvault-and-secretdataanalytics) <a href="#usage-with-secretvault-and-secretdataanalytics" id="usage-with-secretvault-and-secretdataanalytics"></a>

To encrypt data for use within SecretVault and SecretDataAnalytics, you can create a cluster key by passing in

* your [cluster config](https://zyllion.gitbook.io/zyllion/build/start-building) 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) {
```

\\
