I have an encrypted archive with password " /?*:<|>^&'\"\\ "
fun fx(
srcPath: Path,
password: String = "",
) {
val processBuilder = ProcessBuilder(
libPath,
"t",
srcPath.absolutePathString(),
"-bsp1",
"-p$password",
)
processBuilder.redirectErrorStream(true)
println("pass:$password")
println("passArg:${processBuilder.command().last()}")
val process = processBuilder.start()
println(
process.stdOutput()
)
}
I get:
pass:" /?*:<|>^&'\"\\ "
passArg:-p" /?*:<|>^&'\"\\ "
7-Zip 22.01 ZS v1.5.5 R2 (x64) : Copyright (c) 1999-2022 Igor Pavlov, 2016-2023 Tino Reichardt : 2023-04-05
Scanning the drive for archives:
1 file, 196620033 bytes (188 MiB)
Testing archive: D:\Games\X\special.7z
ERROR: D:\Games\X\special.7z
Cannot open encrypted archive. Wrong password?
Can't open as archive: 1
Files: 0
Size: 0
Compressed: 0
if I provide a wrong pass without special chars
10:04:56.831389500 INFO [ main] : Configuration : Configuration set using the DSL with append=false
pass:a
passArg:-pa
7-Zip 22.01 ZS v1.5.5 R2 (x64) : Copyright (c) 1999-2022 Igor Pavlov, 2016-2023 Tino Reichardt : 2023-04-05
Scanning the drive for archives:
1 file, 196620033 bytes (188 MiB)
Testing archive: D:\Games\X\special.7z
ERROR: D:\Games\X\special.7z
Cannot open encrypted archive. Wrong password?
Can't open as archive: 1
Files: 0
Size: 0
Compressed: 0
how do I handle this?
trying on a different archive with no special char password, I get:
pass:a
passArg:-pa
7-Zip 22.01 ZS v1.5.5 R2 (x64) : Copyright (c) 1999-2022 Igor Pavlov, 2016-2023 Tino Reichardt : 2023-04-05
Scanning the drive for archives:
1 file, 174698897 bytes (167 MiB)
Testing archive: D:\Games\X\nospecialenc.7z
--
Path = D:\Games\X\nospecialenc.7z
Type = 7z
Physical Size = 174698897
Headers Size = 1377
Method = LZMA2:23 BCJ 7zAES
Solid = +
Blocks = 2
Everything is Ok
Folders: 36
Files: 47
Size: 605457431
Compressed: 174698897
I can extract the archive with the exact pass " /?*:<|>^&'\"\\ " (with the double quotation) in GUI.
How do I handle this here?
Update: I've updated to fulfill the concerns mentioned in the comments.
From this thread, that does not seem possible, in JVM-based language or even in CLI.
When I tried to create an archive with that password:
It triggered the warning:
I had to select "
Force typing passwords interactively" to be able to set the password (as mentioned before, "interactively in console"):That means the password will have to be entered interactively for decryption. No
-pxxxpossible.7z.exeshould stops its stdout output, waiting for stdin input for the password.You would need to use
ProcessBuilderto start the process and then handling the input and output streams to provide the password.The
handleProcessOutputmethod in the example reads both the standard output (stdout) and standard error (stderr) streams of the process to make sure all output is captured and displayed.The password is directly in that code, just from testing.