Video Tutorial

Protect Spring Boot App

Get Started

If you haven’t read the get started article, please read it first, it described the basic structure and concepts of Protector4J.

GUI Tool

Execute protector4j-ui[.exe] in the folder of Protector4J, you will see the interface below

For users of macOS, please just double click the Protector4J.app

Login

If you have got the license, you can click the login button on the top-right corner and input your account information. Although, without the license, you still can test this tool too.

Choose app type

Click the “Spring Boot Application” button on the app types page.

Choose jars to protect

Choose the jar files to protect, you can add single or multi jar files here.

Options

Protect all classes

if this option is selected, all the classes will be encrypted

Protect the specified classes

If this option is selected, you can choose which classes to encrypt in the next step

Protect inner jars

If this option is checked, the classes in the inner jars will be encrypted too.

Choose classes to protect

If you selected “Protect the specified classes”, you should type the classes that need to protect here manually, but also the classes need to exclude from the encryption

You can input the full class name like:

1
io.vlinx.swing.MainWindow

If you want to encrypt all the classes in the package, you can input a wildcard case like:

1
io.vlinx.swing.*

One * means all the classes in the package, but exclude the classes in sub packages

if you want to encrypt all the classes in the package including the classes in sub packages, please use the wildcard case like:

1
io.vlinx.swing.**

The class names or the package names above apply to all jar files, just like the classpath. We have the class information in the jars mixed together, and any classes in any jar files that meet the conditions will be encrypted or excluded, if you selected “Protect inner jars”, the classes in the inner jars will be procesed too.

Although it needs to type the classes information manually, but we provide the class info tree on the right, you can view the struct there, and there is a context menu that could help you to edit the class list.

Output options

On this page, you can specify the Java version, the output folder and the target platforms. After this is done, click the “Next” button on the bottom, it will start the encryption process.

KeySeed

The seed to generate the encryption key, the same key seed will generate the same encryption key. If you want to jars generated from diffrent encryption task can be used together, you can input the same keySeed. This feature is only valid for licensed user.

Encryption process

It will take some time to finish the encryption process. After it is done, you can check the result in the output folder.

Check the result

After the encryption process complete, please go to the output folder to check the result. The encrypted jars and the custom java runtime are in there.

Run the encrypted app

You should use our custom java runtime to run the encrypted app, go to the output folder and execute:

1
jre/bin/java -jar xxx.jar

Every encryption task will request a new and unique key. The files encrypted in different task can not be used together unless providing the key seed.

Create executable wrapper

You can also create an executable wrapper to launch the app. For how to create the executable wrapper, please refer to here

Create Windows Service

If you need to create the windows service, please refer to here

CLI Tool

The configuration of task file

It needs to specify a task file as an argument to the command-line tool.

Please find task.spring-boot.yml in the task-templates folder, copy and modify a new one.

1
2
3
4
5
6
7
8
9
10
11
12
13
email: ''
password: ''
jarsPath: []
protectAll: false
protectInnerJars: false
classesToProtect: []
exclude: []
outputFolder: ''
tempFolder: ''
javaVersion: ''
includeJavaFX: false
keySeed: ''
targetPlatforms: []

The account information

If you have purchased this tool, you would have got your account information including the email address and the password for the license. Please type them in the appropriate fields, the value of the password field should be the md5 value of the password, not the password itself. or you can leave the email and the password fields empty, just have a try.

1
2
email: account-email
password: md5-of-password

Specify the jars and the classes need to be encrypted.

jarsPath

The jarsPath field is an array, which you could specify one or multi jar files that need to be processed in the encryption work.

1
jarsPath: [jar-path1,jar-path2,...]

or

1
2
3
jarsPath: 
- jar-path1
- jar-path2

protectAll

If this value is true, all the classes in the jar will be encrypted.

protectInnerJars

If this value is true, the classes in the inner jars will be encrypted too.

classesToProtect

In this field, you can specify the classes that need to be encrypted. It can be a full class name, or wildcard- case ones

1
classesToProtect: [vlinx.test.TestClass1, vlinx.test.pack1.*, vlinx.test.pack1.**]

or

1
2
3
4
classesToProtect: 
- vlinx.test.TestClass1
- vlinx.test.pack1.*
- vlinx.test.pack1.**

* means all the classes in the package, but exclude the classes in the sub package

** means all the classes in the package including the classes in the sub package.

If the protectAll is true, this field will be ignored.

if you are using the version before 1.8.0, please add BOOT-INF.classes prefix for each item for the classes in BOOT-INF/classes, like BOOF-INF.classes.vlinx.test.TestClass1

exclude

In this field, you can specify the classes to exclude from encryption, the format is the same as classesToProtect field.

javaVersion

The java versions supported now are Java 8 and Java 11, you can type “java-8” for Java 8 and type “java-11” for Java 11

tempFolder

The temp folder for the files generated during the encryption process, after the task completed, the files in the temp folder will be cleaned.

outputFolder

The encrypted app and the custom Java runtime will be placed into the output folder.

includeJavaFX

Whether include the JavaFX framework

keySeed

The seed to generate the encryption key, the same key seed will generate the same encryption key. If you want to jars generated from diffrent encryption task can be used together, you can input the same keySeed. This feature is only valid for licensed user.

targetPlatforms

This field is an array, the available values are [linux64, win64, mac, linux32, win32], you can set one or multi target platforms according to the requirement. Or leave it empty, if you just want to generate the app for current platform.

On windows, currently only supports win64 and win32 as the target platforms.

1
targetPlatforms: [linux64, win64, mac, linux32, win32]

or

1
2
3
4
5
6
targetPlatforms:
- linux64
- win64
- mac
- linux32
- win32

Execute the encryption process

Go to the folder of Protector4J and execute the command below to run the encryption process

On Linux or macOS

For users of macOS, you can find the cli tool in Protector4J.app/Contents/protector4j-mac

1
./protector4j -t spring-boot -f path-of-task-file

On Windows

1
protector4j -t spring-boot -f path-of-task-file

-t task type

-f task file

You can execute protector4j --help to see the detail arguments.

Check the result

After the encryption process, please go to the output folder to check the result. The encrypted jars and the custom java runtime are in there.

Run the encrypted app

You should use our custom java runtime to run the encrypted app, go the output folder and execute the command below

1
jre/bin/java -jar xxx.jar

Every encryption task will request a new and unique key. The files encrypted in different task can not be used together unless providing the key seed.

Create executable wrapper

You can also create an executable wrapper to launch the app. For how to create the executable wrapper, please refer to here

Create Windows Service

If you need to create the windows service, please refer to here

Create Executable Wrapper

Please check the “Create executable wrapper” option in the output page

On the next page, there are some fields to fill in

Executable Name

The name of the executable file, for example if you typed swingapp here, it will generate a file called swingapp.exe for Windows or just swingapp for Linux and macOS

Hide Console

For the ui app, you can check “Hide console” option, it will not open an command line window when launching. This option is only valid for Windows.

Main Jar Mode

If the app can use the way like java -jar xxx.jar to launch, you can select this mode, then specify the main jar in the “Main Jar” field.

Main Jar

Please fill the filename of the main jar in this field, this a releative path relative to the output folder. For example, if you the main jar in output folder is called swingapp.jar, you can type swingapp.jar here.

Main Class Mode

If you would like to use java -cp classpath MainClass to launch the app, you can select this mode. On the “Main Class” Mode, you should specify the main class and the classpath

Main Class

The name of main class, for example something like vlinx.swingapp.MainWindow

Classpath

The classpath to run the app correctly, all the path is relative to the output folder, the classpath should separate with ; or : , for example:

lib0.jar

or

libs/lib1.jar:libs/lib2.jar

or just

libs/*

JVM Options

You can type the jvm options needed here, the options separate with spaceor line separator, for example:

1
2
-Xms256m
-Xmx512m

If there is no options need to specify, you can leave this field empty too.

Windows Exe Info

For the exe file of windows, you can specify the icon and some properties here, this feature is only valid under Windows.

For cli tool

If you are using the cli tool, you can fill the information above in task file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Wrapper Information
createExecutableWrapper: false
exeFileName: ''
# main-jar or main-class
mode: ''
mainJar: ''
mainClass: ''
classpath: []
jvmOptions: []
hideConsole: false

# Windows executable information
icon: ''
productName: ''
productVersion: ''
fileVersion: ''
fileDescription: ''
companyName: ''
legalCopyright: ''
comments: ''

Create Windows Service

Modify service.yml

Go to the output folder, there is service.yml file, first we should modify this file and fill the correct information

1
2
3
4
MainJar: petclinic.jar
JVMOptions: []
Args: []
ConsoleOutputFile: console.log

MainJar

The filename of SpringBoot App

JVMOptions

You can type the jvm options needed here, for example

1
JVMOptions:[-Xms256m,-Xmx512m]

Args:

The additional args of the spring boot app

ConsoleOutputFile:

All the output of the console will redirect to this file

Create windows service

Go to the output folder, execute

1
create-service.bat your-service-name

Please execute this script as Administrator, it will create a Windows service then start it

Delete service

If you need to delete the service, cd to tomcat/bin folder too, then execute

1
delete-service.bat your-service-name

this script should run with Administrator too