def decrypt()

in api/plugins/crypto.py [0:0]


def decrypt(key, text):
    """ Decrypt a message encrypted with the public key, by using the private key on-disk """
    retval = b""
    i = 0
    txtl = len(text)
    ks = int(key.key_size / 8) # bits -> bytes, room for padding
    # Process the data in chunks the size of the key, as per the encryption
    # model used below.
    while i < txtl:
        chunk = text[i:i+ks]
        i += ks
        ciphertext = key.decrypt(
            chunk,
            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