Industrial model encryption and deployment methods, devices, electronic equipment and storage media
By encrypting industrial inference model files and configuration files, and embedding the decryption key into the inference source code to generate a binary module, the security issues of industrial AI inference services when deployed locally are solved, achieving multiple protections for models and code and improving data security.
Patent Information
- Application Number
- CN202611154897.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-31
- Publication Date
- 2026-11-17
AI Technical Summary
In existing technologies, when industrial AI inference services are deployed locally, the models and code lack security protection mechanisms, making them vulnerable to illegal copying, tampering, and theft.
The model files and configuration files of the trained industrial inference model are encrypted, and the decryption key is embedded in the inference source code to generate a binary module. During deployment, the binary module automatically completes the decryption, and the decrypted model is directly loaded into memory.
It improves the security of models and code, increases the difficulty of reverse engineering models, reduces the risk of being copied, tampered with, and stolen, and enhances the data security of industrial AI inference services.
Smart Images

Figure CN123116226A_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of industrial model reasoning service technology, and particularly relates to an industrial model encryption and deployment method, device, electronic device and storage medium. Background Technology
[0002] With the rapid development of industrial intelligent technologies, industrial AI (Artificial Intelligence) inference services have been widely applied in various industrial production scenarios. Due to the requirements of industrial production data privacy, information security, and compliance management, industrial AI defect detection inference services need to move away from the cloud-based public deployment model. Instead, the accompanying model files and program code need to be delivered completely to the customer's local equipment for deployment and operation in the customer's local environment. This reduces the risk of production data leakage and ensures the privacy and security of industrial data.
[0003] In related technologies, local deployment solutions use plaintext storage and execution to host AI models and business code. However, models and code in plaintext lack security protection mechanisms and are easily copied, tampered with, and stolen. Summary of the Invention
[0004] This application aims to address at least one of the technical problems existing in the prior art. To this end, this application proposes an industrial model encryption and deployment method, apparatus, electronic device, and storage medium to ensure data security for locally deployed industrial AI inference services.
[0005] Firstly, this application provides an industrial model encryption and deployment method, including: The model file of the trained industrial inference model is first encrypted to obtain an encrypted model file, and the configuration file of the industrial inference model is second encrypted to obtain an encrypted configuration file. The decryption key is embedded in the inference source code of the industrial inference model, and the inference source code with the embedded decryption key is compiled to obtain a binary module; the decryption key includes a first decryption key for decrypting the encrypted model file and a second decryption key for decrypting the configuration file; The encrypted model file, the encrypted configuration file, and the binary module are packaged into a deployment package. After the deployment package is deployed to the target runtime environment, when the inference service is started in the target runtime environment, the binary module is loaded, and the encrypted model file and the encrypted configuration file are decrypted into memory using the decryption key in the binary module. The model inference task is then performed based on the decrypted model file and configuration file in memory.
[0006] According to the industrial model encryption and deployment method of this application, multiple protections of the model and code are achieved by encrypting the model file and configuration file, and compiling and protecting the inference source code. The decryption key is embedded in the inference source code, so that the decryption key exists in the binary module in the form of unreadable machine code, which increases the difficulty of reverse extraction of the key. During deployment, decryption is automatically completed by loading the binary module without manual operation by the user. The decrypted model is directly loaded into memory, which greatly increases the difficulty of reverse acquisition of the model and reduces the risk of copying, tampering and theft caused by plaintext storage of the model on the local disk, thereby improving the data security of local deployment of industrial AI inference services.
[0007] According to one embodiment of this application, the first encryption of the model file of the trained industrial inference model to obtain an encrypted model file includes: Read the byte stream of the model file; The byte stream is symmetrically encrypted using at least two levels of key transformation to generate the encryption model file.
[0008] In this embodiment, the model file byte stream is symmetrically encrypted using at least two levels of key transformation to generate an encrypted model file. This means that even if an attacker obtains the encrypted model file, they will need to crack multiple levels of keys layer by layer to restore the plaintext of the model. This increases the complexity and time cost of brute-force attacks and improves the anti-theft capability and security of the model data.
[0009] According to one embodiment of this application, the step of performing symmetric encryption on the byte stream using at least two levels of key transformation to generate the encryption model file includes: Perform a shift operation on the byte stream based on the first encryption subkey; The encrypted model file is obtained by performing an XOR operation on the byte stream after the shift operation based on the second encryption subkey.
[0010] In this embodiment, by performing a shift operation on the byte stream of the model file based on the first encryption subkey, the byte order characteristics of the model file are destroyed, increasing the difficulty for attackers to directly identify the model structure information. Then, by performing an XOR operation on the shifted byte stream based on the second encryption subkey, the true content of the original bytes is further concealed, making the encrypted model file similar to random data in statistical characteristics. This improves the resistance to cryptanalysis attacks such as frequency analysis, and further enhances the anti-cracking and anti-theft capabilities of the model file.
[0011] According to one embodiment of this application, the second encryption of the configuration file of the industrial inference model to obtain an encrypted configuration file includes: Obtain the normalization parameters from the configuration file; the normalization parameters include the mean and / or standard deviation; The normalized parameters are encrypted using character offset encryption to obtain the encrypted configuration file.
[0012] In this embodiment, by obtaining sensitive parameters such as the mean and standard deviation from the configuration file and performing character offset encryption, the original values of sensitive parameters such as the mean and standard deviation can be masked while maintaining the readability of other non-sensitive information in the configuration file. This not only improves the data security of the configuration file, but also makes the configuration file recognized as a valid configuration file in the deployment environment without being easily detected by the encryption process, thus enhancing the concealment of the encryption behavior.
[0013] According to one embodiment of this application, compiling the inference source code embedded with the decryption key to obtain a binary module includes: The inference source code embedded with the decryption key is converted into a binary module that matches the target operating system; the binary module is a library file that matches the target operating system.
[0014] In this embodiment, by converting the inference source code with embedded decryption keys into a binary module that matches the target operating system, the inference source code and the embedded decryption keys, which exist in plaintext, are transformed into an unreadable binary format. Furthermore, since the binary module is a library file that matches the target operating system, the compiled binary module can be loaded and run by applications under the target operating system. This reduces the additional parsing and loading process of the inference source code during operation, which not only improves the startup speed and running efficiency of the inference service, but also increases the difficulty for attackers to reverse analyze and tamper with it.
[0015] According to one embodiment of this application, the deployment package is a model archive file in the TorchServe specification.
[0016] In this embodiment, by configuring the deployment package as a model archive file that conforms to the TorchServe specification, the encrypted industrial inference model can be directly adapted to TorchServe. There is no need to develop an independent inference service infrastructure for the encrypted deployment scheme, which significantly reduces the deployment complexity and operation and maintenance cost of the encrypted model in the customer's local environment.
[0017] Secondly, this application provides an industrial model encryption and deployment device, comprising: The encryption module is used to perform a first encryption on the model file of the trained industrial inference model to obtain an encrypted model file, and to perform a second encryption on the configuration file of the industrial inference model to obtain an encrypted configuration file. A compilation module is used to embed the decryption key into the inference source code of the industrial inference model, and to compile the inference source code with the decryption key embedded to obtain a binary module; the decryption key includes a first decryption key for decrypting the encrypted model file and a second decryption key for decrypting the configuration file; The deployment module is used to package the encrypted model file, the encrypted configuration file, and the binary module into a deployment file package. After the deployment file package is deployed to the target runtime environment, when the inference service is started in the target runtime environment, the binary module is loaded, and the encrypted model file and the encrypted configuration file are decrypted into memory using the decryption key in the binary module. The model inference task is then executed based on the decrypted model file and the configuration file in memory.
[0018] According to the industrial model encryption and deployment device of this application, multiple protections of the model and code are achieved by encrypting the model file and configuration file, and compiling and protecting the inference source code. The decryption key is embedded in the inference source code, so that the decryption key exists in the binary module in the form of unreadable machine code, which increases the difficulty of reverse extraction of the key. During deployment, decryption is automatically completed by loading the binary module without manual operation by the user. The decrypted model is directly loaded into memory, which greatly increases the difficulty of reverse acquisition of the model and reduces the risk of copying, tampering and theft caused by plaintext storage of the model on the local disk, thereby improving the data security of local deployment of industrial AI inference services.
[0019] Thirdly, this application provides an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the industrial model encryption and deployment method described in the first aspect above.
[0020] Fourthly, this application provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the industrial model encryption and deployment method described in the first aspect above.
[0021] Fifthly, this application provides a chip including a processor and a communication interface, the communication interface being coupled to the processor, the processor being used to run programs or instructions to implement the industrial model encryption and deployment method as described in the first aspect above.
[0022] Sixthly, this application provides a computer program product, including a computer program that, when executed by a processor, implements the industrial model encryption and deployment method as described in the first aspect above.
[0023] The above-described one or more technical solutions in the embodiments of this application have at least one of the following technical effects: According to the industrial model encryption and deployment method of this application, multiple protections of the model and code are achieved by encrypting the model file and configuration file, and compiling and protecting the inference source code. The decryption key is embedded in the inference source code, so that the decryption key exists in the binary module in the form of unreadable machine code, which increases the difficulty of reverse extraction of the key. During deployment, decryption is automatically completed by loading the binary module without manual operation by the user. The decrypted model is directly loaded into memory, which greatly increases the difficulty of reverse acquisition of the model and reduces the risk of copying, tampering and theft caused by plaintext storage of the model on the local disk, thereby improving the data security of local deployment of industrial AI inference services.
[0024] In some embodiments, the model file byte stream is symmetrically encrypted using at least two levels of key transformation to generate an encrypted model file. This means that even if an attacker obtains the encrypted model file, they will need to crack multiple levels of keys layer by layer to restore the plaintext of the model. This increases the complexity and time cost of brute-force attacks and improves the anti-theft capability and security of the model data.
[0025] In some embodiments, by performing a shift operation on the byte stream of the model file based on the first encryption subkey, the byte order characteristics of the model file are disrupted, increasing the difficulty for attackers to directly identify the model structure information. Then, by performing an XOR operation on the shifted byte stream based on the second encryption subkey, the true content of the original bytes is further concealed, making the encrypted model file similar to random data in statistical characteristics. This improves the resistance to cryptanalysis attacks such as frequency analysis, and further enhances the anti-cracking and anti-theft capabilities of the model file.
[0026] In some embodiments, by obtaining sensitive parameters such as the mean and standard deviation from the configuration file and performing character offset encryption, the original values of sensitive parameters such as the mean and standard deviation can be masked while maintaining the readability of other non-sensitive information in the configuration file. This not only improves the data security of the configuration file, but also makes the configuration file a valid configuration file in the deployment environment, making it difficult to detect the encryption process and enhancing the concealment of the encryption behavior.
[0027] In some embodiments, by converting the inference source code with embedded decryption keys into a binary module that matches the target operating system, the inference source code and the embedded decryption keys, which exist in plaintext, are transformed into an unreadable binary format. Furthermore, since the binary module is a library file that matches the target operating system, the compiled binary module can be loaded and run by applications under the target operating system. This reduces the additional parsing and loading process of the inference source code during operation, which not only improves the startup speed and running efficiency of the inference service, but also increases the difficulty for attackers to reverse engineer and tamper with it.
[0028] In some embodiments, by configuring the deployment package as a model archive file conforming to the TorchServe specification, the encrypted industrial inference model can be directly adapted to TorchServe, without the need to develop an additional independent inference service infrastructure for the encrypted deployment scheme, which significantly reduces the deployment complexity and operation and maintenance costs of the encrypted model in the customer's local environment.
[0029] Additional aspects and advantages of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description
[0030] The above and / or additional aspects and advantages of this application will become apparent and readily understood in conjunction with the following description of the embodiments in conjunction with the accompanying drawings, wherein: Figure 1 This is a flowchart illustrating the industrial model encryption and deployment method provided in the embodiments of this application; Figure 2 This is a schematic diagram of the structure of the industrial model encryption and deployment device provided in the embodiments of this application; Figure 3 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0031] The technical solutions of the embodiments of this application will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application are within the scope of protection of this application.
[0032] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.
[0033] The following description, in conjunction with the accompanying drawings, details the industrial model encryption and deployment method, apparatus, electronic device, and storage medium provided in this application through specific embodiments and application scenarios.
[0034] The industrial model encryption and deployment method can be applied to the terminal, specifically executed by the hardware or software in the terminal.
[0035] The terminal includes, but is not limited to, portable communication devices such as mobile phones or tablets with touch-sensitive surfaces (e.g., touchscreen displays and / or touchpads). It should also be understood that, in some embodiments, the terminal may not be a portable communication device, but rather a desktop computer with touch-sensitive surfaces (e.g., touchscreen displays and / or touchpads).
[0036] The following embodiments describe a terminal including a display and a touch-sensitive surface. However, it should be understood that the terminal may include one or more other physical user interface devices such as a physical keyboard, mouse, and joystick.
[0037] The industrial model encryption and deployment method provided in this application embodiment can be executed by an electronic device or a functional module or entity in an electronic device that can implement the industrial model encryption and deployment method. The electronic devices mentioned in this application embodiment include, but are not limited to, servers, industrial control computers, edge computing gateways, embedded processors, programmable logic controllers, Internet of Things gateways, personal computers, workstations, cloud computing nodes, distributed computing systems, mobile terminals, etc. The industrial model encryption and deployment method provided in this application embodiment is described below using an electronic device as the execution subject.
[0038] like Figure 1 As shown, the industrial model encryption and deployment method includes steps 110, 120 and 130.
[0039] Step 110: Perform a first encryption on the model file of the trained industrial inference model to obtain an encrypted model file, and perform a second encryption on the configuration file of the industrial inference model to obtain an encrypted configuration file.
[0040] In this embodiment, the industrial inference model refers to a deep learning model trained with a large amount of industrial defect sample data and possessing specific defect detection capabilities. The sample data used to train the industrial inference model varies depending on the product. The product can be any industrial product requiring defect detection, such as lithium battery separators, optical films, metal foils, semiconductor wafers, printed circuit boards, components, etc. This embodiment does not limit the specific type of product.
[0041] Taking lithium battery separators as an example, defects in lithium battery separators typically include scratches, black spots, and holes. A large number of images of lithium battery separators with defects can be used as sample data to train an industrial inference model. After training, the industrial inference model can identify whether there are defects in the lithium battery separator in the image and the type of defect based on the input image of the lithium battery separator.
[0042] In this embodiment, the model file of the industrial inference model stores core data such as the network structure, weight parameters of each network layer, and bias terms of the industrial inference model, and is the basic file for implementing model inference services. The model file can be in formats such as .pt, .onnx, or .pb.
[0043] The configuration file for the industrial inference model is a set of parameter files designed to match the model's operation. It can include hyperparameter settings required for model inference, input / output format definitions, hardware adaptation parameters, preprocessing and post-processing rules, and other information to standardize the model's operational logic and adaptation rules. The configuration file can be in formats such as .json, .yaml, or .xml.
[0044] The weight parameters stored inside the model file are obtained with significant resources invested in data acquisition, model training, and tuning; their leakage would lead to the loss of technological advantages. While the configuration file does not directly contain model weights, it includes information related to the model architecture, such as input dimensions, layer configuration, and activation function types. Attackers can use the configuration file to infer model structural features, thereby aiding subsequent model theft attacks. Therefore, both the model file and the configuration file need to be encrypted separately.
[0045] In this embodiment of the application, the model file is first encrypted using a symmetric encryption algorithm, such as AES (Advanced Encryption Standard) or SM4, to encrypt the model file and obtain an encrypted model file. This makes the model file stored in ciphertext form and cannot be directly read or loaded for use.
[0046] A second encryption is applied to the configuration file, which can use the same or a different encryption algorithm as the first encryption, resulting in an encrypted configuration file. It's important to note that using different encryption strategies for the first and second encryption ensures that the model file and configuration file are protected by independent key systems. Even if one encryption layer is breached, attackers will still be unable to obtain the complete information needed for model operation, thus forming a layered security architecture.
[0047] Step 120: Embed the decryption key into the inference source code of the industrial inference model, and compile the inference source code with the embedded decryption key to obtain a binary module; the decryption key includes a first decryption key for decrypting the encrypted model file and a second decryption key for decrypting the configuration file; In this embodiment, the inference source code is the program code that carries the inference business logic of the industrial inference model, including model calling logic, data preprocessing logic, inference result post-processing logic, device adaptation and interaction logic, etc. The inference source code can be code written in a high-level programming language (such as C++, Python, Rust, etc.).
[0048] The decryption key is the key information corresponding to the encryption key, including a first decryption key used to decrypt the encrypted model file and a second decryption key used to decrypt the encrypted configuration file. In symmetric encryption algorithms, the decryption key is the same as the encryption key.
[0049] In related technologies, common local deployment solutions typically store the decryption key separately from the encryption model in the form of a configuration file, environment variable, or independent key file. However, this approach allows attackers to obtain the decryption key by monitoring file access, reading environment variables, or intercepting key transmission channels, thereby decrypting the model file.
[0050] Based on this, the embodiments of this application embed the decryption key into the compilation unit of the inference source code, and compile the inference source code after embedding the decryption key to generate a binary module. Since the compiled binary module exists in the form of machine code, the original high-level language code structure (including variable names, function names, string constants, etc.) undergoes multiple stages of transformation during the compilation process, such as lexical analysis, syntax analysis, code optimization, and target code generation. The decryption key is encoded as constant data in the machine instruction sequence or embedded in complex computational logic, which increases the difficulty for attackers to reverse-engineer the key through static analysis or dynamic debugging.
[0051] In one example, the first and second decryption keys can be embedded in a specified location in the inference source code as constant definitions or encrypted strings. The inference source code with the embedded keys is then compiled. The compiler converts the source code into a sequence of machine instructions corresponding to the target platform architecture, generating a binary executable module, such as a .so dynamic library, a .dll file, or a binary executable file without a suffix.
[0052] It should be noted that embedding the decryption key into the inference source code and protecting it through compilation not only achieves the covert storage of the key, but also makes the decryption function and the inference function deeply coupled at the code level. Even if an attacker obtains the binary module, it will be difficult to separate the independent decryption logic without destroying the inference function.
[0053] Step 130: Package the encrypted model file, encrypted configuration file, and binary module into a deployment package; after the deployment package is deployed to the target runtime environment, when the inference service is started in the target runtime environment, the binary module is loaded, and the encrypted model file and encrypted configuration file are decrypted into memory using the decryption key in the binary module. The model inference task is then executed based on the decrypted model file and configuration file in memory.
[0054] In this embodiment of the application, the deployment package refers to a package obtained by packaging the encrypted model file, the encrypted configuration file, and the compiled binary module.
[0055] In some embodiments, the deployment package can adopt a layered packaging structure. The outer layer is a container layer containing metadata description files, and the inner layer is divided into a model asset layer (containing encrypted model files and encrypted configuration files) and a program runtime layer (containing binary modules) according to their functions. The metadata description files record information such as the hash digest, encryption algorithm identifier, target runtime environment, and version number of each file to facilitate automatic verification and environment adaptation during deployment.
[0056] In some embodiments, the deployment package is a Model Archive (MAR) file in the TorchServe specification.
[0057] Among them, the MAR file is the standard model deployment package format defined by the TorchServe framework. It follows the predefined directory structure and metadata specifications of TorchServe and usually has the .mar extension.
[0058] In this embodiment, the encrypted model file, encrypted configuration file, and binary module can be packaged according to TorchServe's MAR packaging specification to obtain a MAR file.
[0059] In this embodiment, by configuring the deployment package as a model archive file that conforms to the TorchServe specification, the encrypted industrial inference model can be directly adapted to TorchServe. There is no need to develop an independent inference service infrastructure for the encrypted deployment scheme, which significantly reduces the deployment complexity and operation and maintenance cost of the encrypted model in the customer's local environment.
[0060] In some embodiments, the deployment file package can be encrypted a third time, for example, based on the client's public key, so that only the client holding the corresponding private key can decompress and deploy the deployment file, further improving the security of the distribution chain.
[0061] The target operating environment refers to the computing devices used by the customer on-premises to deploy and run inference services. The hardware of the target operating environment can be an industrial edge computing gateway, an embedded industrial control computer, a local server, or a dedicated inference acceleration device, etc. The software of the target operating environment can include the operating system, necessary drivers, etc.
[0062] After the deployment package in the target runtime environment is decompressed and configured, the inference task can be started by the user or an automated script, triggering the inference engine initialization and entering the inference-ready state. For example, the user can execute the startup script through the command line interface, or start the inference task by clicking the "Start Service" button in the graphical management platform; in automated production scenarios, the production line control system can also trigger the startup of the inference service through interface calls or message queues.
[0063] In related technologies, some local deployment solutions encrypt the model files, but write the decrypted model files to the local disk and then load them when the inference service starts. Since the decrypted model files reside in plaintext on the local storage medium, attackers can easily obtain the complete plaintext model through file system monitoring, disk image analysis, or data recovery tools.
[0064] Based on this, the decrypted model in this embodiment is directly loaded into memory, without storing the plaintext model file locally. Specifically, when the target runtime environment starts the inference service, it can load the binary module, call the memory allocation interface to request a memory buffer, call the internally embedded decryption key, perform decryption operations on the encrypted model file and encrypted configuration file, and write the decrypted plaintext data into the memory buffer. During inference, the model loading interface reads the model structure and weight parameters from the memory buffer and sends them to the computing unit for inference calculation. The computing unit can be a CPU (Central Processing Unit), GPU (Graphics Processing Unit), NPU (Neural Processing Unit), etc.
[0065] During decryption and loading, plaintext model data is bound to memory addresses, not disk files. When the inference service process terminates, the operating system automatically reclaims the memory pages occupied by that process, and the plaintext data is overwritten or released, leaving no recoverable trace on the storage medium. Therefore, plaintext model data exists only in memory space and is not stored in plaintext form on the local disk.
[0066] In some embodiments, to align with mainstream model-service deployment frameworks, TorchServe's proxy Handler can be used to integrate the loading and decryption logic of binary modules into the framework's standard service architecture. Taking TorchServe as an example, the proxy Handler inherits from the framework's base Handler class, implementing dynamic loading of binary modules. Specifically, it first locates the binary module file in the deployment package, then uses an interface to call the operating system's dynamic link library loading mechanism to map the binary module into the memory space of the TorchServe service process. The proxy Handler then calls the binary module's initialization interface, triggering the internally embedded decryption key to perform in-memory decryption of the encrypted model file and encrypted configuration file, completing the instantiation and construction of the model in memory. The proxy Handler is transparent to TorchServe's upper-layer architecture; the framework's standard functions such as model management, request routing, batch processing, and log monitoring can run normally without modification. Users also do not need to adjust their original model registration, service startup, and interface call processes, improving the efficiency of model deployment and inference.
[0067] In some embodiments, to shorten the exposure time of plaintext data in memory, for large model files, the model file can be decrypted in segments according to the network layer according to the needs of the current inference calculation. When the weight of a certain network layer is needed for the current inference calculation, the data of that network layer is decrypted into memory. After the calculation is completed, the memory area is cleared or overwritten.
[0068] According to the industrial model encryption and deployment method of this application, multiple protections of the model and code are achieved by encrypting the model file and configuration file, and compiling and protecting the inference source code. The decryption key is embedded in the inference source code, so that the decryption key exists in the binary module in the form of unreadable machine code, which increases the difficulty of reverse extraction of the key. During deployment, decryption is automatically completed by loading the binary module without manual operation by the user. The decrypted model is directly loaded into memory, which greatly increases the difficulty of reverse acquisition of the model and reduces the risk of copying, tampering and theft caused by plaintext storage of the model on the local disk, thereby improving the data security of local deployment of industrial AI inference services.
[0069] In some embodiments, the model file of the trained industrial inference model is first encrypted to obtain an encrypted model file, including: Read the byte stream of the model file; The byte stream is symmetrically encrypted using at least two levels of key transformation to generate an encryption model file.
[0070] In this embodiment, the content of the model file is stored in the form of a byte stream. When encryption is performed, the model file can be read globally, parsed, and the byte stream of the model file can be extracted.
[0071] Symmetric encryption is an encryption mechanism that uses the same key for both encryption and decryption. At least two levels of keys means that at least two keys are used to encrypt the byte stream. For example, the byte stream is first encrypted using the first subkey, and then the encrypted byte stream is encrypted again using the second subkey.
[0072] In this embodiment, the model file byte stream is symmetrically encrypted using at least two levels of key transformation to generate an encrypted model file. This means that even if an attacker obtains the encrypted model file, they will need to crack multiple levels of keys layer by layer to restore the plaintext of the model. This increases the complexity and time cost of brute-force attacks and improves the anti-theft capability and security of the model data.
[0073] In some embodiments, at least two levels of key transformation are used to perform symmetric encryption on the byte stream to generate an encryption model file, including: Perform a shift operation on the byte stream based on the first encryption subkey; An XOR operation is performed on the byte stream after the shift operation based on the second encryption subkey to obtain the encryption model file.
[0074] In this embodiment, since symmetric encryption is used, the first encryption subkey and the second encryption subkey are also the decryption keys for the encrypted model file.
[0075] The first encryption subkey is used to perform a shift and obfuscation operation on the byte stream. The shift operation refers to rearranging the positions of bytes in the byte stream according to the rules specified by the first encryption subkey, thereby disrupting the original sequential structure of the byte stream and making the format characteristics and data distribution of the model file unrecognizable.
[0076] Specifically, a shift parameter sequence, such as the number of bits for cyclic left shift, block size, and permutation table, can be generated based on the first encryption subkey. This sequence divides the byte stream into multiple data blocks, and the positions of bytes or bits within each data block are transformed according to the shift parameters. For example, a pseudo-random number generator can be initialized using the first encryption subkey as a seed, generating a permutation index sequence of the same length as the byte stream. The byte stream can then be rearranged according to this index sequence.
[0077] The second encryption subkey is used to perform an XOR operation on the shifted and obfuscated byte stream. The XOR operation refers to performing a bitwise XOR operation, byte-by-byte, between the byte stream and the key stream generated by the second encryption subkey.
[0078] Specifically, the second encryption subkey can be used as a seed to initialize the key stream generator, generating a key stream with a length equal to the shifted byte stream. The shifted byte stream and the key stream are then XORed byte by byte to output the ciphertext byte stream, which is the encryption model file.
[0079] In this embodiment, by performing a shift operation on the byte stream of the model file based on the first encryption subkey, the byte order characteristics of the model file are destroyed, increasing the difficulty for attackers to directly identify the model structure information. Then, by performing an XOR operation on the shifted byte stream based on the second encryption subkey, the true content of the original bytes is further concealed, making the encrypted model file similar to random data in statistical characteristics. This improves the resistance to cryptanalysis attacks such as frequency analysis, and further enhances the anti-cracking and anti-theft capabilities of the model file.
[0080] In some embodiments, the configuration file of the industrial inference model is subjected to a second encryption to obtain an encrypted configuration file, including: Retrieve the normalization parameters from the configuration file; the normalization parameters include the mean and / or standard deviation. The normalized parameters are encrypted using character offset encryption to obtain the encrypted configuration file.
[0081] In this embodiment, the configuration file is a collection of auxiliary information required for the operation of the industrial inference model. It is stored in a structured text format and may include model input preprocessing rules, output postprocessing parameters, inference hyperparameters, hardware adaptation configurations, etc. The normalization parameters are numerical values related to input data preprocessing in the configuration file, including the mean and standard deviation (std), which are used to map the input data (such as image pixel values) from the original numerical range to the standardized numerical range used during model training before inference.
[0082] For example, in a product defect detection scenario, the configuration file may include fields such as "mean": [0.485, 0.456, 0.406] and "std": [0.229, 0.224, 0.225], which correspond to the normalization parameters of the RGB three channels, respectively. The normalization parameters determine how the input data is transformed. If an attacker obtains the plaintext configuration file, they can easily combine it with model architecture information to deduce the distribution characteristics of the training data. Therefore, the normalization parameters in the configuration file need to be encrypted and protected.
[0083] Character offset encryption is a lightweight substitution encryption method that generates an unreadable ciphertext string by shifting the position of each character in the character representation of normalized parameters according to a fixed or variable-length offset, thereby achieving covert protection of sensitive numerical information.
[0084] Specifically, the obtained normalized parameters (such as the floating-point value 0.485) can be converted into a string. The characters in this string (such as numbers, decimal points, and minus signs) are then shifted according to a preset offset rule. This offset rule can be determined based on the encryption key; for example, the ASCII value of each character can be added to the offset and then moduloed to map to the new character. The encrypted normalized parameters replace the plaintext values in the original configuration file as a ciphertext string. Other non-sensitive configuration items can remain unchanged or be encrypted using the same strategy, ultimately generating an encrypted configuration file.
[0085] In this embodiment, by obtaining sensitive parameters such as the mean and standard deviation from the configuration file and performing character offset encryption, the original values of sensitive parameters such as the mean and standard deviation can be masked while maintaining the readability of other non-sensitive information in the configuration file. This not only improves the data security of the configuration file, but also makes the configuration file recognized as a valid configuration file in the deployment environment without being easily detected by the encryption process, thus enhancing the concealment of the encryption behavior.
[0086] In some embodiments, the inference source code embedding the decryption key is compiled to obtain a binary module, including: The inference source code containing the embedded decryption key is converted into a binary module that matches the target operating system; the binary module is a library file that matches the target operating system.
[0087] In this embodiment, the library file consists of a sequence of machine instructions, making it difficult to read or modify directly. Operating system applications can dynamically load and call functional modules from the library file, thereby enabling the inference logic to be invoked. Library files can use different file formats under different operating systems. For example, under Linux, library files can be .so (Shared Object) files; under Windows, library files can be .dll (Dynamic Link Library) files or .pyd (Python Dynamic Module) files.
[0088] Inference source code can be written in high-level programming languages such as C++, Python, and Rust, and it usually exists in plaintext, making it easy to read and tamper with. Therefore, converting the inference source code with embedded decryption keys into a binary module compatible with the target operating system allows it to be executed by the operating system's applications, reducing the risk of directly exposing the inference source code.
[0089] Taking the inference source code as Python code written in the Python programming language as an example, after conversion, the binary module exists as a .so file under the Linux operating system; and as a .pyd file under the Windows operating system.
[0090] In this embodiment, the inference source code embedding the decryption key can be converted into a binary module using compilation tools such as Cython or Nuitka.
[0091] In this embodiment, by converting the inference source code with embedded decryption keys into a binary module that matches the target operating system, the inference source code and the embedded decryption keys, which exist in plaintext, are transformed into an unreadable binary format. Furthermore, since the binary module is a library file that matches the target operating system, the compiled binary module can be loaded and run by applications under the target operating system. This reduces the additional parsing and loading process of the inference source code during operation, which not only improves the startup speed and running efficiency of the inference service, but also increases the difficulty for attackers to reverse analyze and tamper with it.
[0092] The industrial model encryption and deployment method provided in this application can be executed by an industrial model encryption and deployment device. This application uses an industrial model encryption and deployment device executing the industrial model encryption and deployment method as an example to illustrate the industrial model encryption and deployment device provided in this application.
[0093] This application also provides an industrial model encryption and deployment device.
[0094] like Figure 2 As shown, the industrial model encryption and deployment device includes: The encryption module 210 is used to perform a first encryption on the model file of the trained industrial inference model to obtain an encrypted model file, and to perform a second encryption on the configuration file of the industrial inference model to obtain an encrypted configuration file. The compilation module 220 is used to embed the decryption key into the inference source code of the industrial inference model and compile the inference source code with the embedded decryption key to obtain a binary module; the decryption key includes a first decryption key for decrypting the encrypted model file and a second decryption key for decrypting the configuration file; Deployment module 230 is used to package the encrypted model file, encrypted configuration file, and binary module into a deployment file package. After the deployment file package is deployed to the target runtime environment, when the inference service is started in the target runtime environment, the binary module is loaded, and the encrypted model file and encrypted configuration file are decrypted into memory using the decryption key in the binary module. The model inference task is then executed based on the decrypted model file and configuration file in memory.
[0095] According to the industrial model encryption and deployment device of this application, multiple protections of the model and code are achieved by encrypting the model file and configuration file, and compiling and protecting the inference source code. The decryption key is embedded in the inference source code, so that the decryption key exists in the binary module in the form of unreadable machine code, which increases the difficulty of reverse extraction of the key. During deployment, decryption is automatically completed by loading the binary module without manual operation by the user. The decrypted model is directly loaded into memory, which greatly increases the difficulty of reverse acquisition of the model and reduces the risk of copying, tampering and theft caused by plaintext storage of the model on the local disk, thereby improving the data security of local deployment of industrial AI inference services.
[0096] In some embodiments, the encryption module 210 is further configured to: Read the byte stream of the model file; The byte stream is symmetrically encrypted using at least two levels of key transformation to generate an encryption model file.
[0097] In some embodiments, the encryption module 210 is further configured to: Perform a shift operation on the byte stream based on the first encryption subkey; An XOR operation is performed on the byte stream after the shift operation based on the second encryption subkey to obtain the encryption model file.
[0098] In some embodiments, the encryption module 210 is further configured to: Retrieve the normalization parameters from the configuration file; the normalization parameters include the mean and / or standard deviation. The normalized parameters are encrypted using character offset encryption to obtain the encrypted configuration file.
[0099] In some embodiments, the compilation module 220 is further configured to: The inference source code containing the embedded decryption key is converted into a binary module that matches the target operating system; the binary module is a library file that matches the target operating system.
[0100] The industrial model encryption and deployment device in this application embodiment can be an electronic device or a component within an electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal or other devices besides a terminal. For example, the electronic device can be a mobile phone, tablet computer, laptop computer, PDA, mobile internet device (MID), augmented reality (AR) / virtual reality (VR) device, robot, wearable device, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc. It can also be a server, network attached storage (NAS), personal computer (PC), television (TV), ATM, or self-service machine, etc. This application embodiment does not specifically limit the device.
[0101] In some embodiments, such as Figure 3 As shown, this application embodiment also provides an electronic device 300, including a processor 301, a memory 302, and a computer program stored in the memory 302 and executable on the processor 301. When the program is executed by the processor 301, it implements the various processes of the above-described industrial model encryption and deployment method embodiment and can achieve the same technical effect. To avoid repetition, it will not be described again here.
[0102] It should be noted that the electronic devices in the embodiments of this application include the aforementioned mobile electronic devices and non-mobile electronic devices.
[0103] This application also provides a non-transitory computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it implements the various processes of the above-described industrial model encryption and deployment method embodiments and achieves the same technical effect. To avoid repetition, it will not be described again here.
[0104] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.
[0105] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described industrial model encryption and deployment method.
[0106] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.
[0107] This application also provides a chip, which includes a processor and a communication interface. The communication interface and the processor are coupled. The processor is used to run programs or instructions to implement the various processes of the above-described embodiment of the encryption and deployment method based on the industrial model, and can achieve the same technical effect. To avoid repetition, it will not be described again here.
[0108] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.
[0109] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.
[0110] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a computer software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods of the various embodiments of this application.
[0111] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.
[0112] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "illustrative embodiment," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0113] Although embodiments of this application have been shown and described, those skilled in the art will understand that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of this application, the scope of which is defined by the claims and their equivalents.
Claims
1. An industrial model encryption and deployment method, characterized in that, include: The model file of the trained industrial inference model is first encrypted to obtain an encrypted model file, and the configuration file of the industrial inference model is second encrypted to obtain an encrypted configuration file. The decryption key is embedded in the inference source code of the industrial inference model, and the inference source code with the decryption key embedded is compiled to obtain a binary module; The decryption key includes a first decryption key for decrypting the encrypted model file and a second decryption key for decrypting the configuration file; The encrypted model file, the encrypted configuration file, and the binary module are packaged into a deployment package. After the deployment package is deployed to the target runtime environment, when the inference service is started in the target runtime environment, the binary module is loaded, and the encrypted model file and the encrypted configuration file are decrypted into memory using the decryption key in the binary module. The model inference task is then performed based on the decrypted model file and configuration file in memory.
2. The method according to claim 1, characterized in that, The first encryption of the model file of the trained industrial inference model yields an encrypted model file, including: Read the byte stream of the model file; The byte stream is symmetrically encrypted using at least two levels of key transformation to generate the encryption model file.
3. The method according to claim 2, characterized in that, The step of performing symmetric encryption on the byte stream using at least two levels of key transformation to generate the encryption model file includes: Perform a shift operation on the byte stream based on the first encryption subkey; The encrypted model file is obtained by performing an XOR operation on the byte stream after the shift operation based on the second encryption subkey.
4. The method according to claim 1, characterized in that, The configuration file of the industrial inference model is second-encrypted to obtain an encrypted configuration file, including: Obtain the normalization parameters from the configuration file; the normalization parameters include the mean and / or standard deviation; The normalized parameters are encrypted using character offset encryption to obtain the encrypted configuration file.
5. The method according to claim 1, characterized in that, The process of compiling the inference source code embedded with the decryption key to obtain a binary module includes: The inference source code embedded with the decryption key is converted into a binary module that matches the target operating system; the binary module is a library file that matches the target operating system.
6. The method according to claim 1, characterized in that, The deployment package is the model archive file in the TorchServe specification.
7. An industrial model encryption and deployment device, characterized in that, include: The encryption module is used to perform a first encryption on the model file of the trained industrial inference model to obtain an encrypted model file, and to perform a second encryption on the configuration file of the industrial inference model to obtain an encrypted configuration file. A compilation module is used to embed the decryption key into the inference source code of the industrial inference model, and to compile the inference source code with the decryption key embedded to obtain a binary module; The decryption key includes a first decryption key for decrypting the encrypted model file and a second decryption key for decrypting the configuration file; The deployment module is used to package the encrypted model file, the encrypted configuration file, and the binary module into a deployment file package. After the deployment file package is deployed to the target runtime environment, when the inference service is started in the target runtime environment, the binary module is loaded, and the encrypted model file and the encrypted configuration file are decrypted into memory using the decryption key in the binary module. The model inference task is then executed based on the decrypted model file and the configuration file in memory.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the method as described in any one of claims 1-6.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1-6.
10. A computer program product, characterized in that, Includes a computer program that, when executed by a processor, implements the method as described in any one of claims 1-6.
