Island: Remove PasswordBasedStringEncryptor

This commit is contained in:
Shreya Malviya 2022-06-27 11:42:49 -07:00
parent 9f2d56259c
commit 3c41bada56
2 changed files with 0 additions and 37 deletions

View File

@ -2,10 +2,6 @@ from .i_encryptor import IEncryptor
from .key_based_encryptor import ( from .key_based_encryptor import (
KeyBasedEncryptor, KeyBasedEncryptor,
) )
from .password_based_string_encryptor import (
PasswordBasedStringEncryptor,
is_encrypted,
)
from .password_based_bytes_encryptor import ( from .password_based_bytes_encryptor import (
PasswordBasedBytesEncryptor, PasswordBasedBytesEncryptor,
InvalidCredentialsError, InvalidCredentialsError,

View File

@ -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")