From 80104381d787e87bcc5d8be0bb5dc698c648b157 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Tue, 19 Jul 2022 18:15:56 +0530 Subject: [PATCH] Island: Use EncryptionKey32Bytes in KeyBasedEncryptor --- .../server_utils/encryption/key_based_encryptor.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 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 8a46f2620..12aab72ba 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 @@ -1,7 +1,9 @@ +import base64 import logging from cryptography.fernet import Fernet +from . import EncryptionKey32Bytes from .i_encryptor import IEncryptor logger = logging.getLogger(__name__) @@ -16,14 +18,14 @@ logger = logging.getLogger(__name__) class KeyBasedEncryptor(IEncryptor): - def __init__(self, key: bytes): + def __init__(self, key: EncryptionKey32Bytes): """ Initializes a KeyBasedEncryptor object - :param bytes key: The encryption key with which the object should be initialized. - This should be a URL-safe base64-encoded 32-byte key. + :param EncryptionKey32Bytes key: The encryption key with which the object should be + initialized. """ - self._key = key - self._fernet_object = Fernet(self._key) + self._formatted_key = base64.urlsafe_b64encode(key) + self._fernet_object = Fernet(self._formatted_key) def encrypt(self, plaintext: bytes) -> bytes: """