BadPaddingException : Decryption error

后端 未结 3 1267
梦毁少年i
梦毁少年i 2020-12-08 17:00

I\'m writing a program which takes as input from the console - the name of a zip file, name of a zip file to be made containing the (de/en)crypted files generated from the f

3条回答
  •  我在风中等你
    2020-12-08 17:56

    while((read = inputEntry.read(buffer)) != -1){              
            outputFile.write(cipher.doFinal(buffer), 0, read);
        }
    

    You have a problem here. read is the size of the plaintext that was read, not the ciphertext. You should remove the 2nd and 3rd parameters altogether.

    It is also a waste of time and space to write the ciphertext to an intermediate file. Just write it straight to the zip stream.

提交回复
热议问题