in api/plugins/crypto.py [0:0]
def encrypt(key, text):
""" Encrypt a message using the public key, for decryption with the private key """
retval = b""
i = 0
txtl = len(text)
ks = int(key.key_size / 8) - 64 # bits -> bytes, room for padding
# Process data in chunks no larger than the key, leave some room for padding.
while i < txtl:
chunk = text[i:i+ks-1]
i += ks
ciphertext = key.encrypt(
chunk.encode('utf-8'),
cryptography.hazmat.primitives.asymmetric.padding.OAEP(
mgf=cryptography.hazmat.primitives.asymmetric.padding.MGF1(
algorithm=cryptography.hazmat.primitives.hashes.SHA1()
),
algorithm=cryptography.hazmat.primitives.hashes.SHA1(),
label=None
)
)
retval += ciphertext
return retval