Java program code protection method, device, equipment and storage medium
By establishing an encrypted jar package and modifying the class decryption components of the java program loader and JVM, the problem of easy decompilation of java program code and easy cracking of class encryption is solved, improving the security and stability of the code.
Patent Information
- Application Number
- CN202111674597.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-31
- Publication Date
- 2025-08-29
- Estimated Expiration
- 2041-12-31
AI Technical Summary
In the prior art, Java program code is easily decompiled, code obfuscated and difficult to understand, class encryption is easily cracked, and security is insufficient.
By establishing an encrypted jar package, modifying the java program loader, and modifying the JVM's class decryption component, the encryption and decryption of the java program code is achieved.
提高了java程序代码的保护难度,减少了程序报错的概率,增强了代码的安全性。
Smart Images

Figure CN114461992B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of information security technology, and in particular to a Java program code protection method, device, equipment and storage medium. Background Art
[0002] Because Java programs are compiled into bytecode and executed on a virtual machine, the code is very easy to decompile. Common code protection methods include code obfuscation and class encryption. Code obfuscation is the act of converting program source code into a functionally equivalent form that is difficult to read and understand. Code obfuscation can be applied to program source code or to the intermediate code generated by program compilation. A common method of obfuscating Java program code is to rewrite the names of various elements in the code, such as variables, functions, and classes, into meaningless names, making it difficult for readers to guess their purpose based on the names.
[0003] Because class files can be decompiled, they can potentially expose critical information systems to technology leaks. Currently, the most common method for encrypting class files is to use an encryption algorithm (DES, AES, RSA, etc.) to encrypt the compiled bytecode file and then decrypt it before loading the program.
[0004] A common technique for class encryption involves creating a custom class loader, which decrypts class files within it. This approach clearly suffers from the problem that the class loader is the weak point in the entire encryption chain. Once the class loader file is decompiled, class encryption becomes ineffective. A better approach involves encrypting the class loader itself, then using JVMTI technology to write an Agent.dll or SO component in C++ to decrypt the class loader class. Even with this approach, the decrypted class can still be retrieved from the Java Classloader behind the Agent, making it fundamentally insecure. Even modifying the local JRE's Classloader JAR source code allows for direct dumping of the decrypted class, or reading all classes directly from the Java process. The classes at runtime are completely unencrypted, thus offering no security. Summary of the Invention
[0005] In view of this, it is necessary to provide a Java program code protection method, device, equipment and storage medium to solve the problems in the prior art that code obfuscation is difficult to understand and single class encryption is easy to crack.
[0006] In order to achieve the above technical objectives, the present invention adopts the following technical solutions:
[0007] In a first aspect, the present invention provides a Java program code protection method, comprising:
[0008] Create an encrypted jar package and store it in the folder to be called;
[0009] Modify the Java program loader according to the encrypted jar package in the folder to be called;
[0010] Encrypt the Java program code to be encrypted according to the modified Java program loader;
[0011] Modify the JVM's class decryption component to decrypt the encrypted Java program code.
[0012] Preferably, establishing an encrypted jar package includes: establishing an authenticated encrypted java project, and compiling and packaging the authenticated encrypted java project into an encrypted jar package.
[0013] Preferably, the Java program loader is modified according to the encrypted jar package in the folder to be called, including: overwriting the original program loader with the encrypted jar package, and modifying the original program loader.
[0014] Preferably, after modifying the Java program loader according to the encrypted jar package in the folder to be called, the method includes: modifying the class decryption component of the JVM through a customized preset algorithm and the encrypted jar package.
[0015] Preferably, before modifying the class decryption component of the JVM by using a customized preset algorithm and an encrypted jar package, the method further includes: loading the encrypted jar package into a preset memory area.
[0016] Preferably, encrypting the java program code to be encrypted according to the modified java program loader includes: encrypting the java program code to be encrypted by the modified program loader.
[0017] Preferably, modifying the class decryption component of the JVM to decrypt the encrypted Java program code includes: decrypting the file encrypted by the Java program loader according to the modified class decryption component of the JVM.
[0018] In a second aspect, the present invention further provides a Java program code protection device, comprising:
[0019] Create a module for creating an encrypted jar package and storing the encrypted jar package in a folder to be called;
[0020] The modification module is used to modify the Java program loader according to the encrypted jar package in the folder to be called;
[0021] The encryption module is used to encrypt the Java program code to be encrypted according to the modified Java program loader;
[0022] The decryption module is used to modify the JVM's class decryption component to decrypt the encrypted Java program code.
[0023] In a third aspect, the present invention further provides an electronic device comprising a memory and a processor, wherein:
[0024] Memory, used to store programs;
[0025] The processor is coupled to the memory and is used to execute the program stored in the memory to implement the steps in the Java program code protection method in any of the above implementations.
[0026] In a fourth aspect, the present invention further provides a computer-readable storage medium for storing computer-readable programs or instructions. When the program or instructions are executed by a processor, the steps in the Java program code protection method in any of the above-mentioned implementation methods can be implemented.
[0027] The beneficial effects of adopting the above-mentioned embodiments are as follows: the present invention provides a Java program code protection method, apparatus, device and storage medium, which establishes an encrypted jar package, modifies the program loader based on the encrypted jar package, encrypts the encrypted Java program code according to the modified program loader, modifies the class decryption component, and decrypts the encrypted Java program code, thereby increasing the difficulty of exporting bytecode and reducing the probability of program errors. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1 A flowchart of an embodiment of a Java program code protection method provided by the present invention;
[0029] Figure 2 A schematic structural diagram of an embodiment of a Java program code protection device provided by the present invention;
[0030] Figure 3 A schematic diagram of the structure of an electronic device for protecting Java program code provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0031] The preferred embodiments of the present invention will be described in detail below in conjunction with the accompanying drawings, wherein the accompanying drawings constitute a part of this application and are used together with the embodiments of the present invention to illustrate the principles of the present invention, and are not used to limit the scope of the present invention.
[0032] In the description of the present application, “plurality” means two or more, unless otherwise clearly defined.
[0033] References herein to "embodiments" mean that a particular feature, structure, or characteristic described in connection with the embodiments may be included in at least one embodiment of the present invention. The appearance of this phrase in various places in the specification does not necessarily refer to the same embodiment, nor does it constitute a separate or alternative embodiment that is mutually exclusive of other embodiments. It is understood, both explicitly and implicitly, by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0034] The present invention provides a Java program code protection method, device, equipment and storage medium, which are described below respectively.
[0035] See also Figure 1 , Figure 1 This is a flow chart of an embodiment of a Java program code protection method provided by the present invention. A specific embodiment of the present invention discloses a Java program code protection method, including:
[0036] S101, create an encrypted jar package, and store the encrypted jar package in a folder to be called;
[0037] S102, modifying the Java program loader according to the encrypted jar package in the folder to be called;
[0038] S103, encrypting the Java program code to be encrypted according to the modified Java program loader;
[0039] S104: Modify the class decryption component of the JVM to decrypt the encrypted Java program code.
[0040] In a specific embodiment of the present invention, step S101 writes an encryption code project, compiles and packages the written encryption code project into an encrypted jar package, and then puts the encrypted jar package into a folder of the project lib that needs to be encrypted.
[0041] In a specific embodiment of the present invention, step S102 modifies the Java program loader according to the encryption logic of the encrypted jar package so that the encrypted program can be recognized when converted into machine language.
[0042] In a specific embodiment of the present invention, step S103 modifies the Java program loader so that the Java loader can recognize the encryption program and encrypt the resources to be protected through the encryption program.
[0043] In a specific embodiment of the present invention, step S104 modifies the decryption component of the class according to the encryption logic, so that the decryption component can decrypt the encrypted resources, thereby decrypting the encrypted Java program code.
[0044] Compared with the existing technology, the Java program code protection method provided in this embodiment establishes an encrypted JAR package, modifies the program loader based on the encrypted JAR package, encrypts the encrypted Java program code according to the modified program loader, and modifies the class decryption component to decrypt the encrypted Java program code, thereby increasing the difficulty of exporting bytecode and reducing the probability of program errors.
[0045] In some embodiments of the present invention, establishing an encrypted jar package includes: establishing an authenticated encrypted java project, and compiling and packaging the authenticated encrypted java project into an encrypted jar package.
[0046] In the above embodiment, an encrypted Java code project is first written to implement the encryption and authentication algorithm. This Java code project is then compiled and packaged into a JAR file. JAR is a platform-independent file format that combines multiple files into a single file. JAR files are cross-platform, eliminating the need to worry about specific platform issues. Besides audio and image files, they can also include class files.
[0047] In some embodiments of the present invention, the Java program loader is modified according to the encrypted jar package in the folder to be called, including: overwriting the original program loader with the encrypted jar package and modifying the original program loader.
[0048] In the above embodiment, although the original Java program loader can only recognize the general Java language, it does not have the ability to recognize the programmed Java encryption code project. By modifying the original Java program loader, the modified Java program loader can recognize the programmed encryption logic.
[0049] It is understandable that since the entire JAR package is encrypted, it can also protect other resources besides Java code.
[0050] In some embodiments of the present invention, after the Java program loader is modified according to the encrypted jar package in the folder to be called, the method includes: modifying the class decryption component of the JVM through a customized preset algorithm and the encrypted jar package.
[0051] In the above embodiment, the customized preset algorithm is a written decryption algorithm, which is a logic for decryption based on the encrypted jar package. The class decryption component of the JVM is modified according to the encrypted jar package and the customized preset algorithm to enable the class decryption component to decrypt the encrypted resource files.
[0052] In some embodiments of the present invention, before modifying the class decryption component of the JVM using a customized preset algorithm and an encrypted jar package, the method further includes: loading the encrypted jar package into a preset memory area.
[0053] In the above embodiment, when modifying the class decryption component of the JVM, the encrypted jar package needs to be loaded into a specific memory area first, which can avoid the original operation of the jar on the disk being easily captured and decrypted by some specific decryption programs.
[0054] In some embodiments of the present invention, encrypting the Java program code to be encrypted according to the modified Java program loader includes: encrypting the Java program code to be encrypted by the modified program loader.
[0055] In the above embodiment, the Java program loader is modified to recognize the logic of the encrypted code, thereby realizing encryption of the Java program code. It is understandable that the present invention can also realize the protection capability of other resources besides Java code in addition to encrypting Java program code.
[0056] In some embodiments of the present invention, the class decryption component of the JVM is modified to decrypt the encrypted Java program code, including: decrypting the file encrypted by the Java program loader according to the modified class decryption component of the JVM.
[0057] In the above embodiment, by modifying the JVM's class decryption component, the decryption component can decrypt encrypted resources. After the decryption component is overwritten and updated in the JVM, a set of pre-startup logic steps for encryption and decryption are implemented that are different from those of general Java programs.
[0058] It's important to note that a custom JRE program launcher is used to decrypt the pre-encrypted JAR package and load it into a specific memory area. The Classloader then uses a custom protocol to load the JAR package from this memory area, completing the program loading process. To prevent the Classloader file from being decompiled and exposing the decrypted JAR package, the Classloader bytecode file must be encrypted separately. This encryption and decryption can be accomplished by creating an encryption and decryption component (a .dll or .so file) using Java TI technology and adding it to the classpath. This component is then added as a startup parameter at program startup, completing the entire program startup process.
[0059] In order to better implement the Java program code protection method in the embodiment of the present invention, based on the Java program code protection method, please refer to Figure 2 , Figure 2 This is a schematic diagram of the structure of an embodiment of a Java program code protection device provided by the present invention. The embodiment of the present invention provides a Java program code protection device 200, including:
[0060] Establishing module 201, used to establish an encrypted jar package and store the encrypted jar package in a folder to be called;
[0061] Modification module 202, used to modify the Java program loader according to the encrypted jar package in the folder to be called;
[0062] The encryption module 203 is used to encrypt the Java program code to be encrypted according to the modified Java program loader;
[0063] The decryption module 204 is used to modify the class decryption component of the JVM to decrypt the encrypted Java program code.
[0064] It should be noted here that the device 200 provided in the above embodiment can implement the technical solutions described in the above method embodiments. The specific implementation principles of the above modules or units can be found in the corresponding contents in the above method embodiments, which will not be repeated here.
[0065] See also Figure 3 , Figure 3 This is a schematic diagram of the structure of an electronic device for protecting Java program code according to an embodiment of the present invention. Based on the aforementioned Java program code protection method, the present invention also provides a corresponding Java program code protection device. The Java program code protection device can be a computing device such as a mobile terminal, desktop computer, notebook, PDA, or server. The Java program code protection device includes a processor 310, a memory 320, and a display 330. Figure 3Only some of the components of the electronic device are shown, but it should be understood that it is not required to implement all of the shown components, and more or fewer components may be implemented instead.
[0066] In some embodiments, the memory 320 may be an internal storage unit of the Java program code protection device, such as a hard disk or memory of the Java program code protection device. In other embodiments, the memory 320 may also be an external storage device of the Java program code protection device, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) card, a Flash Card, etc. equipped with the Java program code protection device. Furthermore, the memory 320 may include both an internal storage unit of the Java program code protection device and an external storage device. The memory 320 is used to store application software installed in the Java program code protection device and various data, such as the program code used to install the Java program code protection device. The memory 320 may also be used to temporarily store data that has been output or is about to be output. In one embodiment, the memory 320 stores a Java program code protection program 340, which can be executed by the processor 310 to implement the Java program code protection method of each embodiment of the present application.
[0067] In some embodiments, the processor 310 may be a central processing unit (CPU), a microprocessor, or other data processing chip, configured to execute program codes stored in the memory 320 or process data, such as executing a Java program code protection method.
[0068] In some embodiments, display 330 can be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, or an OLED (Organic Light-Emitting Diode) touchscreen. Display 330 is used to display information on the Java program code protection device and to display a visual user interface. Components 310-330 of the Java program code protection device communicate with each other via a system bus.
[0069] In one embodiment, when the processor 310 executes the Java program code protection program 340 in the memory 320 , the steps in the above Java program code protection method are implemented.
[0070] This embodiment further provides a computer-readable storage medium storing a Java program code protection program. When the Java program code protection program is executed by a processor, the following steps are implemented:
[0071] Create an encrypted jar package and store it in the folder to be called;
[0072] Modify the Java program loader according to the encrypted jar package in the folder to be called;
[0073] Encrypt the Java program code to be encrypted according to the modified Java program loader;
[0074] Modify the JVM's class decryption component to decrypt the encrypted Java program code.
[0075] In summary, the present embodiment provides a Java program code protection method, apparatus, device and storage medium, which establishes an encrypted JAR package, modifies the program loader based on the encrypted JAR package, encrypts the encrypted Java program code according to the modified program loader, modifies the class decryption component, and decrypts the encrypted Java program code, thereby increasing the difficulty of exporting bytecode and reducing the probability of program errors.
[0076] The above description is only a preferred specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by any technician familiar with this technical field within the technical scope disclosed by the present invention should be covered by the scope of protection of the present invention.
Claims
1. A Java program code protection method, characterized in that: include: Create an encrypted jar package and store it in the folder to be called; Overwrite the original program loader with the encrypted jar package and modify the original program loader; Encrypt the Java program code to be encrypted through the modified program loader; Load the encrypted jar package into a preset memory area, and modify the JVM class decryption component using a custom preset algorithm and the encrypted jar package; According to the class decryption component of the modified JVM, the file encrypted by the Java program loader is decrypted.
2. The Java program code protection method according to claim 1, wherein: The method of establishing the encrypted jar package includes establishing an authenticated encrypted java project, and compiling and packaging the authenticated encrypted java project into the encrypted jar package.
3. A Java program code protection device, characterized in that: include: A creation module is used to create an encrypted jar package and store the encrypted jar package in a folder to be called; A modification module, used to overwrite the original program loader with the encrypted jar package and modify the original program loader; The encryption module is used to encrypt the Java program code to be encrypted through the modified program loader, load the encrypted JAR package into a preset memory area, and modify the JVM class decryption component using a custom preset algorithm and the encrypted JAR package; The decryption module is used to decrypt the file encrypted by the Java program loader according to the class decryption component of the modified JVM.
4. An electronic device, characterized in that: comprising a memory and a processor, wherein, The memory is used to store programs; The processor is coupled to the memory and is configured to execute the program stored in the memory to implement the steps of the Java program code protection method according to any one of claims 1 to 2.
5. A computer-readable storage medium, characterized in that Used to store computer-readable programs or instructions, which, when executed by a processor, can implement the steps of the Java program code protection method described in any one of claims 1-2.
Citation Information
Patent Citations
Code encryption and decryption method and device and storage medium
CN112966227A
Spring container-based class file encryption method and equipment
CN113221077A