Cryptbase tests
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user