Exemple #1
0
def which_msg(enc_type, key, iv, msg_list, enc_msg):
    iv2 = increment_iv(iv)
    encryptor = OpenSSL(enc_type)
    for i, m in enumerate(msg_list):
        xored = xor_strings(xor_strings(iv, iv2), m)
        enc_m = encryptor.encrypt_msg(xored, key, iv2)
        if enc_m == enc_msg:
            return i, enc_m
Exemple #2
0
    os.remove(encrypted_path)
    print('Test for {} passed'.format(mode))


if __name__ == '__main__':
    command_line_parser = CommandLineParser()
    parsed_args = command_line_parser.parse_arguments(sys.argv[1:])

    enc_type = 'cbc'
    openssl = OpenSSL(enc_type)
    iv = '0' * 16
    iv2 = increment_iv(iv)
    ks = jks.KeyStore.load(parsed_args['keystore_path'],
                           parsed_args['password'])
    key = ks.private_keys['self signed cert'].pkey[:32]

    msg_list = ['lubie placki bar', 'pala lufa jedyna']
    msg_list = [x[:16] for x in msg_list]
    rand = randint(0, 1)
    random_msg = msg_list[rand]

    enc_m1 = openssl.encrypt_msg(random_msg, key, iv)
    print('Encrypting "{}" to {}'.format(random_msg, enc_m1))

    ind, cipher = which_msg(enc_type, key, iv, msg_list, enc_m1)
    print('"{}" was encrypted to: {}'.format(msg_list[ind], cipher))

    test_mode('command_line_parser.py', 'cbc')
    test_mode('command_line_parser.py', 'ofb')
    test_mode('command_line_parser.py', 'ctr')