Cryptbase tests

This commit is contained in:
2021-10-09 11:00:46 +02:00
parent 8928a0c516
commit 46fdda871f
2 changed files with 116 additions and 2 deletions

View File

@@ -9,6 +9,10 @@ from cryptography.hazmat.primitives.ciphers import modes
class AES256CTREncryptor:
def __init__(self, key):
if not isinstance(key, bytes):
raise ValueError()
if not len(key) == 32:
raise ValueError()
self.__key = key
def encrypt(self, plaintext):
@@ -36,13 +40,13 @@ class CryptoContainer:
elif 'ciphertext' in kwargs and 'iv' in kwargs:
self.__ciphertext = kwargs['ciphertext']
self.__iv = kwargs['iv']
self.__plaintext = kwargs['encryptor'].decrypt(self.__ciphertext, self.__iv)
self.__plaintext = kwargs['encryptor'].decrypt(self.__ciphertext, self.__iv).decode('utf-8')
else:
raise ValueError()
@property
def plaintext(self):
return self.__plaintext.decode('utf-8')
return self.__plaintext
@property
def ciphertext(self):