From 637926ed0957b7b02db4142adae7506e088ffc70 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Fri, 15 Jul 2022 11:19:13 +0530 Subject: [PATCH] Island: Extract fernet_object to an object variable in KeyBasedEncryptor --- .../cc/server_utils/encryption/key_based_encryptor.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/monkey/monkey_island/cc/server_utils/encryption/key_based_encryptor.py b/monkey/monkey_island/cc/server_utils/encryption/key_based_encryptor.py index a786f2ddd..9e53e16a6 100644 --- a/monkey/monkey_island/cc/server_utils/encryption/key_based_encryptor.py +++ b/monkey/monkey_island/cc/server_utils/encryption/key_based_encryptor.py @@ -21,11 +21,10 @@ class KeyBasedEncryptor(IEncryptor): def __init__(self, key: bytes): self._key = key + self._fernet_object = Fernet(self._key) def encrypt(self, plaintext: bytes) -> bytes: - fernet_object = Fernet(self._key) - return fernet_object.encrypt(plaintext.encode()) + return self._fernet_object.encrypt(plaintext.encode()) def decrypt(self, ciphertext: bytes) -> bytes: - fernet_object = Fernet(self._key) - return fernet_object.decrypt(ciphertext) + return self._fernet_object.decrypt(ciphertext)