Java application protection method based on PKI-JNA
By using a PKI-JNA-based method, a public-private key pair is generated and used to encrypt a Java application. The PKI private key is used to verify identity, and JNA is used to encrypt the bytecode file. This solves the problems of Java applications being easily decompiled and insufficient encryption protection, and achieves enhanced security and authentication.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-17
- Publication Date
- 2026-04-14
AI Technical Summary
Java applications are easily decompiled. Existing technologies are not robust enough for user authentication and offer limited encryption protection for other ordinary application files, making it easy for important basic files such as application configuration files to be leaked.
The method adopts a PKI-JNA-based approach to generate public-private key pairs, uses the PKI public key to encrypt random keys, uses JNA to encrypt bytecode files, and combines PKI private key authentication and random key decryption to form a triple security protection, supporting secondary encryption of multiple algorithms.
It improves the code security of Java applications, enhances user authentication, increases the difficulty of cracking, prevents the risk of application cracking, and supports national cryptographic algorithms to enhance encryption strength.
Smart Images

Figure CN117056880B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of application protection and anti-reverse engineering technology, and in particular to a Java application protection method based on PKI-JNA. Background Technology
[0002] Java is an object-oriented programming language that compiles code into bytecode files, which run on the JVM virtual machine for cross-platform deployment. Java decompilation is the process of reverse-engineering a Java executable program to obtain the original code. Normally compiled Java bytecode files are easily decompiled, making Java applications vulnerable to piracy. Current Java anti-decompilation techniques include code obfuscation and bytecode encryption. However, existing technologies are not robust enough for user authentication, support relatively fixed algorithms, and offer limited encryption protection for other ordinary application files, making it easy to leak important foundational files such as application configuration files. Summary of the Invention
[0003] In view of this, the purpose of this invention is to provide a Java application protection method based on PKI-JNA, which uses PKI public key facilities and JNA technology to solve the problem of preventing Java application decompilation and improve application code security.
[0004] To achieve the above objectives, the present invention adopts the following technical solution: a Java application protection method based on PKI-JNA, comprising the following steps:
[0005] Step S1: Generate a public key-private key pair based on the PKI facility, generate a random encryption key, and encrypt it using the PKI public key;
[0006] Step S2: Encrypt the bytecode binary file using JNA;
[0007] Step S3: Use a random key to encrypt the bytecode file and other files that need protection a second time;
[0008] Step S4: Authenticate using the PKI private key and obtain a random key;
[0009] Step S5: Decrypt the bytecode file and other protected files using a random key;
[0010] Step S6: Use JNA to decrypt the bytecode file a second time.
[0011] In a preferred embodiment: a random key is encrypted using a PKI public key, and each user has a different random key and a PKI private key.
[0012] In a preferred embodiment: the identity is verified using a PKI private key and a random key is obtained. If the PKI private key verification fails, the application cannot be used. A custom bytecode class loader is used in conjunction with JNA to decrypt and load the encrypted bytecode file.
[0013] In a preferred embodiment: the bytecode file is encrypted using JNA, the bytecode file is then encrypted a second time using a random key, and other files that need to be protected are also encrypted using a random key. PKI, JNA, and random keys form a triple security protection, effectively preventing the application from being cracked.
[0014] In a preferred embodiment: through a PKI public key facility mechanism and supporting national cryptographic algorithms for enhanced authentication, encrypted bytecode files and other protected files cannot be viewed by decompilation software.
[0015] Compared with existing technologies, the present invention has the following advantages: The present invention uses a PKI public key facility mechanism, JNA to encrypt bytecode files, and supports random keys with multiple algorithms to encrypt bytecode files and other ordinary files that need protection. PKI, JNA, and random keys form a three-layer protection to ensure the security of application code, greatly increasing the difficulty of cracking. The present invention also adds user authentication through the PKI public key facility mechanism. The PKI of the present invention supports the national cryptographic SM2 algorithm, and the random key encryption process supports the national cryptographic SM4 algorithm.
[0016] This invention utilizes the PKI public key infrastructure mechanism to support national cryptographic algorithms, enhance authentication, encrypt bytecode files using JNA, and support secondary encryption of bytecode files and other ordinary files requiring protection using random keys with multiple algorithms, effectively preventing the risk of application cracking.
[0017] Specifically, this includes the following aspects:
[0018] (1) It supports both encrypted bytecode files and ordinary files, making it difficult to crack:
[0019] This invention utilizes a PKI public key infrastructure mechanism and JNA to encrypt bytecode files. It supports multiple algorithms and random keys for secondary encryption of bytecode files and other ordinary files requiring protection. PKI, JNA, and random keys form a three-tiered protection system to safeguard application code security and effectively prevent the risk of application cracking.
[0020] (2) Enhance user authentication:
[0021] This invention enhances user authentication through the PKI public key infrastructure mechanism.
[0022] (3) Supports national cryptographic algorithms:
[0023] The PKI of this invention supports the national standard SM2 algorithm, and the random key encryption process supports the national standard SM4 algorithm. Attached Figure Description
[0024] Figure 1 This is a flowchart of a preferred embodiment of the present invention. Detailed Implementation
[0025] The present invention will be further described below with reference to the accompanying drawings and embodiments.
[0026] like Figure 1 As shown in the figure, this embodiment of a Java application protection method based on PKI-JNA includes the following steps:
[0027] Step S1: Generate a public key-private key pair based on the PKI facility, generate a random encryption key, and encrypt it using the PKI public key;
[0028] Step S2: Use JNA to break down and encrypt the bytecode binary file;
[0029] Step S3: Use a random key to encrypt the bytecode file and other files that need protection a second time;
[0030] Step S4: Authenticate using the PKI private key and obtain a random key;
[0031] Step S5: Decrypt the bytecode file and other protected files using a random key;
[0032] Step S6: Use JNA to decrypt the bytecode file a second time.
[0033] In this embodiment, the PKI public key generated in step S1 is used to encrypt and protect the random key. During decryption, the random key is obtained based on the user's PKI private key. This protects the key and authenticates the user's identity, ensuring confidentiality and integrity. The random key encryption supports a variety of encryption algorithms and national cryptographic algorithms, such as AES, DES, and SM4.
[0034] In this embodiment, the generation of PKI public and private keys, the generation of random keys, and the encryption of bytecode files and other files requiring protection are handled by the application developer. The user utilizes the valid PKI private key provided by the application developer to decrypt the application. PKI, JNA, and the random key form a three-tiered protection system to safeguard application code security and effectively prevent the application from being compromised.
[0035] In this embodiment, encrypted bytecode binary content is loaded using a custom bytecode class loader. The custom bytecode class loader then calls a JNA method to decrypt the encrypted content generated in step S2. JNA is used to encrypt the custom bytecode class loader, preventing the decryption method from being cracked through the class loader.
[0036] In this embodiment, non-bytecode files can be encrypted using a combination of PKI and a random key to protect critical application files such as configuration files, MyBatis SQL mapping files, Hibernate ORM mapping files, XML files, and Excel templates. The random key algorithm supports AES, DES, the Chinese national standard SM4, and other related encryption algorithms.
[0037] In this embodiment, authentication is enhanced through PKI public key infrastructure mechanism and national cryptographic algorithm, making it impossible to view encrypted bytecode files and other protected files, such as application configuration files, through decompilation software.
[0038] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0039] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0040] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0041] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0042] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention in any other way. Any person skilled in the art may make changes or modifications to the above-disclosed technical content to create equivalent embodiments. However, any simple modifications, equivalent changes, and modifications made to the above embodiments based on the technical essence of the present invention without departing from the scope of the present invention shall still fall within the protection scope of the present invention.
[0043] The above are preferred embodiments of the present invention. Any changes made to the technical solution of the present invention that do not exceed the scope of the technical solution of the present invention shall fall within the protection scope of the present invention.
Claims
1. A Java application protection method based on PKI-JNA, characterized in that, Includes the following steps: Step S1: Generate a public key-private key pair based on the PKI facility, generate a random encryption key, and encrypt it using the PKI public key; Step S2: Encrypt the bytecode binary file using JNA; Step S3: Use a random key to encrypt the bytecode file and other files that need protection a second time; Step S4: Authenticate using the PKI private key and obtain a random key; Step S5: Decrypt the bytecode file and other protected files using a random key; Step S6: Use JNA to decrypt the bytecode file a second time; The random key is encrypted using the PKI public key, and each user has a different random key and PKI private key; The identity is verified using the PKI private key and a random key is obtained. If the PKI private key verification fails, the application cannot be used. A custom bytecode class loader is used in conjunction with JNA to decrypt and load the encrypted bytecode file. The bytecode file is encrypted using JNA, then encrypted again using a random key, and other files requiring protection are also encrypted using a random key. PKI, JNA, and random keys form a triple security defense, effectively preventing the application from being cracked. By utilizing the PKI public key infrastructure mechanism and supporting national cryptographic algorithms for enhanced authentication, encrypted bytecode files and other protected files cannot be viewed through decompilation software.
Citation Information
Patent Citations
Encryption method, decryption method, storage medium and terminal equipment
CN112165490A
Method and device for protecting source code of resource package
CN115525902A