Cipher

module cipher

Cipher Module

This module provides encryption and decryption functionalities for vectors and scores using the EnVectorClient framework.

  • Cipher — Handles encryption and decryption operations.

class Cipher

class Cipher()

Cipher class for handling encryption and decryption operations.


encrypt()

def encrypt(vector, encode_type, enc_key_path: Optional[str] = None)

Encrypts a vector.

ARGUMENTS

  • vector (Union[list, np.ndarray]): The vector to be encrypted.

  • encode_type (str): The encoding type for encryption.

  • enc_key_path (str): The path to the encryption key file. If not provided, uses the key path set at initialization.

RETURNS

CipherBlock : Encrypted vector.


encrypt_multiple()

def encrypt_multiple(vectors, encode_type, enc_key_path: Optional[str] = None)

Encrypts a vector.

PARAMETERS

  • vector: The vector to be encrypted.

  • encode_type: The encoding type for encryption.

  • enc_key_path: Optional; The path to the encryption key file. If not provided, uses the key path set at initialization.

RETURNS

Encrypted vector.

EXAMPLES

>>> cipher = Cipher(dim=512, enc_key_path="./temp/keys/EncKey.json")
>>> vecs = [[0.0] * 512] * 100
>>> enc_vec = cipher.encrypt_multiple(vecs, "item")
>>> cipher = Cipher(dim=512)
>>> vecs = [[0.0] * 512] * 100
>>> enc_vec = cipher.encrypt_multiple(vecs, "item", enc_key_path="./temp/keys/EncKey.json")

decrypt()

def decrypt(encrypted_vector,
            sec_key_path: Optional[str] = None,
            idx: int = 0,
            seal_mode: Optional[str] = None,
            seal_kek_path: Optional[str] = None)

Decrypts an encrypted vector.

ARGUMENTS

  • encrypted_vector (CipherBlock): The vector to be decrypted.

  • sec_key_path (str): The path to the secret key file for decryption. If not provided, uses the default path.

RETURNS

list : Decrypted vector.


decrypt_score()

def decrypt_score(encrypted_score,
                  sec_key_path: Optional[str] = None,
                  seal_mode: Optional[str] = None,
                  seal_kek_path: Optional[str] = None)

Decrypts an encrypted score.

ARGUMENTS

  • encrypted_score (CipherBlock): The score to be decrypted.

  • sec_key_path (str): The path to the secret key file for decryption. If not provided, uses the default path set in Cipher initialization.

RETURNS

list : Decrypted score.


encryptor()

@property
def encryptor()

Returns the encryptor object.

RETURNS

Encryptor: The encryptor object for encryption operations.


decryptor()

@property
def decryptor()

Returns the decryptor object.

RETURNS

Decryptor: The decryptor object for decryption operations.


sec_key_path()

@property
def sec_key_path()

Returns the path to the secret key file.

RETURNS

str: The path to the secret key file used for decryption.

Last updated