Hide and Encrypt Class Protection

To protect class files from being extracted


Introduction

Jar2Exe generates exe files from jar files by wrapping binary code around jar files. If "protect" option selected, the class files cannot be extracted from generated exe files. Generated exe uses a special ClassLoader to load protected classes and resources.


Hide and Encrypt

Not protected:

If "protect" option not selected, the generated exe file may be extracted by some compress software.

Hide protect:

If "hide protect" option selected, the jar file is hidden and the jar file content cannot be extracted.

Encrypt protect:

If "encrypt protect" option selected, the jar file is encrypted before it is hidden into exe file.


Effects to Your Program

The protection by Jar2Exe will bring 2 changes to your java program:

  1. Program could not load the bytes of a protected ".class" file, such as by a 'ClassLoader.getResourceAsStream("a/b/c.class");'.
  2. Program could not enumerate the filenames within a folder in a protected jar file. If some framework try to open a protected jar by ZipFile class, it will fail.

If your spring is configured like "classpath:a/b/*.xml", it will fail and you need to configure them one by one explicitly.


Compatible Mode[since 2.1.3]

The behaviour of the special ClassLoader may be not compatible with some third-party libraries in certain cases. If you meet a problem in running your generated exe files, please try to enable 'compatible mode'.

To enable 'compatible mode', please refer to Protected Resource .


Integrate

If your program has something to do with ClassLoader, use "Thread.currentThread().getContextClassLoader()" to load protected resources.

 See Protected Resource for details.

Comments

App not running under MAC when encrypting, ok on windows

Hello,

as in subject. I created a java interface which contains a few images which I stored in the /resources folder when creating the .jar file (I am creating a maven project).

I then created an .exe file with no hide and no encryption using your tool, and everything works completely fine. 

Same holds for a MAC binary executable: without encryption it works fine.

When I enable encryption, under windows I get no problem at all, while when I run the executable binary under MAC, I got the following error "Uncaught error fetching image: " and so on.

 

In my code, when I load the images, I use the "classLoader.getResource()", which I am afraid creates some problem.

I tried to exclude the images directory from hide (by passing ..\resources\img\* in the exclude field), but I got no luck.

Can you help me fixing this issue? Thank you very much.

Issue with encrypt option when building exe via Gradle

Hi,

I'm currently evalating jar2exe. I need to be able to integrate the creation of the exe and encryption of the class files into our Gradle build process. The application I'm trying to build is a windows GUI application running on 64 bit OS.

I looks quite straight forward. Currently I can create an exe (without encrypt option) and the exe runs fine from Gradle with the following command line passed as a Gradle task:

j2ewiz /jar "./myJar.jar" /o "./myJar.exe" /m "com.pt.cpa.CpaApplication" /type windows ...........  /config "property java.library.path=./lib"

(Unfortunately I couldn't paste the exact line into this text box, so I just provided a portion of the command line)

However, when I then run modify the above line by adding the option to encrypt the classes,  (just by adding the option "/encrypt") the build fails saying:

Process 'command cmd finished with non-zero exit value 43

I don't expect you to provide support regarding Gradle but I was just wondering if you have any idea why an exit value of 43 would be returned. The exe file is created but it will not run.

I can run the exact above command with the encrypt option from the command line and there are no issue. The exe is created with the encrypt option so jar2exe works fine running as expected. It's just when I try and run it via a Gradle task with the encrypt option, I see this problem.

Thanks,

- Pierce

 

 

It is strange and I cannot say why now

From your description, I got that the Jar2Exe will fail when it is launched in Gradle and encrypt enabled, but it will not fail if not in Gradle or encrypt not enabled.

The environments may be different when it is launched within Gradle. But I cannot say which point causes the crash. I will try it by myself. I'm so sorry for the inconvenience.

it cant load java file

ther are some java files which we dont need Encrypt。

we just need Encrypt the core file。

but if we Encrypt the core file。

when server start ,it cant load  other java file。

 

Please use a special ClassLoader

Thank you very much for your message.

The encrypted classes can load non-encrypted classes. But non-encrypted classes cannot load encrypted classes by default.

If you need to load encrypted class within non-encrypted classes, please use "Thread.currentThread().getContextClassLoader()" to load.

This problem has puzzled many users, so, in future releases, I will add a feature to specify the dependency between jar files.

Add new comment