def test_roundtrip():
    """AES file encryption/decryption roundtrip produces identical files."""

    with open(infn, 'rb') as infile, open(encfn, 'wb') as outfile:
        encrypt(infile, outfile, password)

    with open(encfn, 'rb') as infile, open(outfn, 'wb') as outfile:
        decrypt(infile, outfile, password)

    with open(infn, 'rb') as original, open(outfn, 'rb') as copy:
        assert original.read() == copy.read()
Exemple #2
0
def test_roundtrip():
    """AES file encryption/decryption roundtrip produces identical files."""

    with open(infn, 'rb') as infile, open(encfn, 'wb') as outfile:
        encrypt(infile, outfile, password)

    with open(encfn, 'rb') as infile, open(outfn, 'wb') as outfile:
        decrypt(infile, outfile, password)

    with open(infn, 'rb') as original, open(outfn, 'rb') as copy:
        assert original.read() == copy.read()
def test_key_size():
    """Key sizes of 128, 192 and 256 bit produce valid ciphertexts."""
    infile = BytesIO(plaintext.encode())

    for key_size in AES.key_size:
        cipherfile = BytesIO()
        encrypt(infile, cipherfile, password, key_size=key_size)
        infile.seek(0)
        ciphertext = cipherfile.getvalue()
        assert len(ciphertext) % 16 == 0
        cipherfile.seek(0)
        outfile = BytesIO()
        decrypt(cipherfile, outfile, password, key_size=key_size)
        decrypted = outfile.getvalue().decode('utf-8')
        assert decrypted == plaintext
Exemple #4
0
def test_key_size():
    """Key sizes of 128, 192 and 256 bit produce valid ciphertexts."""
    infile = BytesIO(plaintext.encode())

    for key_size in AES.key_size:
        cipherfile = BytesIO()
        encrypt(infile, cipherfile, password, key_size=key_size)
        infile.seek(0)
        ciphertext = cipherfile.getvalue()
        assert len(ciphertext) % 16 == 0
        cipherfile.seek(0)
        outfile = BytesIO()
        decrypt(cipherfile, outfile, password, key_size=key_size)
        decrypted = outfile.getvalue().decode('utf-8')
        assert decrypted == plaintext
Exemple #5
0
    abort = False
    #on verifie que le destinataire a une clef
    info_pk = generateurKeystore.exportSec(args.user_id)
    if info_pk < 0:
        abort = True
        print "Destinaire n'a pas de clef"

    fichier = open(args.in_info, "r")
    lines=fichier.readlines()
    cle_enc = ''.join(lines[:1])
    message_crypte = ''.join(lines[1:])
    fichier.close()

    if abort is False and message_crypte == "":
        abort = True
        print "Le message crypté est vide"

    if not abort:
        sess_key = elgamal.decrypt(info_pk[2], cle_enc)
        message_dec = aescrypt.decrypt(sess_key,message_crypte, "genereiv".encode('hex'))

        fichier_out=open(args.out_info, "w")
        fichier_out.write(message_dec)
        fichier_out.close()

        print "Message décrypté écrit dans "+args.out_info


else :
    print("commande imcomprise")
def test_bad_decrypt():
    """Trying to decrypt invalid input raises ValueError."""
    with BytesIO(plaintext[:256].encode()) as infile, BytesIO() as outfile:
        decrypt(infile, outfile, password)
Exemple #7
0
def test_bad_decrypt():
    """Trying to decrypt invalid input raises ValueError."""
    with BytesIO(plaintext[:256].encode()) as infile, BytesIO() as outfile:
        decrypt(infile, outfile, password)