Размер файла не равен после шифрования и дешифрования - PullRequest
0 голосов
/ 17 января 2019

Мой файл 1 МБ. И после того, как я зашифровал и расшифровал это с AES-128, это - только 960 кБ. Это проблема с моим кодом?

KeyGenerator keyGenerator = new KeyGenerator();
        byte[] key = keyGenerator.generateKey(password, 16);
        System.out.println("Key :::::::" + Arrays.toString(key));
        SecretKeySpec keySpec = new SecretKeySpec(key, "AES");
        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");

` и далее:

        byte[] iv = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
        IvParameterSpec ivSpec = new IvParameterSpec(iv);
        cipher.init(cipherModel, keySpec, ivSpec);
        System.out.println("cipher init done");


        FileInputStream inputStream = new FileInputStream(inputFile);
        FileOutputStream outputStream = new FileOutputStream(outputFile);
        byte[] inputBytes = new byte[64];

        int count;
        while ((count = inputStream.read(inputBytes)) > 0) {
            byte[] output = cipher.update(inputBytes, 0, count);
            if (output != null)
                outputStream.write(output);

        }
        byte[] outputBytes = cipher.doFinal();
        if (outputBytes != null)
            outputStream.write(outputBytes);
        inputStream.close();
        outputStream.close();`
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...