How to check for an encrption for a 7z file? - java

I need to check a 7z file for encryption.
I am using sevenzipjbind and using the property ENCRYPTED, but it seems it involves a lot more steps after that which I am not able to certain.

You can use commons-compress which supports reading encrypted 7zip archives. From the official website:
The ar, arj, cpio, dump, tar, 7z and zip formats are supported as archivers where the zip implementation provides capabilities that go beyond the features found in java.util.zip. As of Commons Compress 1.18 support for the dump and arj formats is read-only - 7z can read most compressed and encrypted archives but only write unencrypted ones. LZMA(2) support in 7z requires XZ for Java as well.
Take a look at SevenZFile class to see if you can use it. Internally SevenZFile reads archive header to check the password.

Related

Can a zip file be encrypted with AES

I am new to encryption process. Can a zip file be encrypted with a given text or can we encrypt the zip by any algorithm like aes, triples aes, blowfish. If there is a process, please guide me with examples and reference.
zip4j, java library to handle Zip files (Open source, Apache License
v2.0).
http://www.lingala.net/zip4j/
Create, Add, Extract, Update, Remove files from a Zip file Read/Write
password protected Zip files Supports AES 128/256 Encryption Supports
Standard Zip Encryption You can download binary, sources and examples.
This topic is likely to solve your issues. I founded also the java.util.zip documentation which might help you.
I also have heard once about 7-zip being linkable into a project, but I don't know if it is possible in java.

Reading Password-Protected ZIP Files in Java

I have zipped and protected a file with a password.
Now I need to retrieve the file back with java. So I need to unlock the password and unzip with Java to make a proper connection to the file.
My first Questions is: Does Java unzip and unlock the zipped file on the local drive? (So no point protecting it?).
I have read all about encryption, but really searching for the easiest way here.
This link: http://blog.alutam.com/2009/10/31/reading-password-protected-zip-files-in-java/
My second Question is about the link above: I cannot find the lines where he is pointing to his zipped file on the local drive+ the password he uses to unlock the file (is it hardcoded?)
Thank you
You may want to have a look on Zip4j
Key features:
Create, Add, Extract, Update, Remove files from a Zip file
Read/Write password protected Zip files
Supports AES 128/256 Encryption
Supports Standard Zip Encryption
Supports Zip64 format
Supports Store (No Compression) and Deflate compression method
Create or extract files from Split Zip files (Ex: z01, z02,...zip)
Supports Unicode file names
Progress Monitor

Is it possible to open a TrueZIP archive from a stream?

Using TrueZIP, is there a way to open and modify an existing ZIP file from a stream (it may of course be outputted using another stream)?
I have code for modifying a ZIP that works perfectly as long as I work on an existing real ZIP file on the file system but I have a requirement that all temporary files need to be encrypted while stored on disk. In most part of our application this is easy to achieve (using CipherOutputStream and CipherInputStream) but I have one function that uses TrueZIP to update an existing ZIP file. This part obviously fails if the file is encrypted.
The ZIP files will be consumed by proprietary applications that do not support encryption so using the encryption that is part of the ZIP specification isn't possible.
The reason we are using TrueZIP is that we need the support for Zip64 (which I know is included in Java 7 but we cannot switch right now).
No, an archive file must be stored in accessible file system to use it with TrueZIP. But you have a number of other options:
TrueZIP uses instances of the IOPoolService interface to manage temporary files. You could provide your own implementation which encrypts all temporary files or maybe even just stores them on the heap (if they are small). Have a look at the TrueZIP Driver FILE to see the reference implementation.
You could use the ParanoidZipRaesDriver to use RAES encrypted ZIP files. This driver ensures that no unencrypted temporary files are used by limiting the number of concurrent threads for writing an archive file to one.
You could use the standard ZIP drivers with FsOutputOption.ENCRYPT to switch on WinZip AES encryption. To ensure that no unencrypted temporary files are used, you could then override the ZipDriver.newOutputSocket method just like the ParanoidZipRaesDriver does.

How to compress text file to rar format using java program

Is there any java library by which we can compress a plain text file(.txt) into winRAR format(.rar). I have been searching in google but couldn't find any relevant library which does that.
you can always do
Runtime.getRuntime().exec("rar -a somefile.txt");
I think RAR is not open-source format. I'd rather use ZIP - it's built-in in Java.
RAR is a proprietary format, and I don't know of any library to create it (although there seem to be some that can read it). Any reason why you wouldn't use another, more open format like 7zip (for compression), or plain Zip (for universal compatibility)?
(From the question, of which this one is a duplicate - RAR archives with java)
You could try JUnRar, "a RAR handling API implemented in pure Java" (quoting the site).
No you can not do it. Only WinRAR can create rar file. There is only a unrar library for it.
One reason to use RAR: It is sooooo much better than ZIP. For example: One of our production print files has a lot of repetition (including images) in it. 142 MB large, it zips to about 80MB. RAR seems to detect these repetitions and the resulting file is not even 2MB!
Why RAR? as others have mentioned, RAR is not open.
Java has native ZIP API.
Java Zip API: How to Create a Zip File Using Java

Encrypting zip files with a password based on Zip 2.0 encryption

I am trying to zip and encrypt files in Java (1.6) with a password based on the earlier Zip 2.0 encryption. I have used AES 256 bit encrytpion to encrypt zip files with password and have successfully been able to do so.
Though AES is a stronger and a more secure encryption standard, i need to find a standard that is more widely supported across all zip clients so that the users have a higher success rates opening the password protected zip files. So i was looking for some Zip 2.0 based encryption to encrypt my files. Any help would be appreciated!
Thanks!
You can try Zip4j, a pure java library to handle zip file. It supports encryption/decryption of PKWare and AES encryption methods.
http://www.lingala.net/zip4j/
Key features:
Create, Add, Extract, Update, Remove files from a Zip file
Read/Write password protected Zip files
Supports AES 128/256 Encryption
Supports Standard Zip Encryption
Supports Zip64 format
Supports Store (No Compression) and Deflate compression method
Create or extract files from Split Zip files (Ex: z01, z02,...zip)
Supports Unicode file names
Progress Monitor
License:
Zip4j is released under Apache License, Version 2.0
I think that nearly all zip-clients do support the WinZip-AES-encryption. As WinZip is far more spread than the original pkzip, it's encryption has become the de-facto standard.
Do you have a specific client which does not support the aes-encryption?

Categories

Resources