File encryption and decryption method, device and system
By obfuscating and encrypting the model files of the machine learning core model and splitting the storage, the problem of easy leakage of model files during access and transmission is solved, and efficient and secure file transfer is achieved.
Patent Information
- Application Number
- CN202311825837.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-27
- Publication Date
- 2025-06-27
AI Technical Summary
The model files of the core model of machine learning are easily stolen or leaked during the access and transmission process, resulting in significant losses for the company.
A file encryption and file decryption method is adopted. By converting the file to be encrypted into a binary stream, obfuscation and encryption are performed, and finally the obfuscation binary encrypted stream is stored to ensure the secure transmission of files.
It effectively improves the storage and transmission security of model files, increases the difficulty of stealing and cracking, avoids the loss and theft of data transmission keys, and ensures high performance and availability of file transfer.
Smart Images

Figure CN120223339A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data security technology, and in particular to a file encryption and file decryption method, device and system. Background Art
[0002] The algorithms and parameters of the core machine learning models are stored in the form of model files (.py, .pkl, etc.). Therefore, the access and transmission security of model files are crucial to the security of the core machine learning models. Once the model files containing algorithms and parameters are stolen or leaked during the storage and transmission process, it will cause immeasurable losses to the companies that own the core machine learning models. Summary of the invention
[0003] In view of the above problems, the present invention is proposed to provide a file encryption and file decryption method, device and system that overcome the above problems or at least partially solve the above problems.
[0004] An embodiment of the present invention provides a file encryption method, comprising:
[0005] Convert the file to be encrypted into a binary stream;
[0006] Obfuscating the binary stream according to the positive sequence positioning index number, the reverse sequence positioning index number and the interception length number in the preset first data group to obtain a binary obfuscated stream;
[0007] Using an encryption key obtained by a preset encryption algorithm, the binary obfuscated stream is encrypted to obtain a binary obfuscated encrypted stream;
[0008] According to the preset positive sequence positioning index number, reverse sequence positioning index number and interception length number in the second data group, the binary obfuscated encrypted stream is obfuscated to obtain an obfuscated binary obfuscated encrypted stream;
[0009] The obfuscated binary encrypted stream is intercepted with bytes of a predetermined length and stored in a first memory, and the obfuscated binary encrypted stream after intercepting the bytes of the predetermined length is stored in a second memory.
[0010] In some optional embodiments, the obfuscating process of the binary stream according to the positive sequence positioning index number, the reverse sequence positioning index number and the truncation length number in the preset first data group includes:
[0011] Starting from the starting position of the binary stream, locate the position of the positive sequence positioning index number, take the position of the positive sequence positioning index number as the starting position, and intercept the bytes corresponding to the interception length number in positive sequence to obtain a binary positive sequence interception stream;
[0012] Starting from the end position of the binary stream, locate the position of the reverse positioning index number. Taking the position of the reverse positioning index number as the starting position, reverse-intercept the bytes corresponding to the intercepted length number to obtain a binary reverse-intercepted stream;
[0013] Perform a swap replacement on the binary forward-intercepted stream and the binary reverse-intercepted stream to obtain the binary obfuscated stream.
[0014] In some alternative embodiments, the first memory is a database and the second memory is a server disk.
[0015] In some alternative embodiments, according to the file encryption method described above, it further includes:
[0016] In response to a homomorphic encryption algorithm public key request received from a model invoker, return a random number ciphertext and a homomorphic encryption algorithm public key to the model invoker;
[0017] Receive a blinded ciphertext sent by the model invoker, where the blinded ciphertext is obtained by blinding the generated request identifier based on the random number ciphertext and the homomorphic encryption algorithm public key;
[0018] Use a pre-generated homomorphic encryption algorithm private key to decrypt the blinded ciphertext to obtain a blinded plaintext. Based on the blinded plaintext, obtain a device parsing identifier, a parsing timestamp, and a first parsing random number. Generate a first data transmission key based on the device parsing identifier, the parsing timestamp, the first parsing random number, and a preset key rule;
[0019] Generate a verification ciphertext based on the first data transmission key, the device parsing identifier, and the parsing timestamp, and return the blinded plaintext and the verification ciphertext to the model invoker;
[0020] If a message indicating successful verification of the verification ciphertext sent by the model invoker is received, use the first data transmission key as the data transmission key to perform the file transmission with the model invoker.
[0021] In some alternative embodiments, the step of, in response to a homomorphic encryption algorithm public key request received from a model invoker, returning a random number ciphertext and a homomorphic encryption algorithm public key to the model invoker includes:
[0022] Generate a first random number according to the homomorphic encryption algorithm public key request;
[0023] Use the homomorphic encryption algorithm public key to encrypt the first random number to obtain the random number ciphertext;
[0024] Send the random number ciphertext and the homomorphic encryption algorithm public key to the model invoker.
[0025] In some alternative embodiments, decrypting the blinded ciphertext by using the pre-generated private key of the homomorphic encryption algorithm to obtain the blinded plaintext, and obtaining a device parsing identifier, a parsing timestamp, and a first parsing random number based on the blinded plaintext, includes:
[0026] Using the private key of the homomorphic encryption algorithm to decrypt the blinded ciphertext to obtain the blinded plaintext;
[0027] Performing an inverse multiplication operation on the blinded plaintext to obtain a request parsing identifier and a first parsing random number;
[0028] Performing reverse parsing on the request parsing identifier according to the splicing rule of the request identifier to obtain a device parsing identifier and a parsing timestamp;
[0029] Determining that the parsing timestamp is within the valid period.
[0030] In some alternative embodiments, generating a verification ciphertext according to the first data transmission key, the device parsing identifier, and the parsing timestamp includes:
[0031] Splicing the device parsing identifier and the parsing timestamp, and performing a hashing operation on the splicing result to obtain a parsing hash result;
[0032] Extracting the first four bits of the parsing hash result;
[0033] Using the first data transmission key to encrypt the extracted first four bits of the parsing hash result to obtain the verification ciphertext.
[0034] In some alternative embodiments, performing the file transmission with the model invoker by using the first data transmission key as the data transmission key includes:
[0035] In response to a data acquisition request from the model invoker, acquiring a predetermined-length confused binary encrypted stream, an encryption key, a first data group, and a second data group stored in a first memory, encrypting them by using the data transmission key, and transmitting them to the model invoker; and acquiring the confused binary encrypted stream after intercepting a predetermined number of bytes stored in a second memory, encrypting it by using the data transmission key, and transmitting it to the model invoker.
[0036] An embodiment of the present invention further provides a file decryption method, including:
[0037] Acquiring the predetermined-length confused binary encrypted stream stored in the first memory and the confused binary encrypted stream after intercepting a predetermined number of bytes stored in the second memory, and splicing them to obtain a confused binary encrypted stream;
[0038] Demix the obfuscated binary encrypted stream according to the forward positioning index number, reverse positioning index number, and truncation length number in the pre-set second data group to obtain a binary encrypted stream;
[0039] Decrypt the binary encrypted stream with the decryption key obtained by using the pre-set encryption algorithm to obtain a binary obfuscated stream;
[0040] Demix the binary obfuscated stream according to the forward positioning index number, reverse positioning index number, and truncation length number in the pre-set first data group to obtain a binary stream;
[0041] Convert the binary stream into a file.
[0042] In some alternative embodiments, the demixing of the binary obfuscated stream according to the forward positioning index number, reverse positioning index number, and truncation length number in the pre-set first data group to obtain a binary stream includes:
[0043] Starting from the starting position of the binary obfuscated stream, locate the position of the forward positioning index number. Taking the position of the forward positioning index number as the starting position, forwardly intercept the bytes corresponding to the truncation length number to obtain a binary reverse-intercepted stream;
[0044] Starting from the end position of the binary obfuscated stream, locate the position of the reverse positioning index number. Taking the position of the reverse positioning index number as the starting position, reversely intercept the bytes corresponding to the truncation length number to obtain a binary forward-intercepted stream;
[0045] Perform a swapping restoration on the binary forward-intercepted stream and the binary reverse-intercepted stream to obtain the binary stream.
[0046] In some alternative embodiments, the file decryption method further includes:
[0047] Send a request for the public key of the homomorphic encryption algorithm to the model training party;
[0048] Receive the ciphertext of the random number and the public key of the homomorphic encryption algorithm returned by the model training party in response to the request for the public key of the homomorphic encryption algorithm;
[0049] Generate a request identifier, blind the request identifier based on the ciphertext of the random number and the public key of the homomorphic encryption algorithm, and send it to the model training party;
[0050] Receive the blinded plaintext and verification ciphertext returned by the model training party; the blinded plaintext is obtained by the model training party decrypting the blinded ciphertext using a pre-generated private key of the homomorphic encryption algorithm; the verification ciphertext is generated by the model training party based on the first data transmission key, device parsing identifier, and parsing timestamp; the first data transmission key is generated based on the blinded plaintext, obtaining the device parsing identifier, parsing timestamp, and first parsing random number, and based on the device parsing identifier, parsing timestamp, first parsing random number, and a preset key rule.
[0051] Deblind the blinded plaintext, generate a second data transmission key based on the deblinding result and the key rule, generate a verification ciphertext according to the second data transmission key, and verify the verification ciphertext based on the verification ciphertext. If the verification is successful, use the second data transmission key as the data transmission key to perform data transmission with the model training party.
[0052] In some alternative embodiments, the generation of the request identifier includes:
[0053] Obtain the device identifier and the current timestamp;
[0054] Perform a hash operation on the device identifier and the current timestamp to obtain a hash result;
[0055] Generate a second random number and a third random number;
[0056] Concatenate the device identifier, the second random number, the current timestamp, the third random number, and the first four digits of the hash result to obtain the request identifier.
[0057] In some alternative embodiments, the blinding of the request identifier based on the random number ciphertext and the public key of the homomorphic encryption algorithm to obtain a blinded ciphertext includes:
[0058] Use the public key of the homomorphic encryption algorithm to perform homomorphic encryption on the request identifier to obtain an identifier ciphertext;
[0059] Perform a multiplication operation on the random number ciphertext and the identifier ciphertext to obtain the blinded ciphertext.
[0060] In some alternative embodiments, the generation of the verification ciphertext based on the deblinding result and the key rule, and the verification of the verification ciphertext based on the verification ciphertext include:
[0061] Use the inverse multiplication operation to perform an operation on the blinded plaintext to obtain a request deblinding identifier and a deblinding random number;
[0062] Based on the de - blinding identifier of the request, obtain the device de - blinding identifier and the de - blinding timestamp, and splice the first five digits of the device de - blinding identifier, the de - blinding random number, and the first five digits of the de - blinding timestamp to obtain the second data transmission key;
[0063] Perform a hash operation on the device de - blinding identifier and the de - blinding timestamp to obtain a de - blinding hash result, and use the second data transmission key to encrypt the first four digits of the de - blinding hash result to obtain a verification ciphertext;
[0064] If it is determined that the verification ciphertext is consistent with the verification ciphertext, the verification passes.
[0065] In some alternative embodiments, using the second data transmission key as the data transmission key to perform data transmission with the model training party includes:
[0066] Send a data acquisition request to the model training party;
[0067] Receive the encrypted data sent by the model training party in response to the data acquisition request;
[0068] Use the data transmission key to decrypt the received encrypted data to obtain a confused binary encrypted stream of a predetermined length, an encryption key, a first data group, a second data group, and the confused binary encrypted stream after intercepting a predetermined number of bytes.
[0069] An embodiment of the present invention also provides a file encryption device, including:
[0070] A stream conversion module for converting a file to be encrypted into a binary stream;
[0071] A first confusion module for confusing the binary stream according to the forward positioning index number, reverse positioning index number, and intercepting length number in the pre - set first data group to obtain a binary confused stream;
[0072] An encryption module for encrypting the binary confused stream using the encryption key obtained by a pre - set encryption algorithm to obtain a binary confused encrypted stream;
[0073] A second confusion module for confusing the binary confused encrypted stream according to the forward positioning index number, reverse positioning index number, and intercepting length number in the pre - set second data group to obtain a confused binary confused encrypted stream;
[0074] A separation and storage module for intercepting a predetermined number of bytes of the confused binary confused encrypted stream and saving it to a first memory, and saving the confused binary confused encrypted stream after intercepting a predetermined number of bytes to a second memory.
[0075] In some alternative embodiments, the file encryption device further includes:
[0076] A request response module, configured to respond to a public key request for a homomorphic encryption algorithm received from a model caller, and return a ciphertext of a random number and a public key of the homomorphic encryption algorithm to the model caller;
[0077] A ciphertext receiving module, configured to receive a blinded ciphertext sent by a model caller, where the blinded ciphertext is obtained by blinding a generated request identifier based on the ciphertext of the random number and the public key of the homomorphic encryption algorithm;
[0078] A first key generation module, configured to use a pre-generated private key of the homomorphic encryption algorithm to decrypt the blinded ciphertext to obtain a blinded plaintext, and based on the blinded plaintext, obtain a device parsing identifier, a parsing timestamp, and a first parsing random number, and generate a first data transmission key based on the device parsing identifier, the parsing timestamp, the first parsing random number, and a preset key rule;
[0079] A ciphertext generation module, configured to generate a verification ciphertext based on the first data transmission key, the device parsing identifier, and the parsing timestamp, and return the blinded plaintext and the verification ciphertext to the model caller;
[0080] A first transmission module, configured to, if receiving a message indicating that the verification of the verification ciphertext sent by the model caller is successful, perform the file transmission with the model caller using the first data transmission key as the data transmission key.
[0081] An embodiment of the present invention further provides a file decryption device, including:
[0082] A splicing module, configured to obtain a predetermined length of a confused binary encrypted stream stored in a first memory and the confused binary encrypted stream after intercepting a predetermined number of bytes stored in a second memory, and splice them to obtain a confused binary encrypted stream;
[0083] A first de-confusing module, configured to de-confuse the confused binary encrypted stream according to the forward positioning index number, the reverse positioning index number, and the intercepted length number in a pre-set second data group to obtain a binary encrypted stream;
[0084] A decryption module, configured to decrypt the binary encrypted stream using a decryption key obtained by a pre-set encryption algorithm to obtain a binary confused stream;
[0085] A second de-confusing module, configured to de-confuse the binary confused stream according to the forward positioning index number, the reverse positioning index number, and the intercepted length number in a pre-set first data group to obtain a binary stream;
[0086] A file conversion module for converting a binary stream into a file.
[0087] In some alternative embodiments, the file decryption device further includes:
[0088] A request sending module for sending a request for the public key of the homomorphic encryption algorithm to the model training party;
[0089] A first receiving module for receiving the ciphertext of the random number and the public key of the homomorphic encryption algorithm returned by the model training party in response to the request for the public key of the homomorphic encryption algorithm;
[0090] A blinding module for generating a request identifier, blinding the request identifier based on the ciphertext of the random number and the public key of the homomorphic encryption algorithm, and sending the blinded ciphertext to the model training party;
[0091] A second receiving module for receiving the blinded plaintext and the verification ciphertext returned by the model training party; the blinded plaintext is obtained by the model training party decrypting the blinded ciphertext using a pre-generated private key of the homomorphic encryption algorithm; the verification ciphertext is generated by the model training party based on the first data transmission key, the device parsing identifier, and the parsing timestamp; the first data transmission key is generated based on the blinded plaintext, obtaining the device parsing identifier, the parsing timestamp, and the first parsing random number, and based on the device parsing identifier, the parsing timestamp, the first parsing random number, and a preset key rule;
[0092] A second key generation module for deblinding the blinded plaintext, generating a second data transmission key based on the deblinding result and the key rule, generating a verification ciphertext according to the second data transmission key, verifying the verification ciphertext based on the verification ciphertext, and if the verification is successful, notifying the second transmission module;
[0093] A second transmission module for using the second data transmission key as the data transmission key to perform data transmission with the model training party.
[0094] An embodiment of the present invention further provides a file transmission system, including a model training device and a model calling device;
[0095] The above-mentioned file encryption device is provided in the model training device for encrypting the data stream of the file to be encrypted;
[0096] The above-mentioned file decryption device is provided in the model calling device for decrypting the encrypted data stream to obtain the decrypted file.
[0097] An embodiment of the present invention also provides a computer storage medium, in which computer-executable instructions are stored, and when the computer-executable instructions are executed by a processor, the above-mentioned file encryption method or the above-mentioned file decryption method is implemented.
[0098] An embodiment of the present invention also provides a computer device, which is characterized by including: a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the program, the above-mentioned file encryption method or the above-mentioned file decryption method is implemented.
[0099] The beneficial effects of the above technical solutions provided by the embodiments of the present invention at least include: In addition to encrypting the model file, it is also obfuscated and split. At the same time, multiple methods are used to provide file service processing. During the data transmission process, the method of generating data transmission keys by both the sender and the receiver is adopted, which avoids the loss and theft of data transmission keys. If the relevant processing rules of the data transmission key are not clear, it will be very difficult to crack. In the actual data transmission application process, it can also be used in combination with other security measures such as the authentication of the calling party identity and the https transmission protocol, which greatly enhances the security of each link in the preservation and transmission of the model file, effectively preventing the risk of decrypting the model file through brute force cracking. At the same time, only part of the encrypted file is saved to the database, so there is no obvious impact on performance, ensuring the high performance and availability of the overall process.
[0100] Other features and advantages of the present invention will be described in the following specification, and part of them will become obvious from the specification, or will be understood by implementing the present invention. The objectives and other advantages of the present invention can be achieved and obtained by the structures specifically pointed out in the written specification, claims, and drawings.
[0101] The technical solutions of the present invention will be further described in detail below through the drawings and embodiments. Description of the Drawings
[0102] The drawings are used to provide a further understanding of the present invention, and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention, and do not constitute a limitation to the present invention. In the drawings:
[0103] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or related technologies. Obviously, for those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0104] Figure 1Schematic flowchart of a file encryption method provided in Embodiment 1 of the present invention;
[0105] Figure 2 Schematic diagram of obfuscating a binary stream in a file encryption method provided in Embodiment 1 of the present invention;
[0106] Figure 3 Schematic diagram of obfuscating an obfuscated encrypted binary stream in a file encryption method provided in Embodiment 1 of the present invention;
[0107] Figure 4 Schematic flowchart of a file decryption method provided in Embodiment 2 of the present invention;
[0108] Figure 5 Schematic flowchart of the operation process of the model training party provided in Embodiment 3 of the present invention;
[0109] Figure 6 Schematic flowchart of the operation process of the model invoker provided in Embodiment 3 of the present invention;
[0110] Figure 7 Schematic diagram of encrypting a machine learning model file of a natural gas market simulation platform in a file encryption method provided in Embodiment 3 of the present invention;
[0111] Figure 8 Schematic diagram of the structure of a file encryption device provided in an embodiment of the present invention;
[0112] Figure 9 Schematic diagram of a partial structure of a file encryption device provided in an embodiment of the present invention;
[0113] Figure 10 Schematic diagram of the structure of a file decryption device provided in an embodiment of the present invention;
[0114] Figure 11 Schematic diagram of a partial structure of a file decryption device provided in an embodiment of the present invention;
[0115] Figure 12 Schematic diagram of the structure of a file transmission system provided in an embodiment of the present invention;
[0116] Figure 13 Schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed implementation manners
[0117] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Apparently, the described embodiments are some but not all of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0118] In the related art, for the security management of model files containing algorithms and parameters, etc., the following management measures are generally included:
[0119] 1) No encryption processing is performed on the content of the model file, and only security measures for identity authentication and data transmission (for example, http transmission) are taken. However, with this method, attackers can obtain the model file by exploiting the vulnerabilities of the security measures.
[0120] 2) Symmetric encryption algorithms such as the Data Encryption Standard (DES) are used to encrypt the model file. However, with this method, once the encryption key is lost or the encryption key is brute-forced by an attacker, the content of the model file will be parsed.
[0121] 3) The model file is compressed, and a decompression password is set for the compressed file during the compression process. When receiving the compressed file, it is decompressed using the decompression password. However, with this method, there are also technical problems such as the decompression password being lost or cracked, and a relatively long waiting time is required during compression and decompression.
[0122] To solve the deficiencies existing in the prior art, the present invention proposes a file encryption and file decryption method, device, and system to ensure the security of the access and transmission of model files.
[0123] Embodiment 1
[0124] In this embodiment, a file encryption method based on a machine learning core model is proposed. After encrypting and obfuscating a model file containing algorithms and parameters, etc. through the machine learning core model, it is then saved and transmitted in a separated manner. Among them, the file encryption key for transmission is dynamically generated each time the model file is transmitted, thereby increasing the difficulty coefficient of the model file being stolen and cracked, and ensuring the security of the storage and transmission of the model file.
[0125] See Figure 1 , the embodiments of the present invention provide a file encryption method, and the method may include the following steps:
[0126] S101. Convert the file to be encrypted into a binary stream;
[0127] In this embodiment, as an alternative embodiment, the file includes a model file and a non-model file. The model file can be a file containing algorithms and parameters of a trained core machine learning model, which can be called by technical developers or maintenance personnel to analyze or improve the core machine learning model. The non-model file can be an important file that needs to be stored or transmitted, such as a data file.
[0128] In this embodiment, taking the file as a model file as an example, the model file is converted into a binary stream.
[0129] S102. According to the forward positioning index number, reverse positioning index number, and truncation length number in the pre-set first data group, perform confusion processing on the binary stream to obtain a binary confusion stream;
[0130] In this embodiment, before encryption, confusion processing is performed on the binary stream.
[0131] In this embodiment, as an alternative embodiment, a first data group and a second data group are pre-set. Each data group includes two index numbers for positioning (forward positioning index number, reverse positioning index number) and one length number for truncation (truncation length number). Among them, the forward positioning index number is equal to the reverse positioning index number, and the sum of the forward positioning index number and the reverse positioning index number is less than the length of the binary stream. As another alternative embodiment, the forward positioning index number can also be unequal to the reverse positioning index number.
[0132] In this embodiment, the first data group and the second data group are randomly set respectively. In the set first data group and second data group, both include two index numbers and one length number. As an alternative embodiment, the first data group and the second data group are stored in a database. When confusion processing needs to be performed on the binary stream, the first data group is obtained from the database, and based on the first data group, confusion processing is performed on the binary stream.
[0133] In this embodiment, as an alternative embodiment, according to the forward positioning index number, reverse positioning index number, and truncation length number in the pre-set first data group, performing confusion processing on the binary stream includes:
[0134] A11. Starting from the starting position of the binary stream, locate the position of the forward positioning index number. Taking the position of the forward positioning index number as the starting position, forwardly intercept the bytes corresponding to the truncation length number to obtain a binary forward truncation stream;
[0135] A12. Starting from the end position of the binary stream, locate the position of the reverse positioning index number. Taking the position of the reverse positioning index number as the starting position, reverse-intercept the bytes corresponding to the intercepted length number to obtain a binary reverse-intercepted stream;
[0136] A13. Swap and replace the binary forward-intercepted stream and the binary reverse-intercepted stream to obtain the binary obfuscated stream.
[0137] In this embodiment, denote the forward positioning index number in the first data group as the first index number a1, the reverse positioning index number as the second index number b1, and the intercepted length number as the first length number c1. In this way, according to the first index number a1, the second index number b1, and the first length number c1 in the first data group, perform obfuscation processing on the binary stream S1 before encryption: Find the position of the first index number a1 from the starting position of the binary stream, intercept the bytes with a length of the first length number c1 starting from the position of the first index number a1 to obtain a binary forward-intercepted stream B1, and, starting from the end position of the binary stream, find the position of the second index number b1 in reverse, intercept the bytes with a length of the first length number c1 starting from the position of the second index number b1 to obtain a binary reverse-intercepted stream B2, and swap and replace the binary forward-intercepted stream B1 and the binary reverse-intercepted stream B2 to obtain a binary obfuscated stream S2.
[0138] Figure 2 It is a schematic diagram of obfuscating a binary stream in a file encryption method provided by an embodiment of the present invention. As Figure 2 shown, the leftmost side of the binary stream S1 is the starting position, the rightmost side is the end position, the forward order is the direction from left to right, and the reverse order is the direction from right to left. Find the position of the first index number a1 in forward order from the starting position of the binary stream. Starting from the position of the first index number a1, intercept the bytes (binary stream) with a length of the first length number c1 to the right to obtain a binary forward-intercepted stream B1, and, starting from the end position of the binary stream, find the position of the second index number b1 in reverse to the left. Starting from the position of the second index number b1, intercept the bytes with a length of the first length number c1 to the left to obtain a binary reverse-intercepted stream B2, and swap and replace the binary forward-intercepted stream B1 and the binary reverse-intercepted stream B2 to obtain a binary obfuscated stream S2.
[0139] In this embodiment, by obfuscating the binary stream, the storage security of the binary stream can be improved.
[0140] S103. Use the encryption key obtained by a pre-set encryption algorithm to encrypt the binary obfuscated stream to obtain a binary obfuscated encrypted stream;
[0141] In this embodiment, the encryption algorithms include, but are not limited to, symmetric encryption block cipher algorithms. For example, SM1 encryption algorithm, SM4 encryption algorithm, SM7 encryption algorithm, etc. The binary obfuscated stream obtained after obfuscation is encrypted using the SM4 encryption algorithm to generate an encrypted binary obfuscated encrypted stream.
[0142] In this embodiment, as an alternative embodiment, the encryption key KF is stored in the database and can be updated irregularly. As an alternative embodiment, the encryption key KF is extracted from the database, and the binary obfuscated stream S2 is encrypted based on the encryption key KF using the SM4 encryption algorithm to obtain a binary obfuscated encrypted stream S3.
[0143] S104. According to the forward positioning index number, reverse positioning index number, and truncation length number in the pre-set second data group, perform obfuscation processing on the binary obfuscated encrypted stream to obtain an obfuscated binary obfuscated encrypted stream;
[0144] In this embodiment, the binary obfuscated encrypted stream corresponding to the model file is further obfuscated.
[0145] In this embodiment, denote the forward positioning index number in the second data group as the third index number a2, the reverse positioning index number as the fourth index number b2, and the truncation length number as the second length number c2. Thus, for the second data group A2, it includes the third index number a2, the fourth index number b2, and the second length number c2. As an alternative embodiment, the set second data group is stored in the database, the second data group is obtained from the database, and based on the second data group, obfuscation processing is performed on the binary obfuscated encrypted stream.
[0146] In this embodiment, as an alternative embodiment, according to the forward positioning index number, reverse positioning index number, and truncation length number in the pre-set second data group, performing obfuscation processing on the binary obfuscated encrypted stream includes:
[0147] B11. Starting from the starting position of the binary obfuscated encrypted stream, locate the position of the forward positioning index number, and based on the position of the forward positioning index number, sequentially intercept the bytes corresponding to the truncation length number to obtain a binary forward-intercepted obfuscated encrypted stream;
[0148] B12. Starting from the end position of the binary obfuscated encrypted stream, locate the position of the reverse positioning index number, and based on the position of the reverse positioning index number, reversely intercept the bytes corresponding to the truncation length number to obtain a binary reverse-intercepted obfuscated encrypted stream;
[0149] B13. Perform swap replacement on the binary forward-intercepted obfuscated encrypted stream and the binary reverse-intercepted obfuscated encrypted stream to obtain the obfuscated binary obfuscated encrypted stream.
[0150] In this embodiment, the second data group is obtained from the database, and according to the third index number a2, the fourth index number b2, and the second length number c2 in the second data group, the binary obfuscated encryption stream S3 is obfuscated: Starting from the starting position of the binary obfuscated encryption stream S3 in the forward order, the position of the third index number a2 is found, and the bytes with the length of the second length number c2 are intercepted to obtain the first obfuscated binary obfuscated encryption stream B3. Starting from the end position of the binary obfuscated encryption stream S3 in the reverse order, the position of the fourth index number b2 is found, and the bytes with the length of the second length number c2 are intercepted to obtain the second obfuscated binary obfuscated encryption stream B4. The first obfuscated binary obfuscated encryption stream B3 and the second obfuscated binary obfuscated encryption stream B4 are swapped and replaced to obtain the obfuscated binary obfuscated encryption stream S4.
[0151] Figure 3 It is a schematic diagram of obfuscating the binary obfuscated encryption stream in a file encryption method provided by an embodiment of the present invention. As Figure 3 shown, the leftmost side of the binary obfuscated encryption stream S3 is the starting position, the rightmost side is the end position, the forward order is the direction from left to right, and the reverse order is the direction from right to left. Starting from the starting position of the binary obfuscated encryption stream S3 in the forward order, the position of the third index number a2 is found. Starting from the position of a2, the bytes with the length of c2 are intercepted to the right to obtain the first obfuscated binary obfuscated encryption stream B3. And starting from the end position of the binary obfuscated encryption stream, the position of the fourth index number b2 is found to the left. Starting from the position of b2, the bytes with the length of c2 are intercepted to the left to obtain the second obfuscated binary obfuscated encryption stream B4. The first obfuscated binary obfuscated encryption stream B3 and the second obfuscated binary obfuscated encryption stream B4 are swapped and replaced to obtain the obfuscated binary obfuscated encryption stream S4.
[0152] In this embodiment, by obfuscating the binary obfuscated encryption stream again, the security of the model file corresponding to the binary obfuscated encryption stream can be effectively improved, and the difficulty of cracking the model file can be increased.
[0153] S105. Intercept the bytes with a predetermined length from the obfuscated binary obfuscated encryption stream, and save them in the first memory, and save the obfuscated binary obfuscated encryption stream after intercepting the bytes with the predetermined length in the second memory.
[0154] In this embodiment, the binary encrypted obfuscated stream is intercepted with the binary stream bytes of a predetermined length and saved in the first memory, and the remaining content is converted into a file with a custom suffix name and saved in the second memory. In this way, by storing the model file corresponding to the binary encrypted obfuscated stream separately, the security of storing the model file is ensured.
[0155] In this embodiment, as an alternative embodiment, the first memory is a database, the second memory is a server disk, and the predetermined length can be set according to actual needs. The obfuscated binary obfuscated encryption stream S4 is intercepted by a predetermined number of bytes to obtain a first model file, which is saved in the database, and the remaining content is converted into a file with a custom suffix name and saved in the server disk.
[0156] In this embodiment, by converting the file to be encrypted into a binary stream, and according to the forward positioning index number, reverse positioning index number, and interception length number in the pre-set first data group, the binary stream is obfuscated to obtain a binary obfuscated stream, the binary obfuscated stream is encrypted to obtain a binary obfuscated encrypted stream, and then according to the forward positioning index number, reverse positioning index number, and interception length number in the second data group, the binary obfuscated encrypted stream is obfuscated to obtain an obfuscated binary obfuscated encrypted stream. Finally, by intercepting the obfuscated binary obfuscated encrypted stream, the obfuscated binary obfuscated encrypted stream is segmented, and the segmented obfuscated binary obfuscated encrypted streams are stored separately. Thus, through multiple obfuscation processes, encryption processes, and segmentation processes on the file, the difficulty of cracking the file is effectively increased, and the security of file storage is guaranteed. Especially for the model file of the machine learning core model obtained by training, by increasing the difficulty coefficient of stealing and cracking the model file, the rights and interests of enterprises owning the machine learning core model can be effectively guaranteed.
[0157] Embodiment 2
[0158] In this embodiment, a file decryption method based on a machine learning core model is proposed, and the encrypted and obfuscated data stored separately is obtained, and the encrypted and obfuscated data is decrypted and de-obfuscated to obtain a model file containing algorithms, parameters, etc.
[0159] See Figure 4 , the embodiments of the present invention provide a file decryption method, and the method may include the following steps:
[0160] S201. Obtain the obfuscated binary obfuscated encrypted stream of a predetermined length saved in the first memory and the obfuscated binary obfuscated encrypted stream after intercepting a predetermined number of bytes saved in the second memory, and splice them to obtain an obfuscated binary obfuscated encrypted stream;
[0161] In some alternative embodiments, based on the obfuscated binary obfuscated encrypted stream of a predetermined length saved in the first memory and the obfuscated binary obfuscated encrypted stream after intercepting a predetermined number of bytes saved in the second memory obtained after encrypting the above file, they are spliced to obtain an obfuscated binary obfuscated encrypted stream;
[0162] S202. Deobfuscate the obfuscated binary encrypted stream according to the forward positioning index number, reverse positioning index number, and intercepted length number in the pre-set second data group to obtain a binary encrypted stream;
[0163] In some alternative embodiments, the step of deobfuscating the obfuscated binary encrypted stream according to the pre-set second data group to obtain a binary encrypted stream includes:
[0164] Starting from the starting position of the obfuscated binary encrypted stream, locate the position of the forward positioning index number. Taking the position of the forward positioning index number as the starting position, intercept the bytes corresponding to the intercepted length number in the forward direction to obtain a binary reverse-intercepted encrypted stream;
[0165] Starting from the end position of the obfuscated binary encrypted stream, locate the position of the reverse positioning index number. Taking the position of the reverse positioning index number as the starting position, intercept the bytes corresponding to the intercepted length number in the reverse direction to obtain a binary forward-intercepted encrypted stream;
[0166] Perform a swapping restoration on the binary forward-intercepted encrypted stream and the binary reverse-intercepted encrypted stream to obtain the binary encrypted stream.
[0167] Continuing with the above example, according to the position information included in the second data group A2, namely the third index number a2, the fourth index number b2, and the second length number c2, perform deobfuscation processing on the obfuscated binary encrypted stream S4. For example, starting from the starting position, find the position of the third index number a2 in the forward direction, intercept the bytes with the length of the second length number c2 to obtain the second obfuscated binary encrypted stream B4. Starting from the end position, find the position of the fourth index number b2 in the reverse direction, intercept the bytes with the length of the second length number c2 to obtain the first obfuscated binary encrypted stream B3. Swap and replace the second obfuscated binary encrypted stream B4 with the first obfuscated binary encrypted stream B3 to obtain the binary encrypted stream S3, thereby realizing the deobfuscation of the obfuscated binary encrypted stream.
[0168] S203. Decrypt the binary encrypted stream using the decryption key obtained by the pre-set encryption algorithm to obtain a binary obfuscated stream;
[0169] In this embodiment, decrypt the binary encrypted stream S3 according to the decryption key to generate the decrypted binary obfuscated stream S2.
[0170] S204. Deobfuscate the binary obfuscated stream according to the forward positioning index number, reverse positioning index number, and intercepted length number in the pre-set first data group to obtain a binary stream;
[0171] In some alternative embodiments, de - obfuscating the binary obfuscated stream according to the forward positioning index number, reverse positioning index number, and intercepted length number in the preset first data group to obtain a binary stream includes:
[0172] Starting from the starting position of the binary obfuscated stream, locate the position of the forward positioning index number. Taking the position of the forward positioning index number as the starting position, intercept the bytes corresponding to the intercepted length number in the forward order to obtain a binary reverse - intercepted stream;
[0173] Starting from the ending position of the binary obfuscated stream, locate the position of the reverse positioning index number. Taking the position of the reverse positioning index number as the starting position, intercept the bytes corresponding to the intercepted length number in the reverse order to obtain a binary forward - intercepted stream;
[0174] Perform a swapping and restoration on the binary forward - intercepted stream and the binary reverse - intercepted stream to obtain the binary stream.
[0175] In this embodiment, following the above example, according to the position information included in the first data group A1, i.e., the first index number a1, the second index number b1, and the first length number c1, perform de - obfuscation processing on the binary obfuscated stream S2. For example, find the position of the first index number a1 in the forward order from the starting position, intercept the bytes with the length of the first length number c1 to obtain a binary forward - intercepted stream B1, find the position of the second index number b1 in the reverse order from the ending position, intercept the bytes with the length of the first length number c1 to obtain a binary reverse - intercepted stream B2, and swap and replace the binary forward - intercepted stream B1 with the binary reverse - intercepted stream B2 to obtain the binary stream S1.
[0176] S205. Convert the binary stream into a file.
[0177] In this embodiment, convert the binary stream S1 into the original model file F1 for the normal use of the model caller.
[0178] The file decryption method in this embodiment is the reverse process of the file encryption method in Embodiment 1. The corresponding processing procedures can refer to the description in Embodiment 1 and will not be elaborated herein.
[0179] Embodiment 3
[0180] In this embodiment, on the basis of ensuring file storage security, a file secure transmission method is further provided. The encrypted file of the model trainer can be transmitted to the model caller, and the file transmission security between the two parties is also very important. The implementation processes of each party will be described below from the perspectives of the model trainer and the model caller respectively.
[0181] The implementation flow chart of the model trainer is as Figure 5As shown in the figure, it mainly includes the following steps:
[0182] S301. In response to the public key request of the homomorphic encryption algorithm from the model invoker, return the ciphertext of the random number and the public key of the homomorphic encryption algorithm to the model invoker;
[0183] In this embodiment, when the user, that is, the model invoker, needs to obtain the model file of the machine learning core model obtained through training from the model trainer, that is, the main body that performs file encryption in this embodiment, it is necessary to first negotiate a key with the model trainer to encrypt the model file to be transmitted using the negotiated dynamic key, thereby enhancing the security during the transmission of the model file. Therefore, a public key request of the homomorphic encryption algorithm is sent to the model trainer to request the public key generation interface of the homomorphic encryption algorithm of the model trainer. The model trainer receives the public key request of the homomorphic encryption algorithm from the model invoker and returns the ciphertext of the random number and the public key of the homomorphic encryption algorithm to the model invoker.
[0184] In this embodiment, as an alternative embodiment, the homomorphic encryption algorithm (HE, Homomorphic Encryption) includes but is not limited to: the full homomorphic encryption (FHE, Full Homomorphic Encryption) algorithm, the partial homomorphic encryption (PHE, Partial Homomorphic Encryption) algorithm, the leveled homomorphic encryption (LHE, Leveled Homomorphic Encryption) algorithm, and the Paillier algorithm.
[0185] In this embodiment, as an alternative embodiment, the step of "in response to the public key request of the homomorphic encryption algorithm from the model invoker, return the ciphertext of the random number and the public key of the homomorphic encryption algorithm to the model invoker" includes:
[0186] C11. Generate a first random number according to the public key request of the homomorphic encryption algorithm;
[0187] C12. Encrypt the first random number using the public key of the homomorphic encryption algorithm to obtain the ciphertext of the random number;
[0188] C13. Send the ciphertext of the random number and the public key of the homomorphic encryption algorithm to the model invoker.
[0189] In this embodiment, the model invokes the homomorphic encryption algorithm public key generation interface from the model training party. After receiving the request, the model training party generates a random number S1, uses the Paillier algorithm to generate a homomorphic encryption algorithm public and private key pair including the homomorphic encryption algorithm public key K and the homomorphic encryption algorithm private key, encrypts the random number S1 with the homomorphic encryption algorithm public key K to obtain the random number ciphertext E1, and returns the random number ciphertext and the homomorphic encryption algorithm public key K to the model invoker. As an alternative embodiment, the homomorphic encryption algorithm public and private key pair can be updated regularly.
[0190] S302. Receive the blinded ciphertext sent by the model invoker. The blinded ciphertext is obtained by blinding the generated request identifier based on the random number ciphertext and the homomorphic encryption algorithm public key.
[0191] In this embodiment, as an alternative embodiment, blinding the request identifier based on the random number ciphertext and the homomorphic encryption algorithm public key to obtain the blinded ciphertext includes:
[0192] C21. Use the homomorphic encryption algorithm public key to homomorphically encrypt the request identifier to obtain the identifier ciphertext.
[0193] C22. Perform a multiplication operation on the random number ciphertext and the identifier ciphertext to obtain the blinded ciphertext.
[0194] In this embodiment, use the homomorphic encryption algorithm public key K obtained from the model training party to homomorphically encrypt the request identifier Q1 to obtain the identifier ciphertext E2, multiply the identifier ciphertext E2 by the random number ciphertext E1 obtained from the model training party to obtain the blinded ciphertext Q2, and send the blinded ciphertext Q2 to the model training party, that is, the model training party receives the blinded ciphertext sent by the model invoker.
[0195] S303. Use the pre-generated homomorphic encryption algorithm private key to decrypt the blinded ciphertext to obtain the blinded plaintext. Based on the blinded plaintext, obtain the device parsing identifier, parsing timestamp, and first parsing random number, and generate the first data transmission key based on the device parsing identifier, parsing timestamp, first parsing random number, and the preset key rule.
[0196] In this embodiment, the model training party obtains the identifier parsing ciphertext and the random number parsing ciphertext by performing an inverse multiplication operation on the blinded ciphertext, and uses the homomorphic encryption algorithm private key to decrypt the identifier parsing ciphertext and the random number parsing ciphertext respectively to obtain the corresponding decryption results. It is also possible to decrypt the blinded ciphertext first and then perform the inverse multiplication operation.
[0197] In this embodiment, as an alternative embodiment, the blinded ciphertext is decrypted by using a pre-generated private key of the homomorphic encryption algorithm to obtain the blinded plaintext. Based on the blinded plaintext, the device parsing identifier, the parsing timestamp, and the first parsing random number are obtained, including:
[0198] C31. The model training party uses the private key of the homomorphic encryption algorithm to decrypt the blinded ciphertext to obtain the blinded plaintext.
[0199] C32. An inverse multiplication operation is performed on the blinded plaintext to obtain the request parsing identifier and the first parsing random number.
[0200] In this embodiment, the blinded ciphertext is decrypted by using the private key of the homomorphic encryption algorithm to obtain the blinded plaintext, and an inverse multiplication operation is performed on the blinded plaintext to obtain the request parsing identifier and the first parsing random number included in the blinded plaintext.
[0201] C33. According to the splicing rule of the request identifier, the request parsing identifier is reversely parsed to obtain the device parsing identifier and the parsing timestamp.
[0202] C34. It is determined that the parsing timestamp is within the valid period.
[0203] In this embodiment, if the parsed parsing timestamp is not within the valid period, it indicates that there is a risk of information forgery, and an error message of the parameter is returned. If it is within the valid period, the device parsing identifier, the parsing timestamp, and the first parsing random number are determined as valid parameters, and a first data transmission key is generated based on the parsed device parsing identifier, the first parsing random number, and the parsing timestamp.
[0204] In this embodiment, as an alternative embodiment, a first data transmission key is generated based on the device parsing identifier, the parsing timestamp, the first parsing random number, and a preset key rule, including:
[0205] The first five digits of the device parsing identifier and the first five digits of the parsing timestamp are obtained.
[0206] The first five digits of the device parsing identifier, the first parsing random number, and the first five digits of the parsing timestamp are spliced to obtain the first data transmission key.
[0207] In this embodiment, as an alternative embodiment, the first five digits of the device parsing identifier I1 + the first parsing random number S1 + the first five digits of the parsing timestamp T are used as the first data transmission key K and saved in the database.
[0208] S304. A verification ciphertext is generated based on the first data transmission key, the device parsing identifier, and the parsing timestamp, and the blinded plaintext and the verification ciphertext are returned to the model invoker.
[0209] In this embodiment, as an alternative embodiment, generating a verification ciphertext based on the first data transmission key, the device parsing identifier, and the parsing timestamp includes:
[0210] Concatenate the device parsing identifier and the parsing timestamp, perform a hashing operation on the concatenation result to obtain a parsing hash result;
[0211] Extract the first four digits of the parsing hash result;
[0212] Use the first data transmission key to encrypt the first four digits of the extracted parsing hash result to obtain the verification ciphertext.
[0213] In this embodiment, use the first data transmission key K to encrypt the first four digits of the parsing hash result I2 to obtain the verification ciphertext E3. Return the blinded plaintext V and the verification ciphertext E3 to the model invoker.
[0214] In this embodiment, the model trainer uses the private key of the homomorphic encryption algorithm to decrypt the blinded ciphertext Q2 to obtain the blinded plaintext V and de-blind it to obtain the requested parsing identifier, that is, the request identifier Q1, and according to the reverse rule of the rule for generating the request identifier Q1, parse to obtain the device parsing identifier (device identifier I1) and the parsing timestamp (current timestamp T), and detect whether the current timestamp is within the valid period. If it is not within the valid period, return a parameter error message. If it is within the valid period, use the first five digits of the device identifier I1 + the first random number S1 + the first five digits of the current timestamp T as the final data transmission key K, and use the data transmission key K to encrypt the first four digits of the hash parsing result I2 to obtain the verification ciphertext E3; return the blinded plaintext V and the verification ciphertext E3 to the model invoker.
[0215] S305, if receiving the message that the verification of the verification ciphertext sent by the model invoker is successful, use the first data transmission key as the data transmission key to perform the file transmission with the model invoker.
[0216] In this embodiment, as an alternative embodiment, the model invoker de-blinds the blinded plaintext, generates a second data transmission key based on the de-blinding result and the key rule, verifies the verification ciphertext. If the verification is successful, use the first data transmission key as the data transmission key to perform the file transmission with the model invoker.
[0217] In some alternative embodiments, the performing the file transmission with the model invoker using the first data transmission key as the data transmission key includes:
[0218] In response to a data acquisition request from a model invoker, obtain a predetermined-length obfuscated binary obfuscated encryption stream, an encryption key, a first data group, and a second data group stored in a first memory, encrypt them using a data transfer key, and transmit them to the model invoker; and obtain the obfuscated binary obfuscated encryption stream after intercepting a predetermined number of bytes stored in a second memory, encrypt it using the data transfer key, and transmit it to the model invoker.
[0219] In this embodiment, as an alternative embodiment, when the model trainer receives a request from the model invoker: obtain a predetermined-length obfuscated binary obfuscated encryption stream, a first data group, and a second data group stored in the first memory, encrypt them using the data transfer key, and transmit them to the model invoker, it includes:
[0220] The model invoker transmits the data transfer key and the encrypted model request identifier to the model trainer;
[0221] The model trainer decrypts the received model request identifier using the data transfer key to obtain the model invoker, and reads a predetermined-length obfuscated binary obfuscated encryption stream, an encryption key, a first data group, and a second data group from the first memory;
[0222] Perform obfuscation processing on the predetermined-length obfuscated binary obfuscated encryption stream, the encryption key, the first data group, and the second data group, encrypt the obfuscated processed file using the data transfer key, and transmit it to the model invoker.
[0223] In this embodiment, after obtaining the model invoker, user identity authentication can be performed on the model invoker, and the model invoker with successful identity authentication can obtain the file.
[0224] The model invoker obtains the obfuscated binary obfuscated encryption stream after intercepting a predetermined number of bytes stored in the second memory of the model invoker, encrypts it using the data transfer key, and transmits it to the model invoker.
[0225] In some alternative embodiments, when obtaining the obfuscated binary obfuscated encryption stream after intercepting a predetermined number of bytes stored in the second memory, encrypting it using the data transfer key, and transmitting it to the model invoker, it includes:
[0226] The model invoker obtains the obfuscated binary obfuscated encryption stream after intercepting a predetermined number of bytes stored in the disk (second memory) of the model trainer according to a mutually agreed method, encrypts it using the data transfer key, and user identity authentication can be performed before obtaining it, and only the user with successful authentication can obtain the file.
[0227] In this embodiment, the transmission method can be FTP, an interface, or other methods, which will not be elaborated here.
[0228] The implementation flowchart of the model invoker is as follows Figure 6 shown, which mainly includes the following steps:
[0229] S401. Send a request for the public key of the homomorphic encryption algorithm to the model trainer;
[0230] In some optional embodiments, when the model invoker needs to obtain the model file of the machine learning core model obtained through training from the model trainer, it needs to first negotiate a key with the model trainer to encrypt the model file to be transmitted using the negotiated dynamic key, thereby enhancing the security during the transmission of the model file. Therefore, a request for the public key of the homomorphic encryption algorithm is sent to the model trainer to request the public key generation interface of the homomorphic encryption algorithm of the model trainer.
[0231] S402. Receive the ciphertext of the random number and the public key of the homomorphic encryption algorithm returned by the model trainer in response to the request for the public key of the homomorphic encryption algorithm;
[0232] In some optional embodiments, based on the request for the public key of the homomorphic encryption algorithm sent by the model invoker to the model trainer, the model trainer returns the ciphertext of the random number and the public key of the homomorphic encryption algorithm to the model invoker.
[0233] In this embodiment, the model invoker does not need to store any key-related information locally. Each time data or file transmission is performed, a data transmission key is generated temporarily to encrypt the transmitted data. Moreover, during the generation process of the data transmission key, the complete key information is not transmitted, which can effectively ensure the security of the data transmission key.
[0234] S403. Generate a request identifier, blind the request identifier based on the ciphertext of the random number and the public key of the homomorphic encryption algorithm to obtain a blinded ciphertext, and send it to the model trainer;
[0235] In some optional embodiments, the generation of the request identifier by the model invoker includes:
[0236] D11. Obtain the device identifier and the current timestamp;
[0237] D12. Perform a hash operation on the device identifier and the current timestamp to obtain a hash result;
[0238] In this embodiment, as an optional embodiment, the hash algorithm includes but is not limited to: SM3, MD5.
[0239] D13. Generate a second random number and a third random number;
[0240] D14. Concatenate the device identifier, the second random number, the current timestamp, the third random number, and the first four digits of the hash result to obtain the request identifier.
[0241] In this embodiment, the model invoker performs a hashing operation based on the device identifier I1 to which it belongs and the current timestamp T to obtain a hashing result I2, extracts the first four digits of the hashing result I2, and concatenates the device identifier I1, the second random number S2, the current timestamp T, the third random number S3, and the first four digits of the hashing result I2 to obtain a request identifier Q1.
[0242] In this embodiment, as an optional embodiment, the request identifier is blinded based on the random number ciphertext and the public key of the homomorphic encryption algorithm to obtain a blinded ciphertext, including:
[0243] D21, using the public key of the homomorphic encryption algorithm to perform homomorphic encryption on the request identifier to obtain an identifier ciphertext;
[0244] D22, performing a multiplication operation on the random number ciphertext and the identifier ciphertext to obtain the blinded ciphertext.
[0245] In this embodiment, the public key K of the homomorphic encryption algorithm obtained from the model trainer is used to perform homomorphic encryption on the request identifier Q1 to obtain an identifier ciphertext E2, and the identifier ciphertext E2 is multiplied by the random number ciphertext E1 obtained from the model trainer to obtain a blinded ciphertext Q2, and the blinded ciphertext Q2 is sent to the model trainer.
[0246] S404. Receive the blinded plaintext and the verification ciphertext returned by the model trainer; the blinded plaintext is obtained by the model trainer decrypting the blinded ciphertext using a pre-generated private key of the homomorphic encryption algorithm; the verification ciphertext is generated by the model trainer based on the first data transmission key, the device parsing identifier, and the parsing timestamp; the first data transmission key is generated based on the blinded plaintext, obtaining the device parsing identifier, the parsing timestamp, and the first parsing random number, and based on the device parsing identifier, the parsing timestamp, the first parsing random number, and a preset key rule;
[0247] In some optional embodiments, after sending the blinded ciphertext Q2 to the model trainer, the model trainer decrypts the blinded ciphertext and generates a verification ciphertext, and returns it to the model invoker.
[0248] S405. Deblind the blinded plaintext, generate a second data transmission key based on the deblinding result and the key rule, generate a verification ciphertext according to the second data transmission key, and verify the verification ciphertext based on the verification ciphertext. If the verification is successful, use the second data transmission key as the data transmission key to perform data transmission with the model trainer;
[0249] In some alternative embodiments, generating a verification ciphertext based on the de - blinding result and the key rule, and verifying the check ciphertext based on the verification ciphertext includes:
[0250] Performing an inverse multiplication operation on the blinded plaintext to obtain a request de - blinding identifier and a de - blinding random number;
[0251] Based on the request de - blinding identifier, obtaining a device de - blinding identifier and a de - blinding timestamp, and concatenating the first five digits of the device de - blinding identifier, the de - blinding random number, and the first five digits of the de - blinding timestamp to obtain a second data transmission key;
[0252] Performing a hashing operation on the device de - blinding identifier and the de - blinding timestamp to obtain a de - blinding hash result, and encrypting the first four digits of the de - blinding hash result using the second data transmission key to obtain a verification ciphertext;
[0253] If it is determined that the check ciphertext is consistent with the verification ciphertext, the verification passes.
[0254] In this embodiment, as an alternative embodiment, generating a second data transmission key based on the de - blinding result and the key rule includes:
[0255] D31, the model invoker performs an inverse multiplication operation on the blinded plaintext to obtain a request de - blinding identifier and a de - blinding random number;
[0256] In this embodiment, the model invoker can calculate and parse out the de - blinding random number and the first random number S1 according to the inverse multiplication principle based on the blinded plaintext V.
[0257] D32, based on the request de - blinding identifier, obtaining a device de - blinding identifier and a de - blinding timestamp, and concatenating the first five digits of the device de - blinding identifier, the de - blinding random number, and the first five digits of the de - blinding timestamp to obtain a second data transmission key;
[0258] In this embodiment, the first five digits of the device identifier I1 (device de - blinding identifier)+the first random number S1 (de - blinding random number)+the first five digits of the current timestamp T (de - blinding timestamp) are used as the final second data transmission key.
[0259] D33, performing a hashing operation on the device de - blinding identifier and the de - blinding timestamp to obtain a de - blinding hash result, and encrypting the first four digits of the de - blinding hash result using the second data transmission key to obtain a verification ciphertext;
[0260] In this embodiment, using the second data transmission key K' to encrypt the first four digits of the hash result I2 (de - blinding hash result) to obtain a verification ciphertext E3.
[0261] D34. Determine that the verification ciphertext is consistent with the authentication ciphertext, and obtain a data transmission key based on the second data transmission key.
[0262] In this embodiment, compare whether the verification ciphertext E3 and the authentication ciphertext E4 are consistent. If the result is consistent, it indicates that the first data transmission key generated by the model training party is consistent with the second data transmission key generated by the model invoker, and use the second data transmission key as the data transmission key for file transmission.
[0263] In this embodiment, the model invoker deblinds the blinded plaintext V, and can calculate the first random number S1 (deblinding random number). According to the key rule with the model training party, generate the second data transmission key K'. Use the second data transmission key K' to encrypt the first four bits of the hash result I2 (deblinding hash result) to obtain the authentication ciphertext E4, and compare whether the verification ciphertext E3 and the authentication ciphertext E4 are consistent. If the result is consistent, it means that the keys generated by both parties are consistent, and the data transmission key is successfully generated.
[0264] In some alternative embodiments, using the second data transmission key as the data transmission key to perform data transmission with the model training party includes:
[0265] Send a data acquisition request to the model training party;
[0266] Receive the encrypted data sent by the model training party in response to the data acquisition request;
[0267] Use the data transmission key to decrypt the received encrypted data to obtain a confused binary confused encryption stream of a predetermined length, an encryption key, a first data group, a second data group, and the confused binary confused encryption stream after intercepting a predetermined number of bytes.
[0268] In some alternative embodiments, the step of using the data transmission key to decrypt the received encrypted data to obtain a confused binary confused encryption stream of a predetermined length, an encryption key, a first data group, a second data group, and the confused binary confused encryption stream after intercepting a predetermined number of bytes includes:
[0269] 1) The model invoker uses the data transmission key to decrypt the received file to obtain a confused binary confused encryption stream of a predetermined length, an encryption key, a first data group, a second data group, and the confused binary confused encryption stream after intercepting a predetermined number of bytes;
[0270] In this embodiment, use the data transmission key to decrypt the file (confused encryption process) returned by the model training party interface to obtain a confused binary confused encryption stream S of a predetermined length, an encryption key KF, a first data group (A1), a second data group (A2), and the confused binary confused encryption stream after intercepting a predetermined number of bytes.
[0271] 2) Concatenate the obfuscated binary obfuscated encryption stream of the predetermined length and the obfuscated binary obfuscated encryption stream after intercepting the predetermined number of bytes to obtain an obfuscated binary obfuscated encryption stream;
[0272] In this embodiment, the files obtained from the database (the first memory) and the disk (the second memory) are concatenated to obtain the complete ciphertext of the model file: the obfuscated binary obfuscated encryption stream.
[0273] In this embodiment, taking the encryption method of the machine learning model file of the natural gas market simulation platform as an example, Figure 7 It is a schematic diagram of the encryption of the machine learning model file of the natural gas market simulation platform for a file encryption method provided by an embodiment of the present invention. As Figure 7 shown, the machine learning model of the natural gas market simulation platform includes: a model training party and a model calling party. Among them,
[0274] Before encrypting the model file, the model training party performs obfuscation to generate an obfuscated file, encrypts the obfuscated file to generate an encrypted file, performs obfuscation after encrypting the encrypted file to obtain an obfuscated file, splits and disassembles the obfuscated file obtained after encryption to form a disk file and a database file stream, and stores them separately;
[0275] The model calling party interacts with the model training party to generate a transmission key, obtains the database file stream and the disk file transmitted according to the transmission key from the model training party, concatenates the received encrypted database file stream and disk file to obtain an obfuscated file, performs de-obfuscation before decrypting the obfuscated file to obtain an encrypted file, decrypts the encrypted file to obtain an obfuscated file, and performs de-obfuscation after decrypting the obfuscated file to obtain the model file and use it.
[0276] In this embodiment, through the application of this machine learning model file encryption method, in addition to encrypting the model file, obfuscation and splitting are also performed. At the same time, multiple methods are used to provide file service processing. During data transmission, the method of generating data transmission keys by both the sender and the receiver is adopted, which avoids the loss and theft of data transmission keys. If the relevant processing rules of the data transmission key are not clear, it will be very difficult to crack. In the actual data transmission application process, other security measures such as the identity authentication of the calling party and the https transmission protocol can also be combined and used, which greatly enhances the security of each link of model file storage and transmission, effectively preventing the risk of decrypting the model file through brute force cracking. At the same time, only part of the encrypted file is saved in the database, so there is no obvious impact on performance, ensuring the high performance and availability of the overall process.
[0277] The method of this embodiment has greatly improved in terms of confidentiality, integrity, and availability, and meets the requirements of the Confidentiality, Integrity, Availability (CIA) model in machine learning for the security of file content, with remarkable effects.
[0278] Based on the same inventive concept, the embodiment of the present invention further provides a file encryption device, as Figure 8 shown, including:
[0279] A stream conversion module 11, configured to convert a file to be encrypted into a binary stream;
[0280] A first confusion module 12, configured to perform confusion processing on the binary stream according to the forward positioning index number, reverse positioning index number, and intercepted length number in a pre-set first data group to obtain a binary confused stream;
[0281] In this embodiment, as an optional embodiment, the first confusion module 12 includes:
[0282] A forward positioning unit, configured to start from the starting position of the binary stream, locate the position of the forward positioning index number, and starting from the position of the forward positioning index number, intercept the bytes corresponding to the intercepted length number in the forward order to obtain a binary forward intercepted stream;
[0283] A reverse positioning unit, configured to start from the end position of the binary stream, locate the position of the reverse positioning index number, and starting from the position of the reverse positioning index number, intercept the bytes corresponding to the intercepted length number in the reverse order to obtain a binary reverse intercepted stream;
[0284] A replacement unit, configured to perform swap replacement on the binary forward intercepted stream and the binary reverse intercepted stream to obtain the binary confused stream.
[0285] An encryption module 13, configured to encrypt the binary confused stream with an encryption key obtained by using a pre-set encryption algorithm to obtain a binary confused encrypted stream;
[0286] A second confusion module 14, configured to perform confusion processing on the binary confused encrypted stream according to the forward positioning index number, reverse positioning index number, and intercepted length number in a pre-set second data group to obtain a confused binary confused encrypted stream;
[0287] A separated storage module 15, configured to intercept bytes of a predetermined length from the confused binary confused encrypted stream, save them to a first memory, and save the confused binary confused encrypted stream after intercepting bytes of the predetermined length to a second memory.
[0288] In this embodiment, the first memory is a database and the second memory is a server disk.
[0289] In some alternative embodiments, on the basis of what is shown, the file encryption device further includes modules as shown in Figure 8 what is shown: Figure 9 modules as shown in
[0290] A request response module 16, configured to respond to a request for a public key of a homomorphic encryption algorithm from a model invoker, and return a random number ciphertext and the public key of the homomorphic encryption algorithm to the model invoker;
[0291] In this embodiment, as an alternative embodiment, the request response module includes:
[0292] A random number generation unit, configured to generate a first random number according to the request for the public key of the homomorphic encryption algorithm;
[0293] A ciphertext generation unit, configured to encrypt the first random number by using the public key of the homomorphic encryption algorithm to obtain the random number ciphertext;
[0294] A sending unit, configured to send the random number ciphertext and the public key of the homomorphic encryption algorithm to the model invoker.
[0295] A ciphertext receiving module 17, configured to receive a blinded ciphertext sent by a model invoker, where the blinded ciphertext is obtained by blinding a generated request identifier based on the random number ciphertext and the public key of the homomorphic encryption algorithm;
[0296] A first key generation module 18, configured to decrypt the blinded ciphertext by using a pre-generated private key of the homomorphic encryption algorithm to obtain a blinded plaintext, and based on the blinded plaintext, obtain a device parsing identifier, a parsing timestamp, and a first parsing random number, and generate a first data transmission key based on the device parsing identifier, the parsing timestamp, the first parsing random number, and a preset key rule;
[0297] In this embodiment, as an alternative embodiment, the first key generation module includes:
[0298] A decryption unit, configured to decrypt the blinded ciphertext by using the private key of the homomorphic encryption algorithm to obtain a blinded plaintext;
[0299] A multiplication operation unit, configured to perform an inverse multiplication operation on the blinded plaintext to obtain a request parsing identifier and a first parsing random number;
[0300] An information acquisition unit, configured to inversely parse the request parsing identifier according to a splicing rule of the request identifier to obtain a device parsing identifier and a parsing timestamp;
[0301] A validity determination unit, configured to determine that the parsing timestamp is within a valid period.
[0302] In this embodiment, as another alternative embodiment, the first key generation module further includes:
[0303] A splicing unit, configured to splice the device parsing identifier and the parsing timestamp, perform a hash operation on the splicing result, and obtain a parsing hash result;
[0304] An extraction unit, configured to extract the first four bits of the parsing hash result;
[0305] A verification ciphertext generation unit, configured to encrypt the first four bits of the extracted parsing hash result by using the first data transmission key to obtain the verification ciphertext.
[0306] A ciphertext generation module 19, configured to generate a verification ciphertext according to the first data transmission key, the device parsing identifier, and the parsing timestamp, and return the blinded plaintext and the verification ciphertext to the model invoker.
[0307] A first transmission module 20, configured to, if receiving a message that the verification of the verification ciphertext sent by the model invoker is successful, perform the file transmission with the model invoker by using the first data transmission key as the data transmission key.
[0308] Optionally, the above-mentioned first transmission module 20 is specifically configured to, in response to a data acquisition request from the model invoker, acquire a predetermined-length obfuscated binary obfuscated encryption stream, an encryption key, a first data group, and a second data group stored in a first memory, encrypt them by using the data transmission key, and transmit them to the model invoker; and acquire the obfuscated binary obfuscated encryption stream after intercepting a predetermined number of bytes stored in a second memory, encrypt it by using the data transmission key, and transmit it to the model invoker.
[0309] The embodiment of the present invention further includes a file decryption device, as Figure 10 shown, including:
[0310] A splicing module 21, configured to acquire a predetermined-length obfuscated binary obfuscated encryption stream stored in a first memory and the obfuscated binary obfuscated encryption stream after intercepting a predetermined number of bytes stored in a second memory, and splice them to obtain an obfuscated binary obfuscated encryption stream;
[0311] A first de-obfuscation module 22, configured to de-obfuscate the obfuscated binary obfuscated encryption stream according to the forward positioning index number, the reverse positioning index number, and the intercepted length number in a second data group set in advance to obtain a binary obfuscated encryption stream;
[0312] A decryption module 23, configured to decrypt the binary obfuscated encryption stream by using a decryption key obtained by using a preset encryption algorithm to obtain a binary obfuscated stream;
[0313] The second de - obfuscation module 24 is configured to de - obfuscate the binary obfuscated stream according to the forward positioning index number, reverse positioning index number, and truncation length number in the pre - set first data group to obtain a binary stream;
[0314] The file conversion module 25 is configured to convert the binary stream into a file.
[0315] In some alternative embodiments, the above - mentioned file decryption device further includes modules as shown in Figure 10 on the basis of Figure 11 :
[0316] The request sending module 26 is configured to send a request for the public key of the homomorphic encryption algorithm to the model trainer;
[0317] The first receiving module 27 is configured to receive the ciphertext of the random number and the public key of the homomorphic encryption algorithm returned by the model trainer in response to the request for the public key of the homomorphic encryption algorithm;
[0318] The blinding module 28 is configured to generate a request identifier, blind the request identifier based on the ciphertext of the random number and the public key of the homomorphic encryption algorithm to obtain a blinded ciphertext, and send it to the model trainer;
[0319] In this embodiment, as an alternative embodiment, generating the request identifier includes:
[0320] Obtaining the device identifier and the current timestamp;
[0321] Performing a hash operation on the device identifier and the current timestamp to obtain a hash result;
[0322] Generating a second random number and a third random number;
[0323] Concatenating the device identifier, the second random number, the current timestamp, the third random number, and the first four digits of the hash result to obtain the request identifier.
[0324] In this embodiment, as an alternative embodiment, blinding the request identifier based on the ciphertext of the random number and the public key of the homomorphic encryption algorithm to obtain a blinded ciphertext includes:
[0325] Using the public key of the homomorphic encryption algorithm to perform homomorphic encryption on the request identifier to obtain an identifier ciphertext;
[0326] Performing a multiplication operation on the ciphertext of the random number and the identifier ciphertext to obtain the blinded ciphertext.
[0327] A second receiving module 29, configured to receive the blinded plaintext and the verification ciphertext returned by the model training party; the blinded plaintext is obtained by the model training party decrypting the blinded ciphertext by using a pre-generated private key of the homomorphic encryption algorithm; the verification ciphertext is generated by the model training party according to the first data transmission key, the device parsing identifier, and the parsing timestamp; the first data transmission key is generated based on the blinded plaintext, obtaining the device parsing identifier, the parsing timestamp, and the first parsing random number, and based on the device parsing identifier, the parsing timestamp, the first parsing random number, and a preset key rule.
[0328] A second key generation module 30, configured to unblind the blinded plaintext, generate a second data transmission key based on the unblinding result and the key rule, generate a verification ciphertext according to the second data transmission key, verify the verification ciphertext based on the verification ciphertext, and if the verification is successful, notify to use the second data transmission key as the data transmission key to perform data transmission with the model training party.
[0329] A second transmission module 31, configured to use the second data transmission key as the data transmission key to perform data transmission with the model training party.
[0330] In this embodiment, as an optional embodiment, the second transmission module 31 is specifically configured to: send a data acquisition request to the model training party; receive the encrypted data sent by the model training party in response to the data acquisition request; use the data transmission key to decrypt the received encrypted data to obtain a confused binary encrypted stream of a predetermined length, an encryption key, a first data group, a second data group, and the confused binary encrypted stream after intercepting a predetermined number of bytes.
[0331] After the second transmission module 31 receives the above data, the model invoker executes the process of decrypting the file.
[0332] In addition, an embodiment of the present invention further provides a file transmission system, as Figure 12 shown, including a model training device 41 and a model invoking device 42;
[0333] The above-mentioned file encryption device is arranged in the model training device for encrypting the data stream of the file to be encrypted;
[0334] The above-mentioned file decryption device is arranged in the model invoking device for decrypting the encrypted data stream to obtain the decrypted file.
[0335] An embodiment of the present invention further provides a computer storage medium, in which computer executable instructions are stored, and when the computer executable instructions are executed by a processor, the above-mentioned file encryption method or the above-mentioned file decryption method is implemented.
[0336] An embodiment of the present invention further provides a computer device, including: a memory, a processor, and a computer program stored on the memory and executable on the processor, where when the processor executes the program, the above file encryption method or the above file decryption method is implemented.
[0337] An embodiment of the present invention further provides an electronic device, as Figure 13 shown, including a memory 101 (such as a non-volatile memory), a processor 102, and a computer program stored on the memory 101 and executable on the processor 102. When the processor 102 executes the program, the steps of the file encryption method in any possible implementation manner described above are implemented, which is equivalent to the file encryption device as described above. Of course, this processor can also be used to process other data or perform operations. The electronic device can be a device such as a PC, a server, a terminal, etc.
[0338] As Figure 13 shown, the electronic device generally may further include: a memory 103, a network interface 104, and an internal bus 105. In addition to these components, other hardware may also be included, which will not be elaborated herein.
[0339] It should be noted that the above file encryption device can be implemented by software. As a logically meaningful device, it is formed by the processor 102 of the electronic device where it is located reading the computer program instructions stored in the non-volatile memory into the memory 103 and running them.
[0340] The embodiments of the subject matter and the functional operations described in this specification can be implemented in the following: digital electronic circuits, tangible embodied computer software or firmware, computer hardware including the structures disclosed in this specification and their structural equivalents, or a combination of one or more of them. The embodiments of the subject matter described in this specification can be implemented as one or more computer programs, that is, one or more modules in computer program instructions encoded on a tangible non-transitory program carrier to be executed by a data processing device or to control the operation of a data processing device. Alternatively or additionally, the program instructions can be encoded on an artificially generated propagated signal, such as a machine-generated electrical, optical, or electromagnetic signal, which is generated to encode information and transmit it to a suitable receiver device for execution by a data processing device. The computer storage medium can be a machine-readable storage device, a machine-readable storage substrate, a random or serial access memory device, or a combination of one or more of them.
[0341] The processes and logical flows described in this specification can be performed by one or more programmable computers executing one or more computer programs to perform the corresponding functions by operating on input data and generating output. The processes and logical flows can also be performed by, for example, FPGA (Field Programmable Gate Array) or ASIC (Application Specific Integrated Circuit) of special logic circuits, and the apparatus can also be implemented as special logic circuits.
[0342] Computers suitable for executing computer programs include, for example, general and / or special microprocessors, or any other type of central processing unit. Generally, the central processing unit will receive instructions and data from a read-only memory and / or a random access memory. The basic components of a computer include a central processing unit for implementing or executing instructions and one or more memory devices for storing instructions and data. Generally, a computer will also include one or more mass storage devices for storing data, such as magnetic disks, magneto-optical disks, or optical disks, etc., or the computer will be operatively coupled to such mass storage devices to receive data from them or transfer data to them, or both. However, a computer is not necessarily required to have such devices. In addition, a computer can be embedded in another device, such as a mobile phone, a personal digital assistant (PDA), a mobile audio or video player, a game console, a global positioning system (GPS) receiver, or a portable storage device such as a universal serial bus (USB) flash drive, to name just a few.
[0343] Computer-readable media suitable for storing computer program instructions and data include all forms of non-volatile memory, media, and memory devices, such as semiconductor memory devices (e.g., EPROM, EEPROM, and flash memory devices), magnetic disks (e.g., internal hard disks or removable disks), magneto-optical disks, and CD-ROM and DVD-ROM disks. The processor and the memory can be supplemented by, or incorporated in, special logic circuits.
[0344] Although this specification contains many specific implementation details, these should not be construed as limiting the scope of any invention or the scope of what is claimed, but rather are mainly used to describe the features of specific embodiments of a particular invention. Certain features described in multiple embodiments in this specification can also be combined and implemented in a single embodiment. On the other hand, various features described in a single embodiment can also be separately implemented in multiple embodiments or implemented in any suitable sub-combination. In addition, although features can function in certain combinations as described above and are even initially claimed as such, one or more features from the claimed combination can in some cases be removed from the combination, and the claimed combination can be directed to a sub-combination or a variation of the sub-combination.
[0345] Similarly, although the operations are depicted in the drawings in a particular order, this should not be construed as requiring that the operations be performed in the particular order shown or sequentially, or that all illustrated operations be performed to achieve the desired result. In some cases, multitasking and parallel processing may be advantageous. Additionally, the separation of various system modules and components in the above-described embodiments should not be understood to be required in all embodiments, and it should be understood that the program components and systems described can generally be integrated together in a single software product or packaged into multiple software products.
[0346] Thus, particular embodiments of the subject matter have been described. Other embodiments are within the scope of the appended claims. In some cases, the acts recited in the claims can be performed in a different order and still achieve the desired result. Additionally, the processing depicted in the figures is not necessarily in the particular order or sequential order shown to achieve the desired result. In some implementations, multitasking and parallel processing may be advantageous.
[0347] It should be noted that, in this document, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variation thereof is intended to cover non-exclusive inclusion, such that a process, method, article or device comprising a series of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising one..." does not exclude the presence of additional identical elements in the process, method, article or device comprising the element.
[0348] The above are only specific embodiments of the present invention, enabling those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be obvious to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the broadest scope consistent with the principles and novel features claimed herein.
Claims
1. A file encryption method, characterized in that, Including: Converting the file to be encrypted into a binary stream; Performing confusion processing on the binary stream according to the forward positioning index number, reverse positioning index number, and truncation length number in the pre-set first data group to obtain a binary confusion stream; Encrypting the binary confusion stream with an encryption key obtained by a pre-set encryption algorithm to obtain a binary confusion encrypted stream; Performing confusion processing on the binary confusion encrypted stream according to the forward positioning index number, reverse positioning index number, and truncation length number in the pre-set second data group to obtain a confused binary confusion encrypted stream; Truncating a predetermined length of bytes from the confused binary confusion encrypted stream and saving them to the first memory, and saving the confused binary confusion encrypted stream after truncating the predetermined length of bytes to the second memory.
2. The file encryption method according to claim 1, wherein The performing confusion processing on the binary stream according to the forward positioning index number, reverse positioning index number, and truncation length number in the pre-set first data group includes: Starting from the starting position of the binary stream, locating the position of the forward positioning index number, taking the position of the forward positioning index number as the starting position, and forwardly truncating the bytes corresponding to the truncation length number to obtain a binary forward truncation stream; Starting from the end position of the binary stream, locating the position of the reverse positioning index number, taking the position of the reverse positioning index number as the starting position, and reversely truncating the bytes corresponding to the truncation length number to obtain a binary reverse truncation stream; Performing swap replacement on the binary forward truncation stream and the binary reverse truncation stream to obtain the binary confusion stream.
3. The file encryption method according to claim 1, characterized in that, The first memory is a database, and the second memory is a server disk.
4. The file encryption method according to any one of claims 1-3, characterized in that, It also includes: In response to the homomorphic encryption algorithm public key request received from the model caller, returning a random number ciphertext and the homomorphic encryption algorithm public key to the model caller; Receiving the blinded ciphertext sent by the model caller, where the blinded ciphertext is obtained by blinding the generated request identifier based on the random number ciphertext and the homomorphic encryption algorithm public key; Decrypting the blinded ciphertext with a pre-generated homomorphic encryption algorithm private key to obtain a blinded plaintext, and based on the blinded plaintext, obtaining a device parsing identifier, a parsing timestamp, and a first parsing random number, and generating a first data transmission key based on the device parsing identifier, the parsing timestamp, the first parsing random number, and a pre-set key rule; Generating a verification ciphertext based on the first data transmission key, the device parsing identifier, and the parsing timestamp, and returning the blinded plaintext and the verification ciphertext to the model caller; If receiving the message that the verification of the verification ciphertext sent by the model caller is successful, using the first data transmission key as the data transmission key to perform the file transmission with the model caller.
5. The file encryption method according to claim 4, wherein The in response to the homomorphic encryption algorithm public key request received from the model caller, returning a random number ciphertext and the homomorphic encryption algorithm public key to the model caller includes: Generating a first random number according to the homomorphic encryption algorithm public key request; Encrypting the first random number with the homomorphic encryption algorithm public key to obtain the random number ciphertext; Send the random number ciphertext and the public key of the homomorphic encryption algorithm to the model invoker.
6. The file encryption method according to claim 4, wherein Using the pre-generated private key of the homomorphic encryption algorithm to decrypt the blinded ciphertext to obtain the blinded plaintext, and based on the blinded plaintext, obtaining the device parsing identifier, parsing timestamp, and first parsing random number, including: Use the private key of the homomorphic encryption algorithm to decrypt the blinded ciphertext to obtain the blinded plaintext; Perform an inverse multiplication operation on the blinded plaintext to obtain the request parsing identifier and the first parsing random number; According to the splicing rule of the request identifier, perform reverse parsing on the request parsing identifier to obtain the device parsing identifier and the parsing timestamp; Determine that the parsing timestamp is within the valid period.
7. The file encryption method according to claim 4, wherein The generating the verification ciphertext according to the first data transmission key, device parsing identifier, and parsing timestamp includes: Splice the device parsing identifier and the parsing timestamp, and perform a hash operation on the splicing result to obtain a parsing hash result; Extract the first four digits of the parsing hash result; Use the first data transmission key to encrypt the first four digits of the extracted parsing hash result to obtain the verification ciphertext.
8. The file encryption method according to claim 4, characterized in that The performing the file transmission with the model invoker using the first data transmission key as the data transmission key includes: In response to the data acquisition request of the model invoker, obtain the predetermined-length confused binary encrypted stream, encryption key, first data group, and second data group stored in the first memory, encrypt them using the data transmission key, and transmit them to the model invoker; and obtain the confused binary encrypted stream after intercepting a predetermined number of bytes stored in the second memory, encrypt it using the data transmission key, and transmit it to the model invoker.
9. A file decryption method, characterized in that, Including: Obtain the predetermined-length confused binary encrypted stream stored in the first memory and the confused binary encrypted stream after intercepting a predetermined number of bytes stored in the second memory, and splice them to obtain a confused binary encrypted stream; According to the forward positioning index number, reverse positioning index number, and intercepting length number in the pre-set second data group, de-confuse the confused binary encrypted stream to obtain a binary encrypted stream; Use the decryption key obtained by the pre-set encryption algorithm to decrypt the binary encrypted stream to obtain a binary confused stream; According to the forward positioning index number, reverse positioning index number, and intercepting length number in the pre-set first data group, de-confuse the binary confused stream to obtain a binary stream; Convert the binary stream into a file.
10. The file decryption method according to claim 9, wherein The de-confusing the binary confused stream according to the forward positioning index number, reverse positioning index number, and intercepting length number in the pre-set first data group to obtain a binary stream includes: Starting from the starting position of the binary confused stream, locate the position of the forward positioning index number, and starting from the position of the forward positioning index number, forwardly intercept the bytes corresponding to the intercepting length number to obtain a binary reverse intercepted stream; Starting from the end position of the binary obfuscated stream, locate the position of the reverse positioning index number. Taking the position of the reverse positioning index number as the starting position, reverse-intercept the bytes corresponding to the intercepted length number to obtain a binary forward-intercepted stream; Swap and restore the binary forward-intercepted stream and the binary reverse-intercepted stream to obtain the binary stream.
11. The file decryption method according to any one of claims 9-10, characterized in that, It further includes: Send a request for the public key of the homomorphic encryption algorithm to the model trainer; Receive the ciphertext of the random number and the public key of the homomorphic encryption algorithm returned by the model trainer in response to the request for the public key of the homomorphic encryption algorithm; Generate a request identifier, blind the request identifier based on the ciphertext of the random number and the public key of the homomorphic encryption algorithm to obtain a blinded ciphertext, and send it to the model trainer; Receive the blinded plaintext and the verification ciphertext returned by the model trainer; the blinded plaintext is obtained by the model trainer decrypting the blinded ciphertext using the pre-generated private key of the homomorphic encryption algorithm; The verification ciphertext is generated by the model trainer based on the first data transmission key, the device parsing identifier, and the parsing timestamp; The first data transmission key is generated based on the blinded plaintext by obtaining the device parsing identifier, the parsing timestamp, and the first parsing random number, and based on the device parsing identifier, the parsing timestamp, the first parsing random number, and the preset key rule; Deblind the blinded plaintext, generate a second data transmission key based on the deblinding result and the key rule, generate a verification ciphertext according to the second data transmission key, and verify the verification ciphertext based on the verification ciphertext. If the verification is successful, use the second data transmission key as the data transmission key to perform data transmission with the model trainer.
12. The file decryption method according to claim 11, characterized in that, The generating the request identifier includes: Obtain the device identifier and the current timestamp; Perform a hash operation on the device identifier and the current timestamp to obtain a hash result; Generate a second random number and a third random number; Concatenate the device identifier, the second random number, the current timestamp, the third random number, and the first four digits of the hash result to obtain the request identifier.
13. The file decryption method according to claim 11, characterized in that, The blinding the request identifier based on the ciphertext of the random number and the public key of the homomorphic encryption algorithm to obtain a blinded ciphertext includes: Use the public key of the homomorphic encryption algorithm to perform homomorphic encryption on the request identifier to obtain an identifier ciphertext; Perform a multiplication operation on the ciphertext of the random number and the identifier ciphertext to obtain the blinded ciphertext.
14. The file decryption method according to claim 11, wherein The generating the verification ciphertext according to the second data transmission key based on the deblinding result and the key rule, and verifying the verification ciphertext based on the verification ciphertext includes: Perform an inverse multiplication operation on the blinded plaintext to obtain a request deblinding identifier and a deblinding random number; Based on the request deblinding identifier, obtain the device deblinding identifier and the deblinding timestamp, and concatenate the first five digits of the device deblinding identifier, the deblinding random number, and the first five digits of the deblinding timestamp to obtain the second data transmission key; Perform a hash operation on the device deblinding identifier and the deblinding timestamp to obtain a deblinding hash result, and use the second data transmission key to encrypt the first four digits of the deblinding hash result to obtain the verification ciphertext; If it is determined that the verification ciphertext is consistent with the validation ciphertext, the verification passes.
15. The file decryption method according to claim 11, characterized in that, Using the second data transmission key as the data transmission key to perform data transmission with the model training party, including: Sending a data acquisition request to the model training party; Receiving the encrypted data sent by the model training party in response to the data acquisition request; Using the data transmission key to decrypt the received encrypted data to obtain a confused binary confused encryption stream of a predetermined length, an encryption key, a first data group, a second data group, and the confused binary confused encryption stream after intercepting a predetermined number of bytes.
16. A file encryption device, characterized in that, Including: A stream conversion module for converting the file to be encrypted into a binary stream; A first confusion module for confusing the binary stream according to the forward positioning index number, reverse positioning index number, and intercepting length number in the pre-set first data group to obtain a binary confused stream; An encryption module for encrypting the binary confused stream using the encryption key obtained by the pre-set encryption algorithm to obtain a binary confused encryption stream; A second confusion module for confusing the binary confused encryption stream according to the forward positioning index number, reverse positioning index number, and intercepting length number in the pre-set second data group to obtain a confused binary confused encryption stream; A separation storage module for intercepting a predetermined number of bytes of the confused binary confused encryption stream and saving it to the first memory, and saving the confused binary confused encryption stream after intercepting a predetermined number of bytes to the second memory.
17. The file encryption device according to claim 16, characterized in that, Further including: A request response module for, in response to the received public key request of the homomorphic encryption algorithm from the model invoker, returning a random number ciphertext and the public key of the homomorphic encryption algorithm to the model invoker; A ciphertext receiving module for receiving the blinded ciphertext sent by the model invoker, where the blinded ciphertext is obtained by blinding the generated request identifier based on the random number ciphertext and the public key of the homomorphic encryption algorithm; A first key generation module for decrypting the blinded ciphertext using the pre-generated private key of the homomorphic encryption algorithm to obtain a blinded plaintext, obtaining a device parsing identifier, a parsing timestamp, and a first parsing random number based on the blinded plaintext, and generating a first data transmission key based on the device parsing identifier, the parsing timestamp, the first parsing random number, and a pre-set key rule; A ciphertext generation module for generating a verification ciphertext based on the first data transmission key, the device parsing identifier, and the parsing timestamp, and returning the blinded plaintext and the verification ciphertext to the model invoker; A first transmission module for, if receiving the message that the verification of the verification ciphertext sent by the model invoker is successful, using the first data transmission key as the data transmission key to perform the file transmission with the model invoker.
18. A file decryption device, characterized in that, Including: A splicing module for obtaining the confused binary confused encryption stream of a predetermined length saved in the first memory and the confused binary confused encryption stream after intercepting a predetermined number of bytes saved in the second memory, and splicing them to obtain a confused binary confused encryption stream; The first de - obfuscation module is used to de - obfuscate the obfuscated binary encrypted stream according to the forward positioning index number, reverse positioning index number, and truncation length number in the pre - set second data group, and obtain the binary encrypted stream; The decryption module is used to decrypt the binary encrypted stream with the decryption key obtained by using the pre - set encryption algorithm, and obtain the binary obfuscated stream; The second de - obfuscation module is used to de - obfuscate the binary obfuscated stream according to the forward positioning index number, reverse positioning index number, and truncation length number in the pre - set first data group, and obtain the binary stream; The file conversion module is used to convert the binary stream into a file.
19. The file decryption device according to claim 18, characterized in that, It further includes: The request sending module is used to send a request for the public key of the homomorphic encryption algorithm to the model training party; The first receiving module is used to receive the ciphertext of the random number and the public key of the homomorphic encryption algorithm returned by the model training party in response to the request for the public key of the homomorphic encryption algorithm; The blinding module is used to generate a request identifier, blind the request identifier based on the ciphertext of the random number and the public key of the homomorphic encryption algorithm to obtain a blinded ciphertext, and send it to the model training party; The second receiving module is used to receive the blinded plaintext and the verification ciphertext returned by the model training party; The blinded plaintext is obtained by the model training party decrypting the blinded ciphertext with the pre - generated private key of the homomorphic encryption algorithm; The verification ciphertext is generated by the model training party according to the first data transmission key, device parsing identifier, and parsing timestamp; The first data transmission key is generated based on the blinded plaintext, obtaining the device parsing identifier, parsing timestamp, and first parsing random number, and is generated based on the device parsing identifier, parsing timestamp, first parsing random number, and the pre - set key rule; The second key generation module is used to un - blind the blinded plaintext, generate a second data transmission key based on the un - blinding result and the key rule, generate a verification ciphertext according to the second data transmission key, and verify the verification ciphertext based on the verification ciphertext. If the verification is successful, it notifies the second transmission module; The second transmission module is used to use the second data transmission key as the data transmission key to perform data transmission with the model training party.
20. A file transmission system, including a model training device and a model calling device; The file encryption device according to any one of claims 16 - 17 is set in the model training device, and is used to perform encrypted data flow on the file to be encrypted; The file decryption device according to any one of claims 18 - 19 is set in the model calling device, and is used to decrypt the encrypted data flow to obtain the decrypted file.
21. A computer storage medium, characterized in that, The computer - readable storage medium stores computer - executable instructions, and when the computer - executable instructions are executed by a processor, they implement the file encryption method according to any one of claims 1 - 8 or the file decryption method according to any one of claims 9 - 16.
22. A computer device, characterized in that, It includes: A memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the program, it implements the file encryption method according to any one of claims 1 - 8 or the file decryption method according to any one of claims 9 - 16.