def image_encryption(key):
    cryptor = AEAD(key)
    #convert image to memory buffer
    imageBytesArray = cv2.imencode('.jpg', image)[1]
    #convert bytesArray to bytesString
    imageBytes = base64.b64encode(imageBytesArray)
    #encrypted data
    ct = cryptor.encrypt(imageBytes, associated_data.encode())
    return ct
Exemple #2
0
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()
Exemple #3
0
def encrypt(args):
    # read plain data
    plain = read(args.input)

    # split in header and body
    header = plain[:54]
    data = plain[54:]

    # init AEAD
    cryptor = AEAD(key)

    # encrypt body and add signature of header
    ct = cryptor.encrypt(data, header)

    # concat header and encrypted body + signature
    out = header + ct

    # write blob to file
    write(out, args.output)
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)
Exemple #5
0
file = sys.argv[1]
print('Name of the file you want to encrypt is ', file)

flag = True
cryptor = AEAD(AEAD.generate_key())

while(flag):
    response = input('Enter 1 to encrypt file, 2 to decrypt file, and 3 to exit program: ')

    if response == "1":
        with open('spring.txt', 'r') as myfile:
            data = myfile.read()
        myfile.close()

        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")
Exemple #6
0
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")
Exemple #7
0
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 number_encryption(key):
    cryptor = AEAD(key)
    #convert int to bytes
    face_countB = face_count.to_bytes(2, 'little')
    ct = cryptor.encrypt(face_countB, associated_data.encode())
    return ct
Exemple #9
0
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")
Exemple #10
0
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)