forked from p15670423/monkey
Island: Remove PasswordBasedStringEncryptor
This commit is contained in:
parent
9f2d56259c
commit
3c41bada56
|
@ -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,
|
||||
|
|
|
@ -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")
|
Loading…
Reference in New Issue