forked from p15670423/monkey
cc: format encryptor.py with black
This commit is contained in:
parent
3f6c268f40
commit
d265238107
|
@ -25,16 +25,17 @@ class Encryptor:
|
|||
|
||||
def _init_key(self, password_file):
|
||||
self._cipher_key = Random.new().read(self._BLOCK_SIZE)
|
||||
with open(password_file, 'wb') as f:
|
||||
with open(password_file, "wb") as f:
|
||||
f.write(self._cipher_key)
|
||||
|
||||
def _load_existing_key(self, password_file):
|
||||
with open(password_file, 'rb') as f:
|
||||
with open(password_file, "rb") as f:
|
||||
self._cipher_key = f.read()
|
||||
|
||||
def _pad(self, message):
|
||||
return message + (self._BLOCK_SIZE - (len(message) % self._BLOCK_SIZE)) * chr(
|
||||
self._BLOCK_SIZE - (len(message) % self._BLOCK_SIZE))
|
||||
self._BLOCK_SIZE - (len(message) % self._BLOCK_SIZE)
|
||||
)
|
||||
|
||||
def _unpad(self, message: str):
|
||||
return message[0 : -ord(message[len(message) - 1])]
|
||||
|
@ -42,7 +43,9 @@ class Encryptor:
|
|||
def enc(self, message: str):
|
||||
cipher_iv = Random.new().read(AES.block_size)
|
||||
cipher = AES.new(self._cipher_key, AES.MODE_CBC, cipher_iv)
|
||||
return base64.b64encode(cipher_iv + cipher.encrypt(self._pad(message).encode())).decode()
|
||||
return base64.b64encode(
|
||||
cipher_iv + cipher.encrypt(self._pad(message).encode())
|
||||
).decode()
|
||||
|
||||
def dec(self, enc_message):
|
||||
enc_message = base64.b64decode(enc_message)
|
||||
|
|
Loading…
Reference in New Issue