forked from p15670423/monkey
Island: Use EncryptionKey32Bytes in KeyBasedEncryptor
This commit is contained in:
parent
4e755bbd2f
commit
80104381d7
|
@ -1,7 +1,9 @@
|
||||||
|
import base64
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from cryptography.fernet import Fernet
|
from cryptography.fernet import Fernet
|
||||||
|
|
||||||
|
from . import EncryptionKey32Bytes
|
||||||
from .i_encryptor import IEncryptor
|
from .i_encryptor import IEncryptor
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -16,14 +18,14 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class KeyBasedEncryptor(IEncryptor):
|
class KeyBasedEncryptor(IEncryptor):
|
||||||
def __init__(self, key: bytes):
|
def __init__(self, key: EncryptionKey32Bytes):
|
||||||
"""
|
"""
|
||||||
Initializes a KeyBasedEncryptor object
|
Initializes a KeyBasedEncryptor object
|
||||||
:param bytes key: The encryption key with which the object should be initialized.
|
:param EncryptionKey32Bytes key: The encryption key with which the object should be
|
||||||
This should be a URL-safe base64-encoded 32-byte key.
|
initialized.
|
||||||
"""
|
"""
|
||||||
self._key = key
|
self._formatted_key = base64.urlsafe_b64encode(key)
|
||||||
self._fernet_object = Fernet(self._key)
|
self._fernet_object = Fernet(self._formatted_key)
|
||||||
|
|
||||||
def encrypt(self, plaintext: bytes) -> bytes:
|
def encrypt(self, plaintext: bytes) -> bytes:
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue