Data encryption / decryption method and related equipment
By sending encryption/decryption instructions and data separately, the cryptographic machine generates a target key stream and performs encryption/decryption processing after receiving the instructions, which solves the problem of slow response speed in the existing technology and achieves faster encryption/decryption. processing and response.
Patent Information
- Application Number
- CN202411225334.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-03
- Publication Date
- 2024-10-01
Smart Images

Figure CN118740523A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of cryptographic technology, and in particular to a method for encrypting / decrypting data and related equipment. Background Art
[0002] With the continuous development of technology and the continuous accumulation of various data, encryption technology has become increasingly important. In the face of increasing data encryption / decryption requests, how to speed up the encryption or decryption processing so that cryptographic devices (such as cryptographic machine servers, etc.) can respond quickly is an urgent problem to be solved in this field.
[0003] In the related art, the network-based encryption / decryption method usually starts to perform encryption or decryption operations only after receiving complete instructions, keys, initialization vectors, and data to be encrypted or data to be decrypted, resulting in a slow response speed of the cryptographic device to the client. Summary of the invention
[0004] The embodiment of the present application provides a method for encrypting / decrypting data and related equipment. The method for encrypting / decrypting data can speed up the data encryption / decryption processing speed and improve the response speed of the cryptographic device.
[0005] The technical solution of this application is implemented as follows: In a first aspect, a method for encrypting / decrypting data is provided, which is applied to a client and includes: Sending a data encryption / decryption instruction to the cipher machine; the data encryption / decryption instruction does not include the data to be encrypted / decrypted; sending encrypted / decrypted data to the cryptographic machine upon receiving first information fed back by the cryptographic machine based on the data encryption / decryption instruction; the first information is used to indicate that the cryptographic machine has determined the corresponding target key stream based on the data encryption / decryption instruction; the encrypted / decrypted data includes the data to be encrypted / decrypted; The target data fed back by the receiving cipher machine based on the encrypted / decrypted data includes first data obtained after the cipher machine performs encryption / decryption processing on the data to be encrypted / decrypted.
[0006] In a second aspect, another data encryption / decryption method is provided, which is applied to a cryptographic machine, and includes: receiving a data encryption / decryption instruction sent by a client; the data encryption / decryption instruction does not include data to be encrypted / decrypted; Determine the target key stream based on the data encryption / decryption instruction, and send first information to the client; the first information is used to indicate that the cipher machine has determined the corresponding target key stream based on the data encryption / decryption instruction; When receiving the encrypted / decrypted data sent by the client based on the first information, the encrypted / decrypted target data is determined according to the target key stream and the encrypted / decrypted data; the encrypted / decrypted data includes the data to be encrypted / decrypted; the target data includes the data after the encryption / decryption processing is performed on the data to be encrypted / decrypted.
[0007] In a third aspect, a client is provided, including: The first sending module is used to send a data encryption / decryption instruction to the cipher machine; the data encryption / decryption instruction does not include the data to be encrypted / decrypted; A second sending module is used to send encrypted / decrypted data to the cryptographic machine when receiving first information fed back by the cryptographic machine based on the data encryption / decryption instruction; the first information is used to indicate that the cryptographic machine has determined the corresponding target key stream based on the data encryption / decryption instruction, and the encrypted / decrypted data includes the data to be encrypted / decrypted; The first receiving module is used to receive target data fed back by the cryptographic machine based on the encrypted / decrypted data; the target data includes first data obtained after the cryptographic machine encrypts / decrypts the data to be encrypted / decrypted.
[0008] In a fourth aspect, a cryptographic machine is provided, comprising: The second receiving module is used to receive a data encryption / decryption instruction sent by a client; the data encryption / decryption instruction does not include data to be encrypted / decrypted; A first determination module is used to determine a target key stream based on the data encryption / decryption instruction and send first information to the client; the first information is used to indicate that the cryptographic machine has determined the corresponding target key stream based on the data encryption / decryption instruction; The second determination module is used to determine the encrypted / decrypted target data according to the target key stream and the encrypted / decrypted data when receiving the encrypted / decrypted data sent by the client based on the first information; the encrypted / decrypted data includes the data to be encrypted / decrypted, and the target data includes the data after encryption / decryption processing of the data to be encrypted / decrypted.
[0009] In a fifth aspect, a device for encrypting / decrypting data is provided, comprising: a processor and a memory; wherein: A memory for storing computer programs that can be executed on the processor; The processor is used to execute the data encryption / decryption method applied to the client or the data encryption / decryption method applied to the password provided in the embodiment of the present application when running the computer program.
[0010] In an embodiment of the present application, a method for encrypting / decrypting data is provided, comprising: sending a data encryption / decryption instruction to a cryptographic machine; sending encryption / decryption data to the cryptographic machine when receiving first information fed back by the cryptographic machine based on the data encryption / decryption instruction; and receiving target data fed back by the cryptographic machine based on the encryption / decryption data. In this way, by sending the data encryption / decryption instruction and the encryption / decryption data separately to the cryptographic machine, the cryptographic machine can calculate and generate a target key stream according to the data encryption / decryption instruction after receiving the data encryption / decryption instruction, and then when receiving the encryption / decryption data, the encrypted / decrypted target data can be obtained directly based on the key stream and the encryption / decryption data, instead of performing encryption / decryption processing after receiving the data encryption / decryption instruction and the encryption / decryption data, thereby speeding up the data encryption / decryption processing and improving the response speed of the cryptographic machine to the client. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] Figure 1 A flowchart of a method for encrypting / decrypting data provided in an embodiment of the present application; Figure 2 A flowchart of another method for encrypting / decrypting data provided in an embodiment of the present application; Figure 3 A schematic diagram of a data encryption process based on the OFB mode provided in an embodiment of the present application; Figure 4 A schematic diagram of a data decryption process based on the OFB mode provided in an embodiment of the present application; Figure 5 A schematic diagram of a data encryption process based on the CTR mode provided in an embodiment of the present application; Figure 6 A schematic diagram of a data decryption process based on the CTR mode provided in an embodiment of the present application; Figure 7 A flowchart of another method for encrypting / decrypting data provided in an embodiment of the present application; Figure 8 A schematic diagram of the data interaction process of a server cryptographic machine provided in an embodiment of the present application; Fig. 9 A flowchart of a data encryption / decryption method based on instruction and data splitting provided in an embodiment of the present application; Fig.10 A schematic diagram of the storage structure of a hash table corresponding to a key stream provided in an embodiment of the present application; Fig.11 A schematic diagram of the structure of a client provided in an embodiment of the present application; Fig.12 A schematic diagram of the structure of a cryptographic machine provided in an embodiment of the present application; Fig.13 A schematic diagram of the composition structure of a device for encrypting / decrypting data provided in an embodiment of the present application. DETAILED DESCRIPTION
[0012] In order to enable a more detailed understanding of the features and technical contents of the embodiments of the present application, the implementation of the embodiments of the present application is described in detail below in conjunction with the accompanying drawings. The attached drawings are for reference only and are not used to limit the embodiments of the present application.
[0013] In the related art, an efficient parallel Galois Counter Mode (GCM) implementation method provides a parallel GCM module based on a field programmable gate array (FPGA) or an application specific integrated circuit (ASIC), which supports a multiplication core module and multiple encryption / decryption modules; the encryption / decryption module performs packet data encryption / decryption and outputs ciphertext and plaintext; the multiplication core module generates an identification mark T based on the additional information A and the ciphertext C, which is used to indicate whether the message encrypted according to the GCM mode is credible. Multiple encryption / decryption modules perform data encryption / decryption at the same time, and transmit the encryption results to the multiplication core module in turn for generalized hash (GHASH) operation. After the current encryption / decryption module operation result is transmitted, the next round of encryption / decryption operation is immediately performed, and the multiplication core module keeps calculating in a loop when the data is valid. This method still performs encryption / decryption after obtaining the complete key, initialization vector, data to be encrypted or data to be decrypted, etc., and it is difficult to ensure the speed of encryption / decryption.
[0014] Based on the problems in the related art, the present application provides a method for encrypting / decrypting data, which can be used for a client, which is a client that sends data encryption / decryption instructions, such as a personal computer, a smart phone, a tablet computer, etc. Figure 1 As shown, the method includes: S101. Send data encryption / decryption instructions to the cipher machine.
[0015] It should be noted that the data encryption / decryption instruction does not include the data to be encrypted / decrypted, that is, the data encryption / decryption instruction does not include the plaintext to be encrypted or the ciphertext to be decrypted.
[0016] In some embodiments, the data encryption / decryption instruction can be generated by the client when the user has the need to encrypt or decrypt data and triggers the corresponding data encryption or data decryption event (for example, the data encryption event is triggered by the soft switch corresponding to the data encryption, and the data decryption event is triggered by the soft switch corresponding to the data decryption).
[0017] In some embodiments, the data encryption / decryption instruction can be based on key information, initialization information, the length of the key stream and first identification information. The first identification information is used to identify the encryption / decryption task corresponding to the data encryption / decryption instruction. Different first identification information corresponds to different data encryption / decryption instructions.
[0018] S102. Upon receiving the first information fed back by the cryptographic machine based on the data encryption / decryption instruction, send the encrypted / decrypted data to the cryptographic machine.
[0019] In some embodiments, the first information is used to indicate that the cryptographic machine has determined the corresponding target key stream based on the data encryption / decryption instruction; the encrypted / decrypted data includes the data to be encrypted / decrypted.
[0020] In some embodiments, since the data encryption instruction carries key information (initial key), initialization information (initialization vector, initial counter value), key stream length and other information, after receiving the data encryption / decryption instruction, the cipher machine can pre-calculate according to the initial key, initialization vector and key stream length, or pre-calculate according to the initial key, initial counter value and key stream length, thereby obtaining the target key stream. After obtaining the target key stream through pre-calculation, the cipher machine can send the first information to the client.
[0021] In some embodiments, after receiving the first information sent by the cryptographic machine and knowing that the cryptographic machine has completed the pre-calculation process, the client can send encryption / decryption data to the cryptographic machine so that the cryptographic machine can use the target key stream to encrypt / decrypt the data to be encrypted / decrypted in the encryption / decryption data, thereby obtaining the target data.
[0022] S103, receiving the target data fed back by the cipher machine based on the encrypted / decrypted data.
[0023] In some embodiments, the target data includes first data obtained by the cryptographic machine after performing encryption / decryption processing on the data to be encrypted / decrypted. After the cryptographic machine obtains the first data after performing encryption / decryption processing on the data to be encrypted / decrypted, the target data may be generated based on the first data and the corresponding first identification information, wherein the first identification information may be carried in the encryption / decryption data sent by the client to the cryptographic machine.
[0024] In the embodiment of the present application, a data encryption / decryption instruction is sent to the cryptographic machine; when the first information fed back by the cryptographic machine based on the data encryption / decryption instruction is received, encryption / decryption data is sent to the cryptographic machine; and target data fed back by the cryptographic machine based on the encryption / decryption data is received. In this way, by sending the data encryption / decryption instruction and the encryption / decryption data separately to the cryptographic machine, the cryptographic machine can calculate and generate a target key stream according to the data encryption / decryption instruction after receiving the data encryption / decryption instruction, and then when receiving the encryption / decryption data, the encrypted / decrypted target data can be obtained directly based on the key stream and the encryption / decryption data, instead of performing encryption / decryption processing after receiving the data encryption / decryption instruction and the encryption / decryption data, thereby speeding up the data encryption / decryption processing and improving the response speed of the cryptographic machine to the client.
[0025] In some embodiments of the present application, before sending a data encryption / decryption instruction to the cryptographic machine, that is, before the above-mentioned step S101, the following steps S201 to S203 may also be executed, and each step is described below.
[0026] S201. Determine key information, initialization information, and the length of the key stream.
[0027] In some embodiments, the key information may be an initial key key, the initialization information may be an initialization vector or an initialization counter value, and the key information, the initialization information and the length of the key stream may all be freely set by the user.
[0028] S202: Randomly generate first identification information.
[0029] In some embodiments, the first identification information is used to identify the encryption / decryption task corresponding to the data encryption / decryption instruction. The first identification information can be generated while determining the key information, initialization information, and the length of the key stream, or after determining the key information, initialization information, and the length of the key stream.
[0030] In some embodiments, the first identification information generation process includes: loading a dynamic link library; including a random function in the dynamic link library; when it is determined that the dynamic link library has been loaded successfully, calling the random function in the dynamic link library to generate a first random number; and determining the first random number as the first identification information.
[0031] In some embodiments, after determining that a triggering event for generating the first identification information is received, a dynamic link library can be loaded, and the first identification information can be generated by calling a random function in the dynamic link library. By calling the random function in the dynamic link library, the first identification information can be quickly generated, and because the first random number generated by the random function is random, the generated first identification information is more secure.
[0032] S203: Generate a data encryption / decryption instruction based on the key information, the initialization information, the length of the key stream and the first identification information.
[0033] In some embodiments, after the key information is determined, the key information, initialization information, the length of the key stream and the first identification information may be combined to generate a data encryption / decryption instruction.
[0034] In some embodiments, the data encryption / decryption instruction includes data encryption / decryption mode information; if the data encryption / decryption mode information indicates an output feedback mode (Output feedback, OFB), the initialization information is an initialization vector; if the data encryption / decryption mode information indicates a counter mode (Counter, CTR), the initialization information is an initial counter value. The data encryption / decryption mode information can be set by the user.
[0035] It can be understood that by determining the key information, initialization information and the length of the key stream, data for generating the key stream can be obtained, and the first identification information is further randomly generated. Data encryption / decryption instructions are generated based on the first identification information, key information, initialization information and the length of the key stream to facilitate subsequent cryptographic machines to generate corresponding target key streams based on the obtained data encryption / decryption instructions.
[0036] In some embodiments of the present application, the process of generating encrypted / decrypted data can be implemented through the following steps S301 to S302, and each step is described below.
[0037] S301. Determine key information, initialization information, the length of a key stream, and the length of data to be encrypted / decrypted corresponding to first identification information.
[0038] In some embodiments, the length of the data to be encrypted / decrypted can be freely set by the user, and the length of the data to be encrypted / decrypted corresponding to different key information, initialization information, key stream lengths and first identification information can be the same or different.
[0039] S302: Generate encryption / decryption data based on the data to be encrypted / decrypted, the length of the data to be encrypted / decrypted, and the first identification information.
[0040] In some embodiments, after the length of the data to be encrypted / decrypted is determined, the data to be encrypted / decrypted, the length of the data to be encrypted / decrypted and the first identification information may be combined to generate the encrypted / decrypted data.
[0041] In some embodiments, the process of generating encrypted / decrypted data may be performed before sending the data encryption / decryption instruction to the cryptographic machine, i.e., before step S101, or after step S101 and before step S102. In other embodiments, the encrypted / decrypted data may also be generated while generating the data encryption / decryption instruction.
[0042] In some embodiments, since the data encryption / decryption instruction and the encryption / decryption data sent by the client include multiple data, the correspondence between the data encryption / decryption instruction and the encryption / decryption data can be determined through the first identification information.
[0043] In some embodiments of the present application, the target data also includes first identification information. The client can send multiple data encryption / decryption instructions to the cryptographic machine, and correspondingly can also send multiple encryption / decryption data to the cryptographic machine. After receiving the multiple encryption / decryption data, the cryptographic machine can generate target data based on each encryption / decryption data and the corresponding target key stream and send it to the client. The client receives the target data fed back by the cryptographic machine based on the multiple encryption / decryption data; according to the first identification information in each target data, the client determines the first data corresponding to each data to be encrypted / decrypted in each encryption / decryption data.
[0044] In some embodiments, since the target data includes first identification information and first data, after receiving multiple target data, the client can match the first identification information corresponding to different data to be encrypted / decrypted with the first identification information in the target data, thereby determining the first data corresponding to each data to be encrypted / decrypted.
[0045] It can be understood that when the client sends multiple encryption / decryption data to the cryptographic machine, based on the first identification information in the multiple target data fed back by the cryptographic machine, the first data corresponding to different data to be encrypted / decrypted can be quickly and accurately determined.
[0046] The present application provides another method for encrypting / decrypting data, which is applied to a cryptographic machine, such as a cryptographic machine server, etc. Figure 2 As shown, the method includes: S401, receiving a data encryption / decryption instruction sent by a client.
[0047] In some embodiments, the data encryption / decryption instruction may be an instruction sent by the client to indicate that data encryption or decryption is required, and the data encryption / decryption instruction does not include the data to be encrypted / decrypted.
[0048] In some embodiments, within a preset time period, the cryptographic machine may simultaneously receive data encryption / decryption instructions sent by multiple clients, or multiple data encryption / decryption instructions sent by the same client, so that multiple data encryption / decryption instructions can be obtained, which include data encryption instructions and data decryption instructions.
[0049] S402: Determine a target key stream based on the data encryption / decryption instruction, and send first information to the client.
[0050] It should be noted that the target key stream can be a pseudo-random data stream used to encrypt data to be encrypted or decrypt data to be decrypted. The target key stream may include multiple block keys, and different block keys are used to encrypt different blocks of data to be encrypted (plaintext blocks) or to decrypt blocks of data to be decrypted (ciphertext blocks).
[0051] In some embodiments, the encryption instruction carries the key information (initial key) and initialization information (initialization vector, initial counter value) of the data to be encrypted / decrypted. Therefore, after receiving the data encryption / decryption instruction, the cipher machine can pre-calculate based on the initial key and initialization vector, or pre-calculate based on the random number and initial counter value to obtain the target key stream.
[0052] In some embodiments, the first information is used to indicate that the cryptographic machine has determined the corresponding target key stream based on the data encryption / decryption instruction. The first information can be considered as confirmation information of successful pre-computation sent by the cryptographic machine to the client to inform the client that the pre-computation operation has been completed, so that the client can send subsequent data to be encrypted / decrypted.
[0053] S403: When receiving the encrypted / decrypted data sent by the client based on the first information, determine the encrypted / decrypted target data according to the target key stream and the encrypted / decrypted data.
[0054] In some embodiments, the encrypted / decrypted data includes data to be encrypted / decrypted and first identification information. If the cryptographic machine receives encrypted / decrypted data sent by the client, it can use the pre-calculated target key stream to encrypt / decrypt the data to be encrypted / decrypted, thereby obtaining the corresponding encrypted / decrypted data, and then generate the corresponding target data based on the encrypted / decrypted data and the first identification information.
[0055] In an embodiment of the present application, a data encryption / decryption instruction sent by a client is received; a target key stream is determined based on the data encryption / decryption instruction, and a first message is sent to the client; when receiving the encryption / decryption data sent by the client based on the first message, the encrypted / decrypted target data is determined based on the target key stream and the encryption / decryption data. In this way, since the data encryption / decryption instruction arrives before the encryption / decryption data, after receiving the data encryption / decryption instruction, the key stream is calculated and generated based on the data encryption / decryption instruction, and then when receiving the encryption / decryption data, the encrypted / decrypted target data can be obtained directly based on the key stream and the encryption / decryption data, instead of performing encryption / decryption processing after receiving the data encryption / decryption instruction and the encryption / decryption data, thereby speeding up the data encryption / decryption processing and improving the response speed of the cryptographic device to the client.
[0056] In some embodiments of the present application, the data encryption / decryption instructions include key information, initialization information and the length of the key stream. Based on this, the "determining the encrypted / decrypted target data according to the target key stream and the encryption / decryption data" in step S402 can be implemented by the following step S501, which is explained below.
[0057] S501: Generate a target key stream based on key information, initialization information and the length of the key stream.
[0058] In some embodiments, the key information may be an initialization key key, and the initialization information may include an initialization vector or an initial counter value. By parsing the data encryption and decryption instructions, the key information, initialization information, and the length of the key stream of the current encryption and decryption task can be obtained, and then the corresponding target data is determined based on the key information, initialization information, and the length of the key stream.
[0059] In some embodiments, the data encryption / decryption instruction may also include first identification information, and the first identification information is a first random number generated by the client by calling a random function in a dynamic link library. The first identification information is used to identify the encryption / decryption task corresponding to the data encryption / decryption instruction. The first identification information may be a number, symbol, etc. used to identify the encryption / decryption task corresponding to the current data encryption / decryption instruction. The first identification information may be randomly generated by the client. The client sends a data encryption / decryption instruction once, which is regarded as generating an encryption / decryption task. One encryption / decryption task corresponds to one data encryption / decryption instruction and encryption / decryption data. In some embodiments of the present application, before determining the target key stream based on the key information, initialization information, and the length of the key stream, if it is determined that there is a key stream corresponding to the key information, initialization information, and the length of the key stream, the key stream is determined as the target key stream. In some embodiments, after receiving the data encryption / decryption instruction sent by the client and parsing it, if it is determined that a key stream corresponding to the key information, initialization information, and the length of the key stream in the data encryption / decryption instruction is stored in its own storage area, the key stream can be directly determined as the target key stream without the need to pre-calculate based on the key information, initialization information, and the length of the key stream again.
[0060] It is understandable that when it is determined that there is a key stream corresponding to the key information, initialization information and the length of the key stream, the key stream is directly determined as the target key stream, and the pre-calculation process is omitted, thereby further improving the speed of data encryption / decryption.
[0061] In some embodiments, the data encryption / decryption instruction includes encryption / decryption mode information, and the initialization information includes an initialization vector and a random number generated by a counter. If the encryption / decryption mode information indicates that the current encryption / decryption mode is an output feedback mode, a target key stream can be generated based on the key information, the initialization vector and the length of the key stream.
[0062] It should be noted that the OFB mode is a symmetric encryption or decryption mode, and the encryption / decryption mode information may be a name, symbol, etc. used to identify the encryption mode.
[0063] In some embodiments, if the data encryption / decryption instruction indicates that the current encryption / decryption mode is OFB mode, the initialization information in the encryption / decryption instruction corresponds to an initialization vector, and the target key stream can be generated based on the initialization vector, key information and the length of the key stream.
[0064] For example, Figure 3 FIG. 1 is a schematic diagram of a data encryption process based on the OFB mode provided by the present application. Figure 3The solid line box in the figure shows the process of generating a key stream based on an initialization vector (IV) and key information key; Figure 4 FIG. 1 is a schematic diagram of a data decryption process based on the OFB mode provided by the present application. Figure 4 The solid line box in the figure shows the process of generating the key stream based on the initialization vector IV and the key information key. Figure 3 and Figure 4 It can be found that both the data encryption process in OFB mode and the data decryption process in OFB mode generate a key stream based on the initialization vector IV and the key information key.
[0065] In some examples, if the encryption / decryption mode information indicates that the current encryption / decryption mode is the counter mode, a target key stream may be generated based on the key information, the initial counter value, and the length of the key stream.
[0066] In some embodiments, if the data encryption / decryption instruction indicates that the current encryption / decryption mode is the CTR mode, the initialization information in the data encryption / decryption instruction corresponds to the initial counter value generated by the counter, and the target key stream can be generated based on the initial counter value, key information and the length of the key stream.
[0067] For example, Figure 5 FIG. 1 is a schematic diagram of a data encryption process based on the CTR mode provided by the present application. Similar to OFB, CTR converts a block cipher into a stream cipher, and generates a continuous key stream by incrementing a counter. Figure 5 The solid line box shows the process of generating a key stream based on the random number Nonce generated by the counter and the key information key; Figure 6 FIG. 1 is a schematic diagram of a data decryption process based on the CTR mode provided by the present application. Figure 6 The solid line box in the figure shows the process of generating the key stream based on the initial counter value Nonce generated by the counter and the key information key. Figure 5 and Figure 6 It can be found that both the data encryption process in CTR mode and the data decryption process in CTR mode generate a key stream based on the initial counter value Nonce generated by the counter and the key information key.
[0068] It can be understood that the corresponding encryption / decryption mode is determined according to the encryption / decryption mode information in the data encryption / decryption instruction, so that different target key streams can be generated according to the initialization information, key information and key stream length corresponding to different encryption / decryption modes.
[0069] In some embodiments of the present application, if the data encryption / decryption instructions include multiple ones, the target key streams and corresponding first identification information determined based on different data encryption / decryption instructions are stored in different nodes of the hash table.
[0070] In some embodiments, the first identification information corresponding to different data encryption / decryption instructions is different, and the target key streams generated based on different data encryption / decryption instructions are also different. Therefore, different target key streams can be distinguished by the first identification information. After multiple target key streams are determined based on multiple data encryption / decryption instructions, different target key streams and the first identification information in the corresponding data encryption / decryption instructions can be stored in different nodes of the hash table, that is, each node in the hash table includes a target key stream and the corresponding first identification information.
[0071] In some embodiments, the target key stream is stored via a linked list structure. When the length of the target key stream is greater than a preset threshold, the target key stream may be stored via a red-black tree. The preset threshold may be any positive integer, such as 8.
[0072] It can be understood that by storing the target key stream generated by different encryption / decryption instructions and the corresponding first identification information in different nodes of the hash table, it is convenient to uniquely determine the corresponding target key stream according to the different first identification information in the hash table in the subsequent process of generating target data based on the target key stream and the data to be encrypted / decrypted, thereby ensuring the accuracy of data encryption.
[0073] In some embodiments, the encrypted / decrypted data also includes second identification information for identifying the encryption / decryption task corresponding to the encrypted / decrypted data; based on this, in the process of determining the encrypted / decrypted target data according to the key stream and the encrypted / decrypted data, the target first identification information that is the same as the second identification information can be determined from the hash table; based on the target first identification information corresponding to the key stream and the encrypted / decrypted data, the target data is determined.
[0074] In some embodiments, the second identification information can be a number, symbol, etc. used to identify the encryption / decryption task. Both the second identification information and the first identification information can be used to identify the encryption / decryption task. In one encryption / decryption task, the data encryption / decryption requester only sends the data encryption / decryption instruction and the encryption / decryption data once. Therefore, in the same encryption / decryption task, the first identification information in the data encryption / decryption instruction and the second identification information in the encryption / decryption data are the same, that is, they correspond to one encryption / decryption task.
[0075] In some embodiments, after receiving the encrypted / decrypted data sent by the data client, in order to obtain the key stream corresponding to the data to be encrypted / decrypted in the encrypted / decrypted data, the corresponding first identification information can be found from the hash table based on the second identification information in the encrypted / decrypted data, that is, the first identification information that is the same as the current second identification information is determined from the hash table.
[0076] In some embodiments, multiple first identification information in the hash table can be traversed, and the current second identification information can be compared with each first identification information in turn to determine the first identification information that is the same as the current second identification information, and the determined first identification information can be used as the target first identification information.
[0077] In some embodiments, after determining the target first identification information, the target key stream corresponding to the target first identification information can be obtained from the hash table, and the target key stream corresponding to the target first identification information can be used to encrypt and decrypt the data to be encrypted / decrypted in the encryption / decryption data, thereby obtaining the encrypted and decrypted data.
[0078] It can be understood that based on the second identification information in the encrypted / decrypted data, the target first identification information that is identical thereto and the key stream corresponding to the target first identification information can be quickly determined from a pre-established preset storage area. Therefore, even when multiple encrypted / decrypted data are received, the security of data encryption and decryption can be guaranteed.
[0079] In other embodiments, the encrypted / decrypted data also includes a first data length of the data to be encrypted / decrypted; the target first identification information corresponds to multiple key streams; based on this, in the process of determining the target data based on the key stream corresponding to the target first identification information and the encrypted / decrypted data, a target key stream with a data length the same as the first data length can be determined from the multiple key streams corresponding to the target first identification information; based on the target key stream and the encrypted / decrypted data, the target data after encryption / decryption processing is determined.
[0080] In some embodiments, the data lengths of the key streams corresponding to the target first identification information may be different. The data length of the data to be encrypted / decrypted and the data of the key stream need to be consistent. The length of the data to be encrypted / decrypted (first data length) is specified in the encryption / decryption data. Therefore, the target key stream with the same data length as the first data length can be determined from multiple key streams based on the first data length.
[0081] In some embodiments, after determining the target key stream, the target key stream can be used to encrypt the data to be encrypted in the encryption / decryption data to obtain the encrypted data; or the target key stream can be used to decrypt the data to be decrypted in the encryption / decryption data to obtain the decrypted data.
[0082] It can be understood that by determining a target key stream having the same data length as the data length of the data to be encrypted / decrypted in the encrypted / decrypted data from multiple target key streams, the correct target key stream corresponding to the current data to be encrypted / decrypted can be determined to ensure the smooth progress of the encryption / decryption process.
[0083] In some embodiments of the present application, if the received data encryption / decryption instructions include multiple data encryption / decryption instructions, multiple target key streams are generated based on the multiple data encryption / decryption instructions, and each target key stream and the corresponding first identification information are stored in a hash table. If multiple encryption / decryption data are received from the client, the corresponding target key stream is determined from the hash table based on the second identification information in each encrypted / decrypted data; based on each target key stream and the data to be encrypted / decrypted in the corresponding encryption / decryption data, the target data corresponding to each encrypted / decrypted data is generated.
[0084] In some embodiments, multiple encrypted / decrypted data may be sent by the same client or by multiple clients, and each encrypted / decrypted data includes second identification information for identifying the encryption / decryption task corresponding to the encrypted / decrypted data. Therefore, the second identification information in each encrypted / decrypted data and the first identification information in the hash table can be compared in turn to determine the first identification information that is the same as each second identification information, and then determine the target key stream corresponding to each encrypted / decrypted data.
[0085] In some embodiments, after determining the target key streams corresponding to multiple encryption / decryption data, each target key stream can be used to perform encryption or decryption operations on the data to be encrypted / decrypted in the corresponding encryption / decryption data, thereby obtaining the target data corresponding to each encryption / decryption data.
[0086] It can be understood that when multiple encrypted / decrypted data are received, the corresponding target key stream can be quickly obtained from a hash table storing multiple target key streams and the first identification information based on the second identification information in each encrypted / decrypted data, thereby ensuring that the encryption / decryption process of each encrypted / decrypted data can be performed in real time, thereby improving the experience of different users.
[0087] In some embodiments of the present application, the data to be encrypted / decrypted includes data to be encrypted and data to be decrypted, and the target data includes first target data and second target data. Based on this, in the process of determining the encrypted / decrypted target data according to the target key stream and the encrypted / decrypted data, the target key stream can be used to encrypt the data to be encrypted to obtain the first target data, and the target key stream can be used to decrypt the data to be decrypted to obtain the second target data.
[0088] In some embodiments, the first target data may be target data after the data to be encrypted is encrypted. Since the length of the key stream is the same as the length of the data to be encrypted, the key stream and the data to be encrypted may be XORed during the encryption of the data to be encrypted, thereby obtaining the encrypted first target data. In some embodiments, the second target data may be target data after the data to be decrypted is decrypted. During the decryption of the data to be decrypted, the target key stream and the data to be decrypted may also be XORed to obtain the decrypted second target data.
[0089] The present application provides a method for encrypting / decrypting data, which involves an interactive process between a client and a cryptographic machine, such as Figure 7 As shown, the method includes: S701. The client sends data encryption / decryption instructions to the cryptographic machine.
[0090] In some embodiments, the data encryption / decryption instruction does not include the data to be encrypted / decrypted. The data encryption / decryption instruction can be based on key information, initialization information, the length of the key stream and first identification information. The first identification information is used to identify the encryption / decryption task corresponding to the data encryption / decryption instruction. Different first identification information corresponds to different data encryption / decryption instructions.
[0091] S702: Determine a target key stream based on the data encryption / decryption instruction, and send first information to the client.
[0092] In some embodiments, the first information is used to indicate that the cryptographic machine has determined the corresponding target key stream based on the data encryption / decryption instruction. The target key stream may be a pseudo-random data stream used to encrypt data to be encrypted or to decrypt data to be decrypted. The target key stream may include multiple block keys, and different block keys are used to encrypt different blocks (plaintext blocks) of data to be encrypted or to decrypt blocks (ciphertext blocks) of data to be decrypted.
[0093] S703. When the client receives the first information fed back by the cryptographic machine based on the data encryption / decryption instruction, the client sends the encrypted / decrypted data to the cryptographic machine.
[0094] In some embodiments, the first information is used to indicate that the cryptographic machine has determined the corresponding target key stream based on the data encryption / decryption instruction; the encrypted / decrypted data includes the data to be encrypted / decrypted. Since the data encryption instruction carries key information (initial key), initialization information (initialization vector, initial counter value), key stream length and other information, after receiving the data encryption / decryption instruction, the cryptographic machine can pre-calculate based on the initial key, initialization vector and key stream length, or pre-calculate based on the initial key, initial counter value and key stream length to obtain the target key stream. After obtaining the target key stream through pre-calculation, the cryptographic machine can send the first information to the client.
[0095] In some embodiments, after receiving the first information sent by the cryptographic machine and knowing that the cryptographic machine has completed the pre-calculation process, the client can send encryption / decryption data to the cryptographic machine so that the cryptographic machine can use the target key stream to encrypt / decrypt the data to be encrypted / decrypted in the encryption / decryption data, thereby obtaining the target data.
[0096] S704. The cipher machine determines the encrypted / decrypted target data based on the target key stream and the encrypted / decrypted data.
[0097] In some embodiments, the encrypted / decrypted data includes the data to be encrypted / decrypted and the first identification information. If the cryptographic machine receives the encrypted / decrypted data sent by the client, it can use the pre-calculated target key stream to encrypt / decrypt the data to be encrypted / decrypted, thereby obtaining the corresponding encrypted / decrypted data (first data), and then generate the corresponding target data according to the encrypted / decrypted data and the first identification information. After determining the target data, the cryptographic machine can send the target data to the client.
[0098] S705. The client receives the target data fed back by the cryptographic machine based on the encrypted / decrypted data.
[0099] In some embodiments, the target data includes first data obtained by the cryptographic machine after performing encryption / decryption processing on the data to be encrypted / decrypted. After the cryptographic machine obtains the first data after performing encryption / decryption processing on the data to be encrypted / decrypted, the target data may be generated based on the first data and the corresponding first identification information, wherein the first identification information may be carried in the encryption / decryption data sent by the client to the cryptographic machine.
[0100] In the embodiment of the present application, a data encryption / decryption instruction is sent to the cryptographic machine; when the first information fed back by the cryptographic machine based on the data encryption / decryption instruction is received, encryption / decryption data is sent to the cryptographic machine; and target data fed back by the cryptographic machine based on the encryption / decryption data is received. In this way, by sending the data encryption / decryption instruction and the encryption / decryption data separately to the cryptographic machine, the cryptographic machine can calculate and generate a target key stream according to the data encryption / decryption instruction after receiving the data encryption / decryption instruction, and then when receiving the encryption / decryption data, the encrypted / decrypted target data can be obtained directly based on the key stream and the encryption / decryption data, instead of performing encryption / decryption processing after receiving the data encryption / decryption instruction and the encryption / decryption data, thereby speeding up the data encryption / decryption processing and improving the response speed of the cryptographic machine to the client.
[0101] Next, the implementation process of the application embodiment in the actual application scenario is introduced.
[0102] The present application provides a data encryption / decryption method based on instruction and data splitting, which can be applied to a server cryptographic machine, such as Figure 8 As shown, the server cryptographic machine 801 (equivalent to the "cryptographic machine" in other embodiments) can exchange data with the user host 803 (equivalent to the "client" in other embodiments) through the data switch 802. The server cryptographic machine 801 supports users to log in to the cryptographic machine management system through a browser to perform device management, key management and other operations, and can provide the client (user host 803) with the required cryptographic operation services, such as symmetric encryption / decryption, asymmetric encryption and decryption, and signature verification.
[0103] like Fig. 9 As shown, the present application provides a flow chart of a data encryption / decryption method based on instruction and data splitting, the method comprising: S901. Confirm whether the main thread has received a data encryption / decryption request.
[0104] In some embodiments, if it is confirmed that the main thread receives the data encryption / decryption request, the following steps S902 to S906 are executed; otherwise, the process ends. The main thread is mainly responsible for receiving, parsing and responding to the cryptographic operation request. The main thread can be established before receiving the data encryption / decryption request, for example, it can be established after the communication connection is established between the user host 803 and the server cryptographic machine 801.
[0105] S902. Confirm whether the data encryption / decryption request is an encryption / decryption instruction request (equivalent to the “data encryption / decryption instruction” in other embodiments).
[0106] In some embodiments, if it is confirmed that the data encryption / decryption request is an encryption / decryption instruction request, the following steps S903 to S904 are executed; otherwise, the following steps S905 to S906 are executed.
[0107] S903. Perform pre-calculation through a pre-calculation engine to obtain a key stream (equivalent to “generating a key stream based on data encryption / decryption instructions” in other embodiments).
[0108] In some embodiments, when the main thread receives OFB, CTR encryption / decryption instructions, the main thread parses the request and obtains input parameters, which are a unique ID, an initial key key (equivalent to the "key information" in other embodiments), an initialization vector IV_in, and a data length Len. The pre-calculation engine is started, and a key stream with a length of Len is calculated. The result is stored in the memory, and the key stream is identified using a unique ID.
[0109] For example, the server cryptographic machine 801 receives OFB and CTR encryption / decryption instruction information (including unique ID, key, IV_in, data length Len) sent by the user host 803, and the calculation process is as follows: (1) OFB pre-calculation: IV_tmp=IV_in offset=0 while Len>0 key_stream+offset=SM4_Encrypt(key, IV_tmp) IV_tmp=key_stream+offset Len=Len-16 offset=offset+16 Through cyclic calculation, a key stream key_stream with a length of Len can be obtained.
[0110] (2) CTR pre-calculation: IV_tmp=IV_in offset=0 while Len>0 key_stream+offset=SM4_Encrypt(key, IV_tmp) IV_tmp=IV_tmp+1 Len=Len-16 offset=offset+16 Through cyclic calculation, a key stream key_stream with a length of Len can be obtained.
[0111] S904. Store the key stream and the unique identifier (ID) (equivalent to the “first identification information” in other embodiments) in a corresponding manner in a memory (equivalent to the “hash table” in other embodiments).
[0112] In some embodiments, after the key stream is obtained through the computing engine, the unique ID and the key stream can be stored in the memory accordingly, so that after receiving the encryption / decryption data, the corresponding key stream can be read from the memory to perform encryption / decryption operations.
[0113] S905: Determine whether the data encryption / decryption request is a data request (equivalent to “encryption / decryption data” in other embodiments).
[0114] If yes, execute the following step S906; otherwise, continue waiting and return to step S901 to continue execution.
[0115] S906. Read the target key stream from the memory and perform an XOR operation to obtain encrypted / decrypted data (equivalent to the “first data” in other embodiments).
[0116] In some embodiments, when the main thread receives OFB, CTR encryption / decryption data, the main thread parses the request and obtains input parameters, which are a unique ID (equivalent to the "second identification information" in other embodiments), data to be encrypted / decrypted data (equivalent to the "data to be encrypted / decrypted" in other embodiments), and data length Len_data. According to the unique ID, a key stream of Len_data length is taken from the key stream, and XORed with data to obtain a result, which is returned to the user host 803.
[0117] Figure 3 The dashed box in the middle shows the process of obtaining the ciphertext stream by XORing the key stream and the plaintext in OFB mode; Figure 4 The dashed box in the middle shows the process of XORing the key stream and the ciphertext to obtain the plaintext stream in OFB mode; Figure 5 The dashed box in the middle shows the process of XORing the key stream and the plaintext to obtain the ciphertext stream in CTR mode; Figure 6 The dashed box in the middle shows the process of XORing the key stream and the ciphertext to obtain the plaintext stream in CTR mode.
[0118] In some embodiments, the server cryptographic machine 801 can simultaneously receive multiple encryption / decryption instruction information sent by the user host, and can obtain multiple key streams key_stream through pre-calculation, and store each unique ID and the corresponding key stream key_stream. The storage structure is a hash table HashMap, such as Fig.10 As shown, in Fig.10In a node, K is a unique ID, V is a key stream, and the hashcode value is stored in different locations according to the unique ID. If there are multiple values in the same location, they are stored in a linked list structure. If there are more than 8 values in the same location, they are stored in a red-black tree structure.
[0119] In some embodiments, the user host 803 subsequently sends data information including a unique ID. After receiving the data information, the server cryptographic machine 801 reads the corresponding key stream key_stream from the HashMap, performs XOR with the data to be encrypted / decrypted to obtain the encryption / decryption result, and returns it to the user host 803. Through the design of the unique ID and HashMap, the user host 803 can send instructions and data requests to the server cryptographic machine 801 in parallel, and the server cryptographic machine 801 performs parallel operations.
[0120] The data encryption / decryption method based on instruction and data splitting provided by the present application splits the instructions and data in the OFB and CTR encryption operations. After the cipher service receives the encryption and decryption instructions of the OFB and CTR modes, it can start an independent process for pre-calculation, thereby achieving the OFB and CTR encryption acceleration goals. After receiving the data, the encryption and decryption operations can be completed after XORing with the pre-calculated results. Among them, the OFB and CTR pre-calculation engines generate key streams according to the instructions, and the main thread is responsible for the XOR operation. The present application has made improvements to the encryption operations of the symmetric algorithms OFB and CTR modes, thereby improving their response speed and computing performance.
[0121] This application can accelerate and optimize the encryption / decryption operations of the symmetric algorithm OFB and CTR mode, improve the interface response speed, and optimize the user experience of the product without affecting the product presentation of the server cryptographic machine and complying with the standard specification interface definition.
[0122] The present application also provides a client, Fig.11 A schematic diagram of the structure of a client provided in an embodiment of the present application is shown in FIG. Fig.11 As shown, the device 10 for encrypting / decrypting data includes: The first sending module 11 is used to send a data encryption / decryption instruction to the cipher machine; the data encryption / decryption instruction does not include the data to be encrypted / decrypted; A second sending module 12 is used to send encrypted / decrypted data to the cryptographic machine when receiving first information fed back by the cryptographic machine based on the data encryption / decryption instruction; the first information is used to indicate that the cryptographic machine has determined the corresponding target key stream based on the data encryption / decryption instruction, and the encrypted / decrypted data includes the data to be encrypted / decrypted; The first receiving module 13 is used to receive the target data fed back by the cryptographic machine based on the encryption / decryption data; the target data includes the first data obtained after the cryptographic machine encrypts / decrypts the data to be encrypted / decrypted. It should be noted that the description of the client of the embodiment of the present application is similar to the description of the method embodiment of encryption / decryption data applied to the client, and has similar beneficial effects as the method embodiment, so it will not be repeated. For the technical details not disclosed in this embodiment, please refer to the description of the method embodiment of this application for understanding.
[0123] In some embodiments, the device 10 for encrypting / decrypting data further comprises: A first information determination module, used to determine key information, initialization information and the length of the key stream; An identification information generation module, used to randomly generate first identification information; the first identification information is used to identify the encryption / decryption task corresponding to the data encryption / decryption instruction; An instruction generation module is used to generate the data encryption / decryption instruction based on the key information, the initialization information, the length of the key stream and the first identification information.
[0124] In some embodiments, the identification information generation module is also used to load a dynamic link library; the dynamic link library includes a random function; when it is determined that the dynamic link library is loaded successfully, the random function in the dynamic link library is called to generate a first random number; and the first random number is determined as the first identification information.
[0125] In some embodiments, the data encryption / decryption instruction includes data encryption / decryption mode information; if the data encryption / decryption mode information indicates an output feedback mode, the initialization information is an initialization vector; if the data encryption / decryption mode information indicates a counter mode, the initialization information is an initial counter value.
[0126] In some embodiments, the device 10 for encrypting / decrypting data further comprises: A second information determination module, used to determine the key information, the initialization information, the length of the key stream and the length of the data to be encrypted / decrypted corresponding to the first identification information; The encryption / decryption data generation module is used to generate the encryption / decryption data based on the data to be encrypted / decrypted, the length of the data to be encrypted / decrypted and the first identification information.
[0127] In some embodiments, the target data also includes the first identification information; the first receiving module 13 is also used to receive target data fed back by the cryptographic machine based on multiple encryption / decryption data when multiple encryption / decryption data are sent to the cryptographic machine; and determine the first data corresponding to each data to be encrypted / decrypted in each encryption / decryption data according to the first identification information in each target data.
[0128] The present application also provides a cryptographic machine, Fig.12 A schematic diagram of the composition structure of a cryptographic machine provided in an embodiment of the present application is shown in FIG. Fig.12 As shown, the cryptographic machine 20 includes: The second receiving module 21 is used to receive a data encryption / decryption instruction sent by a client; the data encryption / decryption instruction does not include data to be encrypted / decrypted; A first determination module 22, configured to determine a target key stream based on the data encryption / decryption instruction and send first information to the client; the first information is used to indicate that the cryptographic machine has determined the corresponding target key stream based on the data encryption / decryption instruction; The second determination module 23 is used to determine the encrypted / decrypted target data according to the target key stream and the encrypted / decrypted data when receiving the encrypted / decrypted data sent by the client based on the first information; the encrypted / decrypted data includes the data to be encrypted / decrypted, and the target data includes the data after encryption / decryption processing of the data to be encrypted / decrypted.
[0129] In some embodiments, the data encryption / decryption instruction includes key information, initialization information and the length of the key stream; the first determination module 22 includes: The first generating submodule is used to generate the target key stream based on the key information, the initialization information and the length of the key stream.
[0130] In some embodiments, the first determining module 22 further includes: The second generating submodule is used to determine the key stream as the target key stream if it is determined that there is a key stream corresponding to the key information, the initialization information and the length of the key stream before determining the target key stream based on the key information, the initialization information and the length of the key stream.
[0131] In some embodiments, the data encryption / decryption instruction includes first identification information for identifying the encryption / decryption task corresponding to the data encryption / decryption instruction; the first identification information is a first random number generated by the client by calling a random function in a dynamic link library.
[0132] In some embodiments, the cryptographic machine 20 further includes: A storage module, configured to store target key streams and corresponding first identification information determined based on different data encryption / decryption instructions in different nodes of a hash table if the data encryption / decryption instructions include multiple ones; Among them, the first identification information corresponding to different data encryption / decryption instructions is different, each node in the hash table includes a target key stream and corresponding first identification information, and the target key stream is stored through a linked list structure; when the length of the target key stream is greater than a preset threshold, the target key stream is stored through a red-black tree.
[0133] It should be noted that the description of the cryptographic machine in the embodiment of the present application is similar to the description of the method embodiment for encrypting / decrypting data applied to the cryptographic machine, and has similar beneficial effects as the method embodiment, so it is not described in detail. For technical details not disclosed in this embodiment, please refer to the description of the method embodiment of the present application for understanding.
[0134] Accordingly, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the method for encrypting / decrypting data applied to a client or the method for encrypting / decrypting data applied to a cryptographic machine provided in the above-mentioned embodiment is implemented.
[0135] It should be noted that in the embodiments of the present application, if the above-mentioned method of encrypting / decrypting data is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application can be essentially or the part that contributes to the relevant solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a U disk, a mobile hard disk, a read-only memory (ROM), a disk or an optical disk. In this way, the embodiments of the present application are not limited to any specific combination of hardware and software.
[0136] The present application also provides a device for encrypting / decrypting data. Fig.13 A schematic diagram of the structure of a device for encrypting / decrypting data provided in an embodiment of the present application is shown in FIG. Fig.13As shown, the device 30 for encrypting / decrypting data includes: a memory 31, a processor 32, a communication interface 33 and a communication bus 34. The memory 31 is used to store instructions that can be executed to encrypt / decrypt data. The processor 32 is used to execute the instructions that can be executed to encrypt / decrypt data stored in the memory to implement the method for encrypting / decrypting data applied to the client or the method for encrypting / decrypting data applied to the cryptographic machine provided in the above embodiment.
[0137] It should be noted that, in this article, the term "comprises" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises at least one ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0138] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0139] The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units; they may be located in one place or distributed on multiple network units; some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0140] In addition, all functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may be a separate unit, or two or more units may be integrated into one unit; the above-mentioned integrated units may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0141] A person of ordinary skill in the art can understand that: all or part of the steps of implementing the above-mentioned method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above-mentioned method embodiment; and the aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROM, disks or optical disks.
[0142] Alternatively, if the above-mentioned integrated unit of the present application is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application can essentially or in other words, the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a product to execute all or part of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROMs, magnetic disks or optical disks.
[0143] The above is only an implementation method of the present application, but the protection scope of the present application is not limited thereto. Any technical object familiar with the technical field can easily think of changes or replacements within the technical scope disclosed in the present application, which should be covered by the protection scope of the present application.
Claims
1. A data encryption / decryption method, applied to a client, characterized in that: include: Sending a data encryption / decryption instruction to the cipher machine; the data encryption / decryption instruction does not include the data to be encrypted / decrypted; Upon receiving first information fed back by the cryptographic machine based on the data encryption / decryption instruction, sending encrypted / decrypted data to the cryptographic machine; the first information is used to indicate that the cryptographic machine has determined the corresponding target key stream based on the data encryption / decryption instruction; the encrypted / decrypted data includes the data to be encrypted / decrypted; Receive target data fed back by the cryptographic machine based on the encrypted / decrypted data; the target data includes first data obtained after the cryptographic machine performs encryption / decryption processing on the data to be encrypted / decrypted.
2. The method according to claim 1, characterized in that The method further comprises: Determine the key information, initialization information and the length of the key stream; Randomly generate first identification information; the first identification information is used to identify the encryption / decryption task corresponding to the data encryption / decryption instruction; The data encryption / decryption instruction is generated based on the key information, the initialization information, the length of the key stream and the first identification information.
3. The method according to claim 2, characterized in that The method for generating the first identification information includes: Loading a dynamic link library; the dynamic link library includes a random function; In the case where it is determined that the dynamic link library is loaded successfully, calling a random function in the dynamic link library to generate a first random number; The first random number is determined as the first identification information.
4. The method according to claim 2, characterized in that: The data encryption / decryption instruction includes data encryption / decryption mode information; if the data encryption / decryption mode information indicates an output feedback mode, the initialization information is an initialization vector; If the data encryption / decryption mode information indicates a counter mode, the initialization information is an initial counter value.
5. The method according to claim 2, characterized in that: Also includes: Determine the key information, the initialization information, the length of the key stream, and the length of the data to be encrypted / decrypted corresponding to the first identification information; The encrypted / decrypted data is generated based on the data to be encrypted / decrypted, the length of the data to be encrypted / decrypted, and the first identification information.
6. The method according to claim 5, characterized in that The target data also includes the first identification information; and the method further includes: In the case where a plurality of encryption / decryption data are sent to the cryptographic machine, receiving target data fed back by the cryptographic machine based on the plurality of encryption / decryption data; According to the first identification information in each target data, first data corresponding to each data to be encrypted / decrypted in each encrypted / decrypted data is determined.
7. A method for data encryption / decryption, applied to a cryptographic machine, characterized in that: include: Receiving a data encryption / decryption instruction sent by a client; the data encryption / decryption instruction does not include data to be encrypted / decrypted; Determine a target key stream based on the data encryption / decryption instruction, and send first information to the client; The first information is used to indicate that the cryptographic machine has determined the corresponding target key stream based on the data encryption / decryption instruction; When receiving the encrypted / decrypted data sent by the client based on the first information, the encrypted / decrypted target data is determined according to the target key stream and the encrypted / decrypted data; the encrypted / decrypted data includes the data to be encrypted / decrypted; and the target data includes the data after encryption / decryption processing of the data to be encrypted / decrypted.
8. The method according to claim 7, characterized in that The data encryption / decryption instruction includes key information, initialization information and the length of the key stream; The step of determining a target key stream based on the data encryption / decryption instruction comprises: The target key stream is generated based on the key information, the initialization information and the length of the key stream.
9. The method according to claim 8, characterized in that Before determining the target key stream based on the key information, the initialization information and the length of the key stream, the method further includes: If it is determined that there is a key stream corresponding to the key information, the initialization information, and the length of the key stream, the key stream is determined as a target key stream.
10. The method according to claim 7, characterized in that The data encryption / decryption instruction includes first identification information for identifying the encryption / decryption task corresponding to the data encryption / decryption instruction; the first identification information is a first random number generated by the client by calling a random function in a dynamic link library.
11. The method according to claim 10, characterized in that The method further comprises: If the data encryption / decryption instructions include multiple ones, storing the target key streams and corresponding first identification information determined based on different data encryption / decryption instructions into different nodes of the hash table; Among them, the first identification information corresponding to different data encryption / decryption instructions is different, each node in the hash table includes a target key stream and corresponding first identification information, and the target key stream is stored through a linked list structure; when the length of the target key stream is greater than a preset threshold, the target key stream is stored through a red-black tree.
12. A client, characterized in that: include: A first sending module, used for sending data encryption / decryption instructions to the cipher machine; The data encryption / decryption instruction does not include the data to be encrypted / decrypted; A second sending module is used to send encrypted / decrypted data to the cryptographic machine when receiving the first information fed back by the cryptographic machine based on the data encryption / decryption instruction; The first information is used to indicate that the cryptographic machine has determined the corresponding target key stream based on the data encryption / decryption instruction, and the encrypted / decrypted data includes the data to be encrypted / decrypted; The first receiving module is used to receive target data fed back by the cryptographic machine based on the encryption / decryption data; the target data includes first data obtained after the cryptographic machine performs encryption / decryption processing on the data to be encrypted / decrypted.
13. A cryptographic machine, characterized in that: include: A second receiving module, used for receiving a data encryption / decryption instruction sent by a client; The data encryption / decryption instruction does not include the data to be encrypted / decrypted; A first determination module, configured to determine a target key stream based on the data encryption / decryption instruction and send first information to the client; The first information is used to indicate that the cryptographic machine has determined the corresponding target key stream based on the data encryption / decryption instruction; The second determination module is used to determine the encrypted / decrypted target data according to the target key stream and the encrypted / decrypted data when receiving the encrypted / decrypted data sent by the client based on the first information; the encrypted / decrypted data includes the data to be encrypted / decrypted, and the target data includes the data after encryption / decryption processing of the data to be encrypted / decrypted.
14. A device for encrypting / decrypting data, characterized in that: include: processor and memory; wherein, The memory is used to store a computer program that can be run on the processor; The processor is configured to execute the method according to any one of claims 1 to 6 or claims 7 to 11 when running the computer program.
Citation Information
Patent Citations
Data high-speed encryption and decryption method and device based on symmetric cryptographic algorithm
CN111464564A
Secret key processing method and device and electronic device
CN113572611A
