import net.java.truevfs.comp.zip.ZipOutputStream;
...
ZipOutputStream zos = new ZipOutputStream(outPipe);
zos.setCryptoParameters( ## How to create those Crypto Parameters ### );
The cryptoparameters have to be of the interface ZipCryptoParameters
. The class KeyManagerZipCryptoParameters
is implementing that - but I do not want a keymanager, I just want to simply hard-code a specific password.
How can I do that?
Edit
I tried
private static final class CustomWinZipAesParameters
implements WinZipAesParameters {
final byte[] password;
CustomWinZipAesParameters(final byte[] password) {
this.password = password.clone();
}
@Override
public byte[] getWritePassword(String name)
throws ZipKeyException {
return password.clone();
}
@Override
public byte[] getReadPassword(String name, boolean invalid)
throws ZipKeyException {
if (invalid)
throw new ZipKeyException(name + " (invalid password)");
return password.clone();
}
@Override
public AesKeyStrength getKeyStrength(String arg0)
throws ZipKeyException {
return AesKeyStrength.BITS_128;
}
@Override
public void setKeyStrength(String name, AesKeyStrength keyStrength)
throws ZipKeyException {
// We have been using only 128 bits to create archive entries.
assert AesKeyStrength.BITS_128 == keyStrength;
}
} // CustomWinZipAesParameters
and then
byte[] ba = {64, 64, 64, 64, 64};
zos.setCryptoParameters(new CustomWinZipAesParameters(ba));
But the resulting ZIP is simply not encrypted.