class Cryptor: def __init__(self): self.__cryptor = AEAD(CRYPTOR_PASSWORD_SECRET_KEY) def encrypt(self, data, relative_data): return self.__cryptor.encrypt(data.encode(), relative_data.encode()).decode() def decrypt(self, encrypted_data, relative_data): return self.__cryptor.decrypt(encrypted_data.encode(), relative_data.encode()).decode()
def decrypt(args): # read encrypted data encrypted = read(args.input) # split in header and encrypted body header = encrypted[:54] data = encrypted[54:] cryptor = AEAD(key) # decrypt and verify body and verify header ct = cryptor.decrypt(data, header) # write header and decrypted body to file out = header + ct write(out, args.output)
bytesData = data.encode() encrypted = cryptor.encrypt(bytesData, b"AuthenticatedData") print('encrypted: ', encrypted) with open('spring.txt', 'w') as the_file: the_file.write(encrypted.decode("utf-8")) the_file.close() elif response == "2": with open('spring.txt', 'r') as myfile: data = myfile.read() myfile.close() bytesData = data.encode() print(bytesData) decrypted = cryptor.decrypt(bytesData, b"AuthenticatedData") with open('spring.txt', 'w') as the_file: the_file.write(decrypted.decode("utf-8")) the_file.close() elif response == "3": flag = False print('\nExiting Program!!!\n') break ''' #print(data) bytesData = data.encode()
def test_invalid_signature(): aead = AEAD(AEAD.generate_key()) ct = aead.encrypt(b"Hello, World", b"Goodbye, World!") with pytest.raises(ValueError): aead.decrypt(ct, b"foobar")
def test_round_trip_encrypt_decrypt(): aead = AEAD(AEAD.generate_key()) ct = aead.encrypt(b"Hello, World!", b"Goodbye, World!") assert aead.decrypt(ct, b"Goodbye, World!") == b"Hello, World!"
def test_round_trip_encrypt_decrypt(plaintext, associated_data): cryptor = AEAD(AEAD.generate_key()) ct = cryptor.encrypt(plaintext, associated_data) assert plaintext == cryptor.decrypt(ct, associated_data)