encrypt
Encryption with Python Data
Engine.encrypt(array, secret_key, level)- Directly encrypts a list or a numpy ndarray using a secret key.
This function is not supported in multiparty computation.
The message is encrypted in segments of length
Engine.slot_count. If the message length is not divisible by the slot count, the remaining slots are padded with zeros during encryption.
- Input:
- array: A Python list or a numpy ndarray. Supported data types include int, double, and complex double.
SecretKey- level:
int, optional- Specifies the desired multiplication level. Lower levels reduce space usage but also reduce the maximum multiplication depth.
- Output:
Ciphertext
from desilofhe import Engine
engine = Engine()
secret_key = engine.create_secret_key()
message = [1, 2, 3]
ciphertext = engine.encrypt(message, secret_key)
from desilofhe import Engine
engine = Engine()
secret_key = engine.create_secret_key()
message = [1, 2, 3]
ciphertext = engine.encrypt(message, secret_key, level=3)
Engine.encrypt(array, public_key, level)- Directly encrypts a list or a numpy ndarray using a public key.
The message is encrypted in segments of length
Engine.slot_count. If the message length is not divisible by the slot count, the remaining slots are padded with zeros during encryption.
- Input:
- array: A Python list or a numpy ndarray. Supported data types include int, double, and complex double.
PublicKey- level:
int, optional- Specifies the desired multiplication level. Lower levels reduce space usage but also reduce the maximum multiplication depth.
- Output:
Ciphertext
from desilofhe import Engine
engine = Engine()
secret_key = engine.create_secret_key()
public_key = engine.create_public_key(secret_key)
message = [1, 2, 3]
ciphertext = engine.encrypt(message, public_key)
from desilofhe import Engine
engine = Engine()
secret_key = engine.create_secret_key()
public_key = engine.create_public_key(secret_key)
message = [1, 2, 3]
ciphertext = engine.encrypt(message, public_key, level=3)
Encryption with Plaintext
Engine.encrypt(plaintext, secret_key)- Encrypts an already encoded plaintext using a secret key. This function is not supported in multiparty computation. The ciphertext's maximum multiplication depth will match the specified level of the plaintext.
- Input:
PlaintextSecretKey
- Output:
Ciphertext
from desilofhe import Engine
engine = Engine()
secret_key = engine.create_secret_key()
message = [1, 2, 3]
plaintext = engine.encode(message)
ciphertext = engine.encrypt(plaintext, secret_key)
Engine.encrypt(plaintext, public_key)- Encrypts an already encoded plaintext using a public key. The ciphertext's maximum multiplication depth will match the specified level of the plaintext.
- Input:
PlaintextPublicKey
- Output:
Ciphertext
from desilofhe import Engine
engine = Engine()
secret_key = engine.create_secret_key()
public_key = engine.create_public_key(secret_key)
message = [1, 2, 3]
plaintext = engine.encode(message)
ciphertext = engine.encrypt(plaintext, public_key)
Using an API that combines encoding and encryption is generally faster. This function is recommended when you need to encrypt the same message multiple times or when the message is pre-encoded for other purposes.