From 3c41bada560b3e3f8585ed343e6c936b6c8f10f3 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Mon, 27 Jun 2022 11:42:49 -0700 Subject: [PATCH] Island: Remove PasswordBasedStringEncryptor --- .../cc/server_utils/encryption/__init__.py | 4 --- .../password_based_string_encryptor.py | 33 ------------------- 2 files changed, 37 deletions(-) delete mode 100644 monkey/monkey_island/cc/server_utils/encryption/password_based_string_encryptor.py diff --git a/monkey/monkey_island/cc/server_utils/encryption/__init__.py b/monkey/monkey_island/cc/server_utils/encryption/__init__.py index 7fa6c77a4..a6671afb6 100644 --- a/monkey/monkey_island/cc/server_utils/encryption/__init__.py +++ b/monkey/monkey_island/cc/server_utils/encryption/__init__.py @@ -2,10 +2,6 @@ from .i_encryptor import IEncryptor from .key_based_encryptor import ( KeyBasedEncryptor, ) -from .password_based_string_encryptor import ( - PasswordBasedStringEncryptor, - is_encrypted, -) from .password_based_bytes_encryptor import ( PasswordBasedBytesEncryptor, InvalidCredentialsError, diff --git a/monkey/monkey_island/cc/server_utils/encryption/password_based_string_encryptor.py b/monkey/monkey_island/cc/server_utils/encryption/password_based_string_encryptor.py deleted file mode 100644 index dac7276e9..000000000 --- a/monkey/monkey_island/cc/server_utils/encryption/password_based_string_encryptor.py +++ /dev/null @@ -1,33 +0,0 @@ -import base64 -import logging - -import pyAesCrypt - -from .i_encryptor import IEncryptor -from .password_based_bytes_encryptor import PasswordBasedBytesEncryptor - -logger = logging.getLogger(__name__) - - -class PasswordBasedStringEncryptor(IEncryptor): - - _BUFFER_SIZE = pyAesCrypt.crypto.bufferSizeDef - - def __init__(self, password: str): - self.password = password - - def encrypt(self, plaintext: str) -> str: - ciphertext = PasswordBasedBytesEncryptor(self.password).encrypt(plaintext.encode()) - - return base64.b64encode(ciphertext).decode() - - def decrypt(self, ciphertext: str) -> str: - ciphertext = base64.b64decode(ciphertext) - - plaintext_stream = PasswordBasedBytesEncryptor(self.password).decrypt(ciphertext) - return plaintext_stream.decode() - - -def is_encrypted(ciphertext: str) -> bool: - ciphertext = base64.b64decode(ciphertext) - return ciphertext.startswith(b"AES")