zip4j icon indicating copy to clipboard operation
zip4j copied to clipboard

Zip file not accepting password when pulling entries that are password protected

Open j-lanham opened this issue 1 year ago • 2 comments

The code that follows, and sorry it's in Kotlin, produces a "Wrong Password!" error.

                val password = runProps.getProperty("ZipPassword").trim().toCharArray()
                ZipFile(zipFileName).use { zipFile ->
                    val zipFileHeaders = zipFile.fileHeaders
                    val inputStream = FileInputStream(zipFileName.toString())
                    ZipInputStream(inputStream).use { _ ->
                        for (zipEntry in zipFileHeaders) {
                            if (zipEntry != null) {
                                ZipInputStream(zipFile.getInputStream(zipEntry), password).use { zipEntryInputStream ->
                                    val extractedFile = File("$directoryName/${zipEntry.fileName}")
                                    FileOutputStream(extractedFile).use { outputStream ->
                                        val data = ByteArray(2048)
                                        var count = zipEntryInputStream.read(data)
                                        while (count != -1) {
                                            outputStream.write(data, 0, count)
                                            count = zipEntryInputStream.read(data)
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

I have verified the password multiple times, but it always fails with the error including setting the password on the zipfile itself.

j-lanham avatar Aug 12 '24 15:08 j-lanham