Class loader-based encryption module plug-in method and device and related product
By using the plug-in proxy technology of class loaders, the problem of high update costs for encryption algorithms in blockchain is solved, enabling flexible management of encryption modules and reducing update costs.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- FUZHOU QIYUAN INFORMATION TECHNOLOGY CO LTD
- Filing Date
- 2022-08-15
- Publication Date
- 2026-06-02
AI Technical Summary
In blockchain technology, updates to existing encryption algorithms are usually implemented through static libraries, resulting in high update costs and difficulty in flexible updates and management.
By using class loaders, class loaders that load hosts and plugins are created. By leveraging class injection and container fusion technologies, plug-in proxying of encryption modules is implemented, reducing the cost of updating encryption algorithms.
It enables flexible updates and management of encryption algorithms, reduces update costs, and improves the flexibility and efficiency of the system.
Smart Images

Figure CN115269056B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of blockchain technology, and in particular to a method, apparatus and related products for plugging in cryptographic modules based on a class loader. Background Technology
[0002] A blockchain is a chain of blocks, each containing specific information, linked together in chronological order. This chain is stored on all servers; as long as at least one server in the system is operational, the entire blockchain is secure. These servers are called nodes in the blockchain system, providing storage space and computing power. Modifying information in the blockchain requires the consent of more than half of the nodes and modification of the information across all nodes. Since these nodes are typically controlled by different entities, tampering with information in the blockchain is extremely difficult.
[0003] In the application of blockchain technology, terminal block nodes are involved. Each block node is equivalent to a terminal, and for it to participate in the overall blockchain system, it must be loaded with necessary code and resource packages. Currently, this is often implemented using static libraries. Among these, encryption algorithms are a crucial function for blockchain. When the encryption algorithm is implemented as a static library, updating the encryption algorithm requires updating the entire dynamic library, resulting in high update costs. Summary of the Invention
[0004] To address the aforementioned issues, this application provides a method, apparatus, and related products for plugging in encryption modules based on class loaders.
[0005] The embodiments of this application disclose the following technical solutions:
[0006] A pluggable method for cryptographic modules based on class loaders, comprising:
[0007] By using class injection, a first-class loader for loading the host and a second-class loader for loading the plugin are created.
[0008] The first type of loader loads system classes related to the host and pre-embedded empty containers to form a host application package;
[0009] The host application package is launched to receive the name, source code path, and event class of the plugin within the defined first lifecycle through the empty container and forward them to the second type loader, so that the second type loader loads the component classes related to the encryption module;
[0010] Register the loaded component classes related to the encryption module in the host's registry to create resource instances related to the encryption module;
[0011] Within the defined second lifecycle, the empty container merges the resource instances related to the encryption module and the resource instances related to the host to achieve plug-in proxying of the encryption module by the host.
[0012] Optionally, the step of merging the resource instances related to the encryption module and the resource instances related to the host created within the defined second lifecycle through the empty container to achieve the plug-in proxy of the encryption module by the host includes: assigning different IDs to the resource instances related to the encryption module and the resource instances related to the host, so as to merge the resource instances related to the encryption module and the resource instances related to the host created within the defined second lifecycle through the empty container based on the assigned IDs, thereby achieving the plug-in proxy of the encryption module by the host.
[0013] Optionally, assigning different IDs to resource instances associated with the encryption module and resource instances associated with the host includes:
[0014] Based on predefined packet segments and defined resource types, different IDs are assigned to resource instances related to the encryption module and resource instances related to the host.
[0015] Optionally, the resource types include system resource types and application resource types, and the allocation of different IDs is configured with a resource type identifier field and a resource sub-package range field.
[0016] A class loader-based cryptographic module plug-in device, comprising:
[0017] The first program unit is used to create a first-class loader for loading the host and a second-class loader for loading the plugin through class injection.
[0018] The second program unit is used to load system classes related to the host and pre-embedded empty containers through the first type of loader to form a host application package;
[0019] The third program unit is used to start the host application package to receive the name, source code path, and event class of the plugin through the empty container within a defined first lifecycle and forward them to the second type loader, so that the second type loader loads the component class related to the encryption module.
[0020] The fourth program unit is used to register the loaded component classes related to the encryption module in the host's registry to create resource instances related to the encryption module.
[0021] The fifth program unit is used to merge resource instances related to the encryption module and resource instances related to the host within the defined second lifecycle through the empty container, so as to realize the plug-in proxy of the encryption module by the host.
[0022] Optionally, the fifth program unit is further configured to: assign different IDs to resource instances related to the encryption module and resource instances related to the host, so as to merge the created resource instances related to the encryption module and resource instances related to the host within a defined second lifecycle through the empty container based on the assigned IDs, so as to realize the plug-in proxy of the encryption module by the host.
[0023] Optionally, the fifth program unit is further configured to:
[0024] Based on predefined packet segments and defined resource types, different IDs are assigned to resource instances related to the encryption module and resource instances related to the host.
[0025] Optionally, the resource types include system resource types and application resource types, and the allocation of different IDs is configured with a resource type identifier field and a resource sub-package range field.
[0026] An electronic device includes a memory and a processor, wherein the memory stores an executable program, and the processor, when running the executable program, performs the following steps:
[0027] By using class injection, a first-class loader for loading the host and a second-class loader for loading the plugin are created.
[0028] The first type of loader loads system classes related to the host and pre-embedded empty containers to form a host application package;
[0029] The host application package is launched to receive the name, source code path, and event class of the plugin within the defined first lifecycle through the empty container and forward them to the second type loader, so that the second type loader loads the component classes related to the encryption module;
[0030] Register the loaded component classes related to the encryption module in the host's registry to create resource instances related to the encryption module;
[0031] Within the defined second lifecycle, the empty container merges the resource instances related to the encryption module and the resource instances related to the host to achieve plug-in proxying of the encryption module by the host.
[0032] A computer storage medium, characterized in that the computer storage medium stores a computer-executable program, which, when executed, performs the following steps:
[0033] By using class injection, a first-class loader for loading the host and a second-class loader for loading the plugin are created.
[0034] The first type of loader loads system classes related to the host and pre-embedded empty containers to form a host application package;
[0035] The host application package is launched to receive the name, source code path, and event class of the plugin within the defined first lifecycle through the empty container and forward them to the second type loader, so that the second type loader loads the component classes related to the encryption module;
[0036] Register the loaded component classes related to the encryption module in the host's registry to create resource instances related to the encryption module;
[0037] Within the defined second lifecycle, the empty container merges the resource instances related to the encryption module and the resource instances related to the host to achieve plug-in proxying of the encryption module by the host.
[0038] In the technical solution of this application embodiment, a first-class loader for loading the host and a second-class loader for loading plugins are created through class injection. The first-class loader loads system classes related to the host and a pre-embedded empty container to form a host application package. The host application package is started so that the empty container receives the name, source code path, and event class of the plugin within a defined first lifecycle and forwards them to the second-class loader, so that the second-class loader loads component classes related to the encryption module. The loaded component classes related to the encryption module are registered in the host's registry to create resource instances related to the encryption module. The empty container merges the created resource instances related to the encryption module with resource instances related to the host within a defined second lifecycle to realize the host's plug-in proxy for the encryption module. Thus, when there are updates to the encryption algorithm, it can be implemented based on the plugin, thereby reducing the cost of updating the encryption algorithm. Attached Figure Description
[0039] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0040] Figure 1 This is a flowchart illustrating a method for plugging in encryption modules based on a class loader, according to an embodiment of this application.
[0041] Figure 2 This is a schematic diagram of the structure of a class loader-based encryption module plug-in device according to an embodiment of this application;
[0042] Figure 3 This is a schematic diagram of the structure of the electronic device in the embodiments of this application;
[0043] Figure 4 This is a schematic diagram of the hardware structure of the electronic device in the embodiments of this application. Detailed Implementation
[0044] Implementing any technical solution of the embodiments of this application does not necessarily require achieving all of the above advantages at the same time.
[0045] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0046] In the technical solution of this application embodiment, a first-class loader for loading the host and a second-class loader for loading plugins are created through class injection. The first-class loader loads system classes related to the host and a pre-embedded empty container to form a host application package. The host application package is started so that the empty container receives the name, source code path, and event class of the plugin within a defined first lifecycle and forwards them to the second-class loader, so that the second-class loader loads component classes related to the encryption module. The loaded component classes related to the encryption module are registered in the host's registry to create resource instances related to the encryption module. The empty container merges the created resource instances related to the encryption module with resource instances related to the host within a defined second lifecycle to realize the host's plug-in proxy for the encryption module. Thus, when there are updates to the encryption algorithm, it can be implemented based on the plugin, thereby reducing the cost of updating the encryption algorithm.
[0047] Figure 1 This is a schematic diagram of a method for plugging in encryption modules based on a class loader, as described in an embodiment of this application; Figure 1 As shown, it includes:
[0048] S101. By using class injection, create a first-class loader for loading the host and a second-class loader for loading the plugin;
[0049] S102. Load the system classes related to the host and the pre-embedded empty containers through the first type of loader to form the host application package;
[0050] S103. Start the host application package to receive the name, source code path, and event class of the plugin through the empty container within the defined first lifecycle and forward them to the second type loader, so that the second type loader loads the component class related to the encryption module.
[0051] S104. Register the loaded component classes related to the encryption module in the host's registry to create resource instances related to the encryption module;
[0052] S105. Within the defined second lifecycle, the empty container merges the resource instances related to the encryption module and the resource instances related to the host to achieve the plug-in proxy of the encryption module by the host.
[0053] By defining the first lifecycle and the second lifecycle, the reuse of the empty container is realized, which reduces the difficulty of algorithm design and facilitates flexible use according to application scenarios.
[0054] Optionally, the step of merging the resource instances related to the encryption module and the resource instances related to the host created within the defined second lifecycle through the empty container to realize the pluggable proxy of the encryption module by the host includes:
[0055] S115. Assign different IDs to resource instances related to the encryption module and resource instances related to the host;
[0056] S125. Based on the assigned ID, the resource instances related to the encryption module and the resource instances related to the host are merged within the defined second lifecycle through the empty container to realize the plug-in proxy of the encryption module by the host.
[0057] Optionally, assigning different IDs to resource instances related to the encryption module and resource instances related to the host includes: assigning different IDs to resource instances related to the encryption module and resource instances related to the host based on predefined packet segments and defined resource types, thereby preventing ID conflicts between resource instances related to the encryption module and resource instances related to the host that would prevent the merging of resource instances from being achieved.
[0058] Optionally, the resource types include system resource types and application resource types. The allocation of different IDs is set with a resource type identifier field and a resource sub-packet range field, thereby ensuring that resource instances related to the encryption module and resource instances related to the host have different IDs, while also intuitively indicating the resource type and resource sub-packet range.
[0059] Optionally, starting the host application package to receive the plugin's name, source code path, and event class through the empty container within a defined first lifecycle and forward them to the second type of loader includes: starting the host application package to intercept events based on callback hooks through the empty container within a defined first lifecycle to receive the plugin's name, source code path, and event class and forward them to the second type of loader, thereby realizing dynamic callbacks and ensuring execution efficiency.
[0060] Optionally, the step of loading system classes related to the host and pre-embedded empty containers to form a host application package through the first type of loader further includes: establishing a mapping relationship between the empty container and the second type of loader to execute the startup of the host application package, so as to receive the name, source code path, and event class of the plugin through the empty container within a defined first lifecycle and forward them to the second type of loader, thereby realizing the forwarding of the name, source code path, and event class of the plugin based on the empty container.
[0061] Figure 2 This is a schematic diagram of a pluggable encryption module based on a class loader, according to an embodiment of this application; Figure 2 As shown, it includes:
[0062] The first program unit 201 is used to create a first-class loader for loading the host and a second-class loader for loading the plugin through class injection.
[0063] The second program unit 202 is used to load system classes related to the host and pre-embedded empty containers through the first type of loader to form a host application package;
[0064] The third program unit 203 is used to start the host application package to receive the name, source code path, and event class of the plugin through the empty container within a defined first lifecycle and forward them to the second type loader, so that the second type loader loads the component class related to the encryption module.
[0065] The fourth program unit 204 is used to register the loaded component classes related to the encryption module in the registry of the host to create resource instances related to the encryption module.
[0066] The fifth program unit 205 is used to merge the resource instances related to the encryption module and the resource instances related to the host created within the defined second lifecycle through the empty container, so as to realize the plug-in proxy of the encryption module by the host.
[0067] Optionally, the fifth program unit is further configured to: assign different IDs to resource instances related to the encryption module and resource instances related to the host, so as to merge the created resource instances related to the encryption module and resource instances related to the host within a defined second lifecycle through the empty container based on the assigned IDs, so as to realize the plug-in proxy of the encryption module by the host.
[0068] Optionally, the fifth program unit is further configured to:
[0069] Based on predefined packet segments and defined resource types, different IDs are assigned to resource instances related to the encryption module and resource instances related to the host.
[0070] Optionally, the resource types include system resource types and application resource types, and the allocation of different IDs is configured with a resource type identifier field and a resource sub-package range field.
[0071] Optionally, the third program unit is further configured to: launch the host application package to intercept events based on callback hooks within a defined first lifecycle through the empty container to receive the plugin's name, source code path, and event class, and forward them to the second type loader.
[0072] Optionally, the apparatus further includes: a sixth program unit, configured to, after loading the host-related system classes and the pre-embedded empty container to form a host application package through the first type of loader, establish a mapping relationship between the empty container and the second type of loader, so as to execute the startup of the host application package, so as to receive the name of the plugin, the source code path, and the event class through the empty container within a defined first lifecycle and forward them to the second type of loader.
[0073] Figure 3 This is a schematic diagram of the structure of an electronic device according to an embodiment of this application; as shown Figure 3 As shown, it includes a memory 301 and a processor 302. The memory stores an executable program, and when the processor runs the executable program, it performs the following steps:
[0074] By using class injection, a first-class loader for loading the host and a second-class loader for loading the plugin are created.
[0075] The first type of loader loads system classes related to the host and pre-embedded empty containers to form a host application package;
[0076] The host application package is launched to receive the name, source code path, and event class of the plugin within the defined first lifecycle through the empty container and forward them to the second type loader, so that the second type loader loads the component classes related to the encryption module;
[0077] Register the loaded component classes related to the encryption module in the host's registry to create resource instances related to the encryption module;
[0078] Within the defined second lifecycle, the empty container merges the resource instances related to the encryption module and the resource instances related to the host to achieve plug-in proxying of the encryption module by the host.
[0079] This application embodiment also provides a computer storage medium storing a computer-executable program. When the computer-executable program is executed, it performs the following steps:
[0080] By using class injection, a first-class loader for loading the host and a second-class loader for loading the plugin are created.
[0081] The first type of loader loads system classes related to the host and pre-embedded empty containers to form a host application package;
[0082] The host application package is launched to receive the name, source code path, and event class of the plugin within the defined first lifecycle through the empty container and forward them to the second type loader, so that the second type loader loads the component classes related to the encryption module;
[0083] Register the loaded component classes related to the encryption module in the host's registry to create resource instances related to the encryption module;
[0084] Within the defined second lifecycle, the empty container merges the resource instances related to the encryption module and the resource instances related to the host to achieve plug-in proxying of the encryption module by the host.
[0085] Figure 4 This is a schematic diagram of the hardware structure of the electronic device in the embodiments of this application; as shown Figure 4 As shown, the hardware structure of this electronic device may include: Electronic device 400 includes a computing unit 401, which can perform various appropriate actions and processes according to a computer program stored in read-only memory (ROM) 402 or a computer program loaded from storage unit 406 into random access memory (RAM) 403. The RAM 403 may also store various programs and data required for the operation of device 400. The computing unit 401, ROM 402, and RAM 403 are interconnected via bus 404. Input / output (I / O) interface 405 is also connected to bus 404.
[0086] Multiple components in electronic device 400 are connected to I / O interface 405, including: input unit 406, output unit 407, storage unit 408, and communication unit 409. Input unit 406 can be any type of device capable of inputting information to electronic device 400. Input unit 406 can receive input digital or character information and generate key signal inputs related to user settings and / or function control of electronic device. Output unit 407 can be any type of device capable of presenting information and may include, but is not limited to, a display, speaker, video / audio output terminal, vibrator, and / or printer. Storage unit 404 may include, but is not limited to, disks and optical discs. Communication unit 409 allows electronic device 400 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks, and may include, but is not limited to, modems, network cards, infrared communication devices, wireless communication transceivers, and / or chipsets, such as Bluetooth™ devices, WiFi devices, WiMax devices, cellular communication devices, and / or the like.
[0087] The computing unit 401 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 401 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 401 performs the various methods and processes described above. For example, in some embodiments, the above steps can be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 40*. In some embodiments, part or all of the computer program can be loaded and / or installed on the electronic device 400 via ROM 402 and / or communication unit 409. In some embodiments, the computing unit 401 can be configured to perform the above steps by any other suitable means (e.g., by means of firmware).
[0088] The electronic devices in this application embodiments exist in various forms, including but not limited to:
[0089] (1) Mobile communication devices: These devices are characterized by their mobile communication capabilities and primarily aim to provide voice and data communication. These terminals include: smartphones (e.g., iPhones), multimedia phones, feature phones, and low-end phones, etc.
[0090] (2) Ultra-mobile personal computer devices: These devices fall under the category of personal computers, possessing computing and processing capabilities, and generally also have mobile internet access features. These terminals include PDAs, MIDs, and UMPCs, such as the iPad.
[0091] (3) Portable entertainment devices: These devices can display and play multimedia content. This category includes audio and video players (such as iPods), handheld game consoles, e-book readers, as well as smart toys and portable car navigation devices.
[0092] (4) Server: A device that provides computing services. The components of a server include a processor 410, hard disk, memory, system bus, etc. Servers are similar to general computer architectures, but because they need to provide highly reliable services, they have higher requirements in terms of processing power, stability, reliability, security, scalability, and manageability.
[0093] (5) Other electronic devices with data interaction functions.
[0094] It should be noted that the various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, for the device and system embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the description of the method embodiments. The device and system embodiments described above are merely illustrative. The modules described as separate components may or may not be physically separate, and the components indicated as modules may or may not be physical modules, that is, they may be located in one place or distributed across multiple network modules. Some or all of the modules can be selected to achieve the purpose of the solution in this embodiment according to actual needs. Those skilled in the art can understand and implement this without creative effort.
[0095] The above description is merely one specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A method for plugging in encryption modules based on class loaders, characterized in that, include: By using class injection, a first-class loader for loading the host and a second-class loader for loading the plugin are created. The first type of loader loads system classes related to the host and pre-embedded empty containers to form a host application package; The host application package is launched to receive the name, source code path, and event class of the plugin within the defined first lifecycle through the empty container and forward them to the second type loader, so that the second type loader loads the component classes related to the encryption module; Register the loaded component classes related to the encryption module in the host's registry to create resource instances related to the encryption module; Within the defined second lifecycle, the empty container merges the resource instances related to the encryption module and the resource instances related to the host to achieve plug-in proxying of the encryption module by the host.
2. The method according to claim 1, characterized in that, The step of merging resource instances related to the encryption module and resource instances related to the host created within the defined second lifecycle through the empty container to achieve plug-in proxying of the encryption module by the host includes: assigning different IDs to resource instances related to the encryption module and resource instances related to the host, so as to merge resource instances related to the encryption module and resource instances related to the host created within the defined second lifecycle through the empty container based on the assigned IDs, thereby achieving plug-in proxying of the encryption module by the host.
3. The method according to claim 1, characterized in that, Assigning different IDs to resource instances associated with the encryption module and resource instances associated with the host, including: Based on predefined packet segments and defined resource types, different IDs are assigned to resource instances related to the encryption module and resource instances related to the host.
4. The method according to claim 1, characterized in that, Resource types include system resource types and application resource types, and different IDs are assigned with resource type identifier fields and resource sub-package range fields.
5. A pluggable device for encryption modules based on a class loader, characterized in that, include: The first program unit is used to create a first-class loader for loading the host and a second-class loader for loading the plugin through class injection. The second program unit is used to load system classes related to the host and pre-embedded empty containers through the first type of loader to form a host application package; The third program unit is used to start the host application package to receive the name, source code path, and event class of the plugin through the empty container within a defined first lifecycle and forward them to the second type loader, so that the second type loader loads the component class related to the encryption module. The fourth program unit is used to register the loaded component classes related to the encryption module in the host's registry to create resource instances related to the encryption module. The fifth program unit is used to merge resource instances related to the encryption module and resource instances related to the host within the defined second lifecycle through the empty container, so as to realize the plug-in proxy of the encryption module by the host.
6. The apparatus according to claim 5, characterized in that, The fifth program unit is further configured to: assign different IDs to resource instances related to the encryption module and resource instances related to the host, so as to merge the resource instances related to the encryption module and the resource instances related to the host created by the empty container within a defined second lifecycle based on the assigned IDs, so as to realize the plug-in proxy of the encryption module by the host.
7. The apparatus according to claim 6, characterized in that, The fifth program unit is further used for: Based on predefined packet segments and defined resource types, different IDs are assigned to resource instances related to the encryption module and resource instances related to the host.
8. The apparatus according to claim 7, characterized in that, The resource types include system resource types and application resource types, and the different IDs assigned are configured with a resource type identifier field and a resource sub-package range field.
9. An electronic device, characterized in that, The system includes a memory and a processor, wherein the memory stores an executable program, and the processor executes the following steps when running the executable program: By using class injection, a first-class loader for loading the host and a second-class loader for loading the plugin are created. The first type of loader loads system classes related to the host and pre-embedded empty containers to form a host application package; The host application package is launched to receive the name, source code path, and event class of the plugin within the defined first lifecycle through the empty container and forward them to the second type loader, so that the second type loader loads the component classes related to the encryption module; Register the loaded component classes related to the encryption module in the host's registry to create resource instances related to the encryption module; Within the defined second lifecycle, the empty container merges the resource instances related to the encryption module and the resource instances related to the host to achieve plug-in proxying of the encryption module by the host.
10. A computer storage medium, characterized in that, The computer storage medium stores a computer-executable program, and when the computer-executable program is executed, the following steps are performed: By using class injection, a first-class loader for loading the host and a second-class loader for loading the plugin are created. The first type of loader loads system classes related to the host and pre-embedded empty containers to form a host application package; The host application package is launched to receive the name, source code path, and event class of the plugin within the defined first lifecycle through the empty container and forward them to the second type loader, so that the second type loader loads the component classes related to the encryption module; Register the loaded component classes related to the encryption module in the host's registry to create resource instances related to the encryption module; Within the defined second lifecycle, the empty container merges the resource instances related to the encryption module and the resource instances related to the host to achieve plug-in proxying of the encryption module by the host.