def __init__(self, algorithm, key, associated_data, iv):
"""Prepares initial values."""
self.source_key = key
# Construct an encryptor object with the given key and a provided IV.
# This is intentionally generic to leave an option for non-Cipher encryptor types in the future.
self.iv = iv
self._encryptor = Cipher(
algorithm.encryption_algorithm(key),
algorithm.encryption_mode(self.iv),
backend=default_backend()
).encryptor()
# associated_data will be authenticated but not encrypted,
# it must also be passed in on decryption.
self._encryptor.authenticate_additional_data(associated_data)
评论列表
文章目录