Method for encrypting Java files

By using the combination of RSA and AES algorithms for dynamic verification during Java class loading, the problem of difficulty in preventing decompilation of existing Java class files is solved, and the secure loading and timeliness of class files are realized, and the encryption and decryption are improved. Security and flexibility.

CN119210793AInactive Publication Date: 2024-12-27XIAMEN BEST DIGITAL TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411224025.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-03
Publication Date
2024-12-27
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

Existing Java class file encryption methods cannot effectively prevent decompilation, especially when using Spring framework or other dependency injection into the IOC framework, code obfuscation cannot achieve true encryption.

Method used

Through a dynamic database, a layer of verification is performed during class loading, the public and private keys are generated using the RSA encryption algorithm, and the keys are generated in the custom class loader in combination with the AES encryption algorithm, and the decryption verification is performed in the dynamic link library. The class file will be loaded, otherwise an exception will be thrown.

Benefits of technology

It realizes effective encryption of Java class files, prevents class files from being exposed, improves the security of the encryption and decryption process, and realizes dynamic control through version number and validity period to ensure the timeliness of file usage.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119210793A_ABST
    Figure CN119210793A_ABST
Patent Text Reader

Abstract

The invention provides a method for encrypting Java files, and relates to the technical field of network security, and the method comprises the steps: generating a public key A, a private key B, and a version number identifier V and a valid period D of each pair of the public key A and the private key B by using an RSA encryption algorithm; according to the public key A, the version number identifier V and the valid period D, an encryption module uses an AES encryption algorithm to obtain a secret key C in a custom class loader, and the secret key C is stored in the custom class loader; according to the public key A, the version number identifier V, the valid period D, the private key B and the secret key C, performing decryption in the dynamic link library by using a decryption function to obtain a decryption result; and according to the decryption result, the user-defined class loader carries out judgment to obtain a judgment result, if the judgment result is R, class files continue to be loaded, and if the judgment result is F, abnormity is thrown out, and the loading process is terminated. According to the method, class loading is controlled by performing one-layer verification on the dynamic database in the class loading process, and class file exposure is prevented.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of network security, and in particular to a method for encrypting a Java class file. Background Art

[0002] General Java class encryption settings make it difficult for humans to read and understand, but can still be decompiled into human-readable source code through decompilation tools. In addition, many applications use the Spring framework or other dependency injection IOC frameworks. Therefore, code obfuscation cannot achieve truly effective encryption. Summary of the invention

[0003] The present invention provides a method for encrypting a Java class file, which controls class loading by performing a layer of verification in a class loading process through a dynamic database to prevent class file exposure.

[0004] In order to solve the above technical problems, the technical solution of the present invention is as follows:

[0005] A method for encrypting a Java class file, the method comprising:

[0006] Use the RSA encryption algorithm to generate the public key A and the private key B and the version number V and validity period D of each pair of public key A and private key B;

[0007] According to the public key A, version number V, and validity period D, in the custom class loader, the encryption module uses the AES encryption algorithm to obtain the key C, and stores the key C in the custom class loader;

[0008] According to the public key A, the version number V, the validity period D, the private key B, and the key C, the decryption function is used in the dynamic link library to decrypt to obtain the decryption result;

[0009] According to the decryption result, the custom class loader makes a judgment to obtain a judgment result. If it is R, the class file continues to be loaded. If it is F, an exception is thrown and the loading process is terminated.

[0010] Furthermore, the key management system uses the RSA encryption algorithm to obtain the public key A, the private key B, the version number V and the validity period, including:

[0011] The key management system uses the RSA encryption algorithm to generate a pair of public and private keys;

[0012] The key management system assigns a unique version number V to each pair of public and private keys;

[0013] The key management system sets an expiration date D for each pair of public and private keys;

[0014] The key management system stores the public key A, private key B, version number identifier V, and expiration date D.

[0015] Furthermore, the key management system uses the RSA encryption algorithm to generate a pair of public and private keys, including:

[0016] Select prime numbers p and q;

[0017] According to p and q, use the formula n = p × q to calculate the modulus n;

[0018] According to the modulus n, use the formula Φ(n) = (p - 1)(q - 1) to calculate the Euler's totient function Φ(n) of n;

[0019] Select an integer e as the public key exponent, where 1 < e < Φ(n) and e is relatively prime to Φ(n);

[0020] According to the public key exponent e, use the formula d × e ≡ 1 (mod Φ(n)) to calculate the private key exponent d;

[0021] According to the modulus n, public key exponent e, and private key exponent d, obtain the public key (e, n) and private key (d, n).

[0022] Furthermore, according to the public key A, version number identifier V, and expiration date D, in the custom class loader, the encryption module uses the AES encryption algorithm to obtain the key C and stores the key C in the custom class loader, including:

[0023] Obtain the public key A, version number identifier V, and expiration date D;

[0024] Perform AES encryption on the public key A to obtain the encrypted string S;

[0025] Combine the version number V, expiration date D, and the encrypted string S to obtain the combined string S1;

[0026] According to the combined string S1, use the RSA algorithm to encrypt the combined string S1 to obtain the key C, where S1 = V + S + D;

[0027] Store the key C in the custom class loader.

[0028] Furthermore, after storing the key C in the custom class loader, obtain the dynamic link library connection method and return result, including:

[0029] In the custom class loader, set the path and parameters for connecting to the dynamic link library;

[0030] Use the decryption function in the dynamic link library to pass the public key A, version number V, expiration date D, and key C;

[0031] After the decryption function of the dynamic link library is executed, the return result is obtained. If the decryption is successful and the verification is passed, the result R is returned. If the decryption fails or the verification fails, the result F is returned.

[0032] Return the result to the custom class loader.

[0033] Further, according to the public key A, the version number identifier V, the validity period D, the private key B, and the key C, a decryption function is used in the dynamic link library to perform decryption to obtain a decryption result, including:

[0034] Define a decryption function in the dynamic link library and obtain the public key A, version number V, validity period D, and key C;

[0035] Use the decryption function in the dynamic link library to retrieve the corresponding private key B in the key management system according to the version number V and the validity period D;

[0036] Perform AES encryption on the public key A to obtain the encrypted string S';

[0037] The version number V, the encrypted string S' and the expiration date D are combined into the final string S'1, where S'1 = V + S' + D;

[0038] Use private key B to decrypt key C using the RSA decryption method to obtain the decrypted string S'2.

[0039] Further, the string S'1 and the string S'2 are obtained, and the string S'1 is compared with the string S'2 to return a result;

[0040] If the string S'1 is equal to the string S'2, the verification is successful and the result R is returned;

[0041] If the string S'1 is not equal to the string S'2, the verification fails and the result F is returned;

[0042] Pass the returned result to the custom class loader.

[0043] Furthermore, according to the decryption result, the custom class loader makes a judgment to obtain a judgment result. If it is R, the class file continues to be loaded. If it is F, an exception is thrown and the loading process is terminated, including:

[0044] After calling the decryption function of the dynamic link library, the custom class loader receives the returned result;

[0045] The custom class loader makes a judgment based on the returned result to obtain the judgment result;

[0046] If the result is R, continue the class loading process, load the corresponding class file according to the returned network path, and load it into the Java virtual machine using the standard Java class loading mechanism;

[0047] If the result is F, throw an exception and terminate the class loading process.

[0048] Furthermore, the encryption module and the dynamic link library work together to perform real-time verification during the Java class file loading process.

[0049] Furthermore, the version number V and the validity period D are used to dynamically control the usage period of Java class files.

[0050] The above solution of the present invention includes at least the following beneficial effects:

[0051] The above scheme of the present invention controls class loading by performing a layer of verification in the class loading process through a dynamic database to prevent class file exposure; the function of encrypting files is dynamically achieved through the dynamic database; these encrypted items can be scanned and decoded smoothly during the startup phase under the Java framework, and the encryption and decryption process has a high degree of security; the file usage time can be dynamically managed according to the version number and validity period. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] Figure 1 It is a schematic diagram of a method for encrypting a Java class file provided by an embodiment of the present invention.

[0053] Figure 2 It is a flowchart of a method for encrypting a Java class file provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0054] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.

[0055] like Figure 1 As shown, an embodiment of the present invention provides a method for encrypting a Java class file, the method comprising:

[0056] Use the RSA encryption algorithm to generate the public key A and the private key B and the version number V and validity period D of each pair of public key A and private key B;

[0057] According to the public key A, version number V, and validity period D, in the custom class loader, the encryption module uses the AES encryption algorithm to obtain the key C, and stores the key C in the custom class loader;

[0058] According to the public key A, the version number V, the validity period D, the private key B, and the key C, the decryption function is used in the dynamic link library to decrypt to obtain the decryption result;

[0059] According to the decryption result, the custom class loader makes a judgment to obtain a judgment result. If it is R, the class file continues to be loaded. If it is F, an exception is thrown and the loading process is terminated.

[0060] In an embodiment of the present invention, a public key A (Public Key A) and a private key B (Private Key B) are generated by an RSA algorithm. RSA is an asymmetric encryption algorithm. The public key is used to encrypt data, while the private key is used to decrypt data. The version number identifier V (Version Identifier) ​​and the validity period D (Validity Period) are used to manage the version and validity of the key to ensure that the system can verify the legitimacy of the key during use. In a custom class loader, an AES key C is generated using the public key A, the version number V and the validity period D. AES is a symmetric encryption algorithm suitable for encrypting a large amount of data. The key C is stored in the custom class loader to ensure that the key can only be accessed through a legitimate RSA public key and related parameters. In a dynamic link library, decryption is performed using the public key A, the version number V, the validity period D, the private key B and the key C to obtain a decryption result. The decryption result usually contains some important information, such as an identifier of whether to allow loading of a class, etc. The custom class loader makes a judgment based on the decryption result. If the result is R, the class file continues to be loaded; if the result is F, an exception is thrown and the loading process is terminated.

[0061] like Figure 1 As shown, the key management system uses the RSA encryption algorithm to obtain the public key A, private key B, version number V and validity period, including:

[0062] The key management system uses the RSA encryption algorithm to generate a pair of public and private keys;

[0063] The key management system assigns a unique version number V to each pair of public and private keys;

[0064] The key management system sets an expiration date D for each pair of public and private keys;

[0065] The key management system stores the public key A, private key B, version number V and validity period D.

[0066] In the embodiments of the present invention, a public key A and a private key B are generated through the RSA algorithm. The public key is used to encrypt data, and the private key is used to decrypt data. The asymmetric encryption method ensures the security of data transmission. Only the entity holding the private key can decrypt the data encrypted by the public key, improving the security of data transmission and preventing unauthorized access and data leakage. A unique version number identifier V is assigned to each pair of public and private keys to facilitate tracking and management of the key versions, enabling the system to identify different versions of keys, facilitating subsequent key updates and replacements, enhancing the flexibility and traceability of key management, and ensuring that there is no confusion when the system updates keys. A validity period D is set for each pair of public and private keys to ensure that the keys expire after a certain period of time, which can effectively prevent the keys from being used for a long time and being obtained by attackers, improving the security of the system, reducing the risk of key abuse, forcing regular key updates, and enhancing the overall security. The public key A, private key B, version number V, and validity period D are securely stored to ensure that the information can be securely accessed and used when needed. They will be stored in a secure database or key management system to ensure that they are not easily accessible by unauthorized parties, ensuring the security of the keys and related information, facilitating auditing and compliance checks, providing centralized management of the keys, and making the use and update of keys more efficient.

[0067] As Figure 1 shown, the key management system uses the RSA encryption algorithm to generate a pair of public and private keys, including:

[0068] Select prime numbers p and q;

[0069] According to p and q, using the formula n = p × q, calculate the modulus n;

[0070] According to the modulus n, using the formula Φ(n) = (p - 1)(q - 1), calculate the Euler's totient function Φ(n) of n;

[0071] Select an integer e as the public key exponent, where 1 < e < Φ(n) and e is relatively prime to Φ(n);

[0072] According to the public key exponent e, using the formula d × e ≡ 1 (mod Φ(n)), calculate the private key exponent d;

[0073] According to the modulus n, public key exponent e, and private key exponent d, obtain the public key (e, n) and the private key (d, n).

[0074] In the embodiment of the present invention, two large prime numbers p and q are first selected. The security of the two prime numbers is crucial to the overall security of RSA. The large prime numbers are selected to improve the strength of encryption and ensure that cracking is extremely difficult, because the security of RSA depends on the difficulty of prime number decomposition. Large prime numbers make the generated key more difficult for attackers to reversely calculate, thereby improving the encryption security. According to the selected prime numbers p and q, the modulus n is used to generate public keys and private keys, which is a core component of the RSA algorithm. The size of the modulus n affects the security and encryption efficiency of RSA. Usually, a sufficiently large n is selected to enhance security. The Euler function is used to subsequently calculate the exponents of the public key and the private key, determine the available public key exponents, and ensure that the generation of the public key and the private key complies with RSA. The mathematical basis of RSA ensures that the relationship between the two is correct. The public key exponent e is a key parameter in the encryption process. The commonly used choice is 65537 because it satisfies the coprime condition and has high computational efficiency. Choosing a suitable e ensures the effectiveness and security of the encryption process and avoids the situation of sharing factors with Φ(n). The private key exponent d is used to decrypt data encrypted by the public key, ensuring that only the person holding the private key can decrypt the message, ensuring the mathematical relationship between the private key d and the public key e, so that the encryption and decryption processes can correspond correctly. The public key is used to encrypt data and the private key is used to decrypt data. The public key can be made public, while the private key must be kept confidential, forming a pair of keys to support secure information transmission. The publicity of the public key and the privacy of the private key constitute the core of RSA encryption.

[0075] like Figure 1 As shown, according to the public key A, version number V, and validity period D, in the custom class loader, the encryption module uses the AES encryption algorithm to obtain the key C, and stores the key C in the custom class loader, including:

[0076] Get the public key A, version number V, and validity period D;

[0077] Perform AES encryption on the public key A to obtain the encrypted string S;

[0078] By combining the version number V, the expiration date D and the encrypted string S, a combined string S1 is obtained;

[0079] According to the combined string S1, the combined string S1 is encrypted using the RSA algorithm to obtain the key C, where S1 = V + S + D;

[0080] Store key C in a custom class loader.

[0081] In the embodiment of the present invention, it is ensured that the latest and legal keys and related parameters are used in the encryption process, which enhances the security of the system, lays a foundation for subsequent encryption operations, and ensures that the system can effectively manage keys during operation; AES encryption of the public key can protect the public key from being directly exposed, thereby increasing the security of the key. Even if someone obtains the public key A, unauthorized persons cannot use it directly because they cannot decrypt the string S encrypted by AES; a combined string containing multiple important information is created to provide context for subsequent encryption, ensuring that the generation of the key C is unique and valid. The combined string S1 not only contains the version and validity information, but also contains the public key encrypted by AES, thereby improving the overall security and information integrity; through RSA encryption, it is ensured that only the person holding the corresponding private key can decrypt the key C, thereby realizing the secure transmission and storage of the key. The generation process of the key C ensures that even if the attacker obtains the combined string S1, the key C cannot be decrypted, thereby enhancing the security of the system; it is ensured that the key C can be securely accessed when needed and can be used during the class loading process. By storing the key C in the custom class loader, the system can dynamically use the key to decrypt data, thereby ensuring the secure loading of the class.

[0082] like Figure 1 As shown, after storing key C in the custom class loader, the dynamic link library connection method and return results are obtained, including:

[0083] In the custom class loader, set the path and parameters for connecting to the dynamic link library;

[0084] Use the decryption function in the dynamic link library to pass the public key A, version number V, validity period D, and key C;

[0085] After the decryption function of the dynamic link library is executed, the return result is obtained. If the decryption is successful and the verification is passed, the result R is returned. If the decryption fails or the verification fails, the result F is returned.

[0086] Return the result to the custom class loader.

[0087] In an embodiment of the present invention,

[0088] In your description, ensure that the custom class loader can correctly find and call the required dynamic link library to prepare for the subsequent decryption operation. By correctly configuring the path and parameters, it can achieve effective interaction with the external library and ensure that the decryption function can be executed smoothly. Use the efficient decryption algorithm implemented in the dynamic link library to decrypt and verify the data. Through the decryption function of the dynamic link library, the performance and security of the decryption operation are improved, and the optimized algorithm is used to increase the processing speed. After the decryption function of the dynamic link library is executed, a result is returned. Depending on whether the decryption is successful or not and whether the verification is passed, the result R or F may be returned. Decryption is successful and the verification is passed: return result If the result R is returned, it means that the class file can continue to be loaded; if the decryption fails or the verification fails: the result F is returned, indicating that the loading process needs to be terminated and an exception is thrown; the decryption result is used to determine whether the class loading process is allowed to continue, ensuring that the loaded class files are legal and safe. The return of the result enables the system to make dynamic decisions based on the effectiveness of the decryption and enhance the security of the system; the decryption result R or F is returned to the custom class loader for subsequent processing; the custom class loader determines whether to continue loading the class file or throw an exception based on the returned result, ensuring that the class loading process is safe and only verified class files can be loaded, thereby reducing potential security risks.

[0089] like Figure 1 As shown, according to the public key A, version number identifier V, validity period D, private key B, and key C, a decryption function is used in the dynamic link library to decrypt to obtain a decryption result, including:

[0090] Define a decryption function in the dynamic link library and obtain the public key A, version number V, validity period D, and key C;

[0091] Use the decryption function in the dynamic link library to retrieve the corresponding private key B in the key management system according to the version number V and the validity period D;

[0092] Perform AES encryption on the public key A to obtain the encrypted string S';

[0093] The version number V, the encrypted string S' and the expiration date D are combined into the final string S'1, where S'1 = V + S' + D;

[0094] Use private key B to decrypt key C using the RSA decryption method to obtain the decrypted string S'2.

[0095] In the embodiment of the present invention, all input parameters required for decryption are prepared so that the decryption operation can be correctly performed when the function is executed, ensuring that the decryption function can flexibly receive external parameters, and improving the reusability and modularity of the code; ensuring the security and effectiveness of the decryption operation, avoiding the use of expired or mismatched private keys for decryption, and enhancing the key management by verifying the version number and validity period, ensuring the legitimacy and effectiveness of the private key B; protecting the public key A through AES encryption to prevent it from being unauthorized access or tampering during transmission. Even if the attacker obtains the public key A, if S' is not decrypted, the public key A cannot be used for illegal operations, thereby enhancing the security of the system; creating a combined string containing all important information for subsequent decryption and verification, ensuring the context integrity of subsequent operations, so that the decryption process has enough information for verification; decrypting the key C into usable plaintext, facilitating subsequent operations, such as using the key to decrypt data, etc. If the decryption is successful, the system will obtain valid key information to ensure that the next step of safe operation can be performed. If the decryption fails, it means that the key C may have been tampered with or is no longer valid, thereby improving the security of the system.

[0096] like Figure 1 As shown, obtain the string S'1 and the string S'2, compare the string S'1 with the string S'2, and return the result;

[0097] If the string S'1 is equal to the string S'2, the verification is successful and the result R is returned;

[0098] If the string S'1 is not equal to the string S'2, the verification fails and the result F is returned;

[0099] Pass the returned result to the custom class loader.

[0100] In the embodiment of the present invention, it is ensured that there are two strings that need to be compared in the verification stage, which respectively represent the relevant information generated in the encryption and decryption processes; it provides clear basic data for the subsequent verification steps to ensure that effective comparison can be performed; if S'1 is equal to S'2, it means that the decryption and verification process is successful and the data has not been tampered with; if S'1 is not equal to S'2, it means that the decryption fails or the data has been tampered with, and the system should take measures to prevent potential security risks; through comparison, the system can effectively judge the validity of the decryption result and ensure the security of subsequent operations; the verification result is fed back to the custom class loader to determine the subsequent operation, and the result R: the subsequent operation is allowed. Continue to load class files to ensure that the class loaded by the system is a verified safe class; Result F: Terminate the loading process and throw an exception to prevent the loading of unsafe classes and protect the system from potential attacks; Through the returned result, the system can dynamically control the class loading process, improve the security of the entire application, and ensure that only legal and verified class files can be loaded; The custom class loader decides whether to continue loading the required class files based on the returned result; If the verification is successful, the loader continues to load the class to ensure the normal operation of the application; If the verification fails, the loader throws an exception to ensure that unsafe classes are not loaded, thereby protecting the stability and security of the application.

[0101] like Figure 1 As shown, according to the decryption result, the custom class loader makes a judgment to obtain a judgment result. If it is R, the class file continues to be loaded. If it is F, an exception is thrown and the loading process is terminated, including:

[0102] After calling the decryption function of the dynamic link library, the custom class loader receives the returned result;

[0103] The custom class loader makes a judgment based on the returned result to obtain the judgment result;

[0104] If the result is R, continue the class loading process, load the corresponding class file according to the returned network path, and load it into the Java virtual machine using the standard Java class loading mechanism;

[0105] If the result is F, throw an exception and terminate the class loading process.

[0106] In the embodiment of the present invention, it is ensured that the class loader can obtain the results of the decryption and verification operations, which is crucial for subsequent judgments and operations; it provides a clear basis for the subsequent judgment process to decide whether to continue loading the class file; if the result is R, it means that the verification is successful, proving that the class file is legal and can be safely loaded; if the result is F, it means that the verification failed, there may be a security risk, and the loading process must be terminated; through the judgment results, the security and flexibility of the system are enhanced, and the loading strategy can be dynamically adjusted according to actual conditions; it is ensured that the verified class files can be successfully loaded into the application to ensure the normal operation of the program; the credibility of the system is improved, because only verified classes can be loaded; the loading process complies with the standard Java class loading mechanism to prevent unsafe or illegal class files from being loaded, thereby protecting the security of the system; by throwing exceptions, the system can respond to potential security risks in a timely manner to prevent the execution of unauthorized code; the stability and reliability of the system are enhanced to ensure that only verified security classes can be executed.

[0107] like Figure 1 As shown, the encryption module and the dynamic link library work together to perform real-time verification during the Java class file loading process.

[0108] In the embodiment of the present invention, the encryption module is responsible for generating keys and encrypting public keys, while the dynamic link library is responsible for decryption and verification. Through this collaboration, the system can verify the legitimacy of class files in real time at each step of class loading; implement security checks at key stages of the class loading process to ensure that only verified class files can be loaded into the Java virtual machine; by combining symmetric encryption (such as AES) and asymmetric encryption (such as RSA), the encryption module and the dynamic link library can dynamically manage the creation, storage and use of keys; ensure that verification can be performed according to the latest keys and security policies at runtime, and timely discover and prevent security risks; through the management of version numbers and validity periods, the system can ensure the validity of keys and class files within their life cycle. When loading class files, the system It can check the legitimacy of class files and their related keys to ensure that the loaded classes are the latest and do not exceed their validity period; through real-time verification, the system can effectively prevent code injection and unauthorized class loading, reducing potential security vulnerabilities; improve the security of the entire application, and protect sensitive data and system resources from malicious attacks; through dynamic verification and exception handling mechanisms, the system can remain stable in the face of potential security threats; increase the robustness of the system, ensure that only verified security classes can be executed, and prevent system crashes or errors caused by loading unsafe classes; the combination of encryption modules and dynamic link libraries enables the system to be adjusted according to different operating environments and requirements; developers can quickly update and manage keys according to changes in security policies to adapt to different application scenarios.

[0109] like Figure 1 As shown, the dynamic control of the usage period of Java class files is achieved through the version number V and the validity period D.

[0110] In the embodiment of the present invention, the version number identifier V assigns a unique identifier to each Java class file, indicating the version of the class file, so that the system can track and manage different versions of the class file. Through version control, the system can ensure that the latest class file version is loaded, avoid using outdated or incompatible classes, and thus reduce the risk of runtime errors; the validity period D sets a validity period for each Java class file, after which the class file will no longer be allowed to be loaded; the validity period management ensures that the system can update and replace expired class files in a timely manner to prevent security problems or functional deficiencies caused by the use of expired class files; during the class loading process, the system checks the version number V and validity period D of the class file in real time to ensure that only class files within the validity period and of the latest version can be loaded, and the dynamic verification mechanism can prevent unauthorized or expired class files from being loaded in real time. Loading, improving the security of the system; by implementing the management of version numbers and validity periods, the system can promptly identify and refuse to load potentially harmful or unsafe class files, reducing the risk of code injection and malicious attacks, and protecting the security of the system and user data; by forcing the use of the latest version of class files, the system can ensure functional consistency and compatibility, reduce runtime errors caused by version mismatches, and improve the stability and reliability of applications; the combination of version numbers and validity periods enables the system to flexibly manage the update and replacement of class files, and promptly deploy versions that repair or enhance functions, thereby improving the adaptability of the system and being able to quickly respond to changes in business needs and security threats; through a powerful dynamic management and control mechanism, users can trust the security and legality of the system when loading class files; this enhances user trust in the system and improves user satisfaction and usage experience.

[0111] The above is a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.

Claims

1. A method for encrypting a Java class file, characterized in that: The method includes: Using the RSA encryption algorithm to generate a public key A, a private key B, a version number identifier V, and an expiration date D for each pair of the public key A and the private key B; According to the public key A, the version number identifier V, and the expiration date D, in the custom class loader, the encryption module uses the AES encryption algorithm to obtain a key C and stores the key C in the custom class loader; According to the public key A, the version number identifier V, the expiration date D, the private key B, and the key C, use the decryption function in the dynamic link library for decryption to obtain a decryption result; According to the decryption result, the custom class loader makes a judgment to obtain a judgment result. If it is R, continue to load the class file. If it is F, throw an exception and terminate the loading process.

2. The method for encrypting a Java class file according to claim 1, characterized in that: The key management system uses the RSA encryption algorithm to obtain the public key A, the private key B, the version number identifier V, and the expiration date, including: The key management system uses the RSA encryption algorithm to generate a pair of public and private keys; The key management system assigns a unique version number identifier V to each pair of public and private keys; The key management system sets an expiration date D for each pair of public and private keys; The key management system stores the public key A, the private key B, the version number identifier V, and the expiration date D.

3. The method for encrypting a Java class file according to claim 2, characterized in that: The key management system uses the RSA encryption algorithm to generate a pair of public and private keys, including: Select prime numbers p and q; According to p and q, use the formula n = p × q to calculate the modulus n; According to the modulus n, use the formula Φ(n) = (p - 1)(q - 1) to calculate the Euler's totient function Φ(n) of n; Select an integer e as the public key exponent, where 1 < e < Φ(n) and e is relatively prime to Φ(n); According to the public key exponent e, use the formula d × e ≡ 1 (mod Φ(n)) to calculate the private key exponent d; According to the modulus n, the public key exponent e, and the private key exponent d, obtain the public key (e, n) and the private key (d, n).

4. The method for encrypting a Java class file according to claim 3, characterized in that: According to the public key A, the version number identifier V, and the expiration date D, in the custom class loader, the encryption module uses the AES encryption algorithm to obtain a key C and stores the key C in the custom class loader, including: Obtain the public key A, the version number identifier V, and the expiration date D; Perform AES encryption on the public key A to obtain an encrypted string S; Combine the version number V, the expiration date D, and the encrypted string S to obtain a combined string S1; According to the combined string S1, use the RSA algorithm to encrypt the combined string S1 to obtain the key C, where S1 = V + S + D; Store the key C in the custom class loader.

5. The method for encrypting a Java class file according to claim 4, characterized in that: After storing the key C in the custom class loader, obtain the dynamic link library connection method and the return result, including: In the custom class loader, set the path and parameters for connecting to the dynamic link library; Use the decryption function in the dynamic link library, and pass the public key A, the version number V, the expiration date D, and the key C; After the decryption function of the dynamic link library is executed, obtain the return result. If the decryption is successful and the verification passes, return the result R. If the decryption fails or the verification fails, return the result F; Return the result to the custom class loader.

6. The method for encrypting a Java class file according to claim 5, characterized in that: According to the public key A, version number V, validity period D, private key B, and key C, the decryption function is used in the dynamic link library to decrypt to obtain the decryption result, including: Define a decryption function in the dynamic link library and obtain the public key A, version number V, validity period D, and key C; Use the decryption function in the dynamic link library to retrieve the corresponding private key B in the key management system according to the version number V and the validity period D; Perform AES encryption on the public key A to obtain the encrypted string S'; The version number V, the encrypted string S' and the expiration date D are combined into the final string S'1, where S'1 = V + S' + D; Use private key B to decrypt key C using the RSA decryption method to obtain the decrypted string S'2.

7. The method for encrypting a Java class file according to claim 6, characterized in that: Get string S'1 and string S'2, compare string S'1 with string S'2, and return the result; If the string S'1 is equal to the string S'2, the verification is successful and the result R is returned; If the string S'1 is not equal to the string S'2, the verification fails and the result F is returned; Pass the returned result to the custom class loader.

8. The method for encrypting a Java class file according to claim 7, characterized in that: According to the decryption result, the custom class loader makes a judgment to obtain the judgment result. If it is R, the class file continues to be loaded. If it is F, an exception is thrown and the loading process is terminated, including: After calling the decryption function of the dynamic link library, the custom class loader receives the returned result; The custom class loader makes a judgment based on the returned result to obtain the judgment result; If the result is R, continue the class loading process, load the corresponding class file according to the returned network path, and load it into the Java virtual machine using the standard Java class loading mechanism; If the result is F, throw an exception and terminate the class loading process.

9. The method for encrypting a Java class file according to claim 8, characterized in that: The encryption module and the dynamic link library work together to perform real-time verification during the Java class file loading process.

10. The method for encrypting a Java class file according to claim 9, characterized in that: Through the version number V and the validity period D, dynamic management and control of the usage period of Java class files can be achieved.