A data encryption method, a data decryption method and a device, and a storage medium
By performing sub-packet cutting and exclusive-OR encryption on high-frequency data, the problem of insufficient security in existing encryption algorithms when processing high-frequency data is solved, and efficient and secure data encryption and decryption processing is achieved.
Patent Information
- Application Number
- CN202210908667.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-29
- Publication Date
- 2024-12-24
- Estimated Expiration
- 2042-07-29
AI Technical Summary
Existing encryption algorithms sacrifice security in order to ensure performance when processing high-frequency data. The massive characteristics of difficult to effectively process high-frequency data pose severe challenges to real-time data communication and historical data storage encryption.
By cutting the data packet to be encrypted into two adjacent sub-data packets, using one of the sub-data packets as encryption keys to perform XOR operation on the other sub-data packets, obtaining the encrypted sub-data packets and splicing them to form the final encryption The same is true for data packets when decrypting, using compressed high-entropy density data to improve security.
It realizes the security of data encryption while ensuring encryption speed and efficiency. It is suitable for real-time communication and historical storage scenarios, significantly improving the encryption and decryption performance.
Smart Images

Figure CN115051790B_ABST
Abstract
Description
Technical Field
[0001] The technical solution disclosed herein relates to the field of data processing technology, and in particular to a data encryption method, a data decryption method and device, and a storage medium. Background Art
[0002] The high-frequency data generated by various industrial equipment that require real-time monitoring during operation, including wind turbines, are of great value for condition monitoring, online diagnosis and offline analysis.
[0003] However, the massive nature of high-frequency data poses a severe challenge to the communication encryption of real-time data and the storage encryption of historical data. At present, commonly used symmetric encryption algorithms include RC4, DES, and AES, and commonly used asymmetric encryption algorithms include RSA and ECC. However, these commonly used encryption algorithms usually sacrifice a certain degree of security in order to ensure performance when processing high-frequency data. Summary of the invention
[0004] In view of this, the embodiments of the present disclosure provide a data encryption method, a data decryption method and device, and a storage medium.
[0005] According to a first aspect of the present disclosure, a data encryption method and a data decryption method are proposed, wherein the data encryption method comprises:
[0006] Cutting the data packet to be encrypted to obtain at least two sub-data packets, wherein the at least two sub-data packets include: a first sub-data packet and a second sub-data packet that are adjacent to each other; and the second sub-data packet is located after the first sub-data packet;
[0007] Encrypting the at least two sub-data packets respectively to obtain encrypted sub-data packets corresponding to the sub-data packets, including: using the first sub-data packet as an encryption key, and using the encryption key to perform encryption operation on the second sub-data packet to obtain an encrypted sub-data packet corresponding to the second sub-data packet;
[0008] The encrypted sub-data packets corresponding to the sub-data packets are concatenated to obtain an encrypted data packet corresponding to the data packet to be encrypted.
[0009] The data decryption method comprises:
[0010] Cutting the encrypted data packet to obtain at least two sub-data packets, wherein the at least two sub-data packets include: a first sub-data packet to be decrypted and a second sub-data packet to be decrypted, which are adjacent to each other; and the second sub-data packet to be decrypted is located after the first sub-data packet to be decrypted;
[0011] Decrypting the at least two sub-data packets respectively to obtain decrypted sub-data packets corresponding to the respective sub-data packets, including: using the decrypted sub-data packet obtained after decrypting the first sub-data packet to be decrypted as a decryption key, and using the decryption key to perform a decryption operation on the second sub-data packet to be decrypted to obtain a decrypted sub-data packet corresponding to the second sub-data packet to be decrypted;
[0012] The decrypted sub-data packets corresponding to the sub-data packets are concatenated to obtain the decrypted data packet corresponding to the encrypted data packet.
[0013] According to a second aspect of the present disclosure, a data encryption device and a data decryption device are proposed, wherein the data encryption device comprises:
[0014] A data packet cutting module to be encrypted, used for cutting the data packet to be encrypted to obtain at least two sub-data packets, wherein the at least two sub-data packets include: a first sub-data packet and a second sub-data packet that are adjacent to each other; and the second sub-data packet is located after the first sub-data packet;
[0015] an encryption module, configured to perform encryption processing on the at least two sub-data packets respectively to obtain encrypted sub-data packets corresponding to the respective sub-data packets, including: using the first sub-data packet as an encryption key, and performing encryption operation on the second sub-data packet using the encryption key to obtain an encrypted sub-data packet corresponding to the second sub-data packet;
[0016] The encrypted sub-data packet splicing module is used to splice the encrypted sub-data packets corresponding to the sub-data packets to obtain an encrypted data packet corresponding to the data packet to be encrypted.
[0017] The data decryption device comprises:
[0018] An encrypted data packet cutting module is used to cut the encrypted data packet to obtain at least two sub-data packets, wherein the at least two sub-data packets include: a first sub-data packet to be decrypted and a second sub-data packet to be decrypted that are adjacent to each other; and the second sub-data packet to be decrypted is located after the first sub-data packet to be decrypted;
[0019] a decryption module, configured to perform decryption processing on the at least two sub-data packets respectively to obtain decrypted sub-data packets corresponding to each sub-data packet, including: using the decrypted sub-data packet obtained after decrypting the first sub-data packet to be decrypted as a decryption key, and using the decryption key to perform a decryption operation on the second sub-data packet to be decrypted to obtain a decrypted sub-data packet corresponding to the second sub-data packet to be decrypted;
[0020] The decrypted sub-data packet splicing module is used to splice the decrypted sub-data packets corresponding to the sub-data packets to obtain the decrypted data packet corresponding to the encrypted data packet.
[0021] According to a third aspect of the present disclosure, a computer-readable storage medium is provided, wherein the machine-readable storage medium stores machine-readable instructions, and when the machine-readable instructions are called and executed by a processor, the processor is prompted to implement the data encryption method and the data decryption method of any embodiment of the present disclosure.
[0022] According to a fourth aspect of the present disclosure, there is provided an electronic device, comprising:
[0023] processor;
[0024] a memory for storing processor-executable instructions;
[0025] The processor is configured to execute the data encryption method and the data decryption method of any embodiment of the present disclosure.
[0026] The technical solution provided by the embodiments of the present disclosure may have the following beneficial effects:
[0027] The data encryption method and data decryption method provided by the embodiments of the present disclosure use the first sub-data packet as a key to encrypt and decrypt the second sub-data packet. Since each sub-data packet is a data packet with a high entropy density after compression, it has good security.
[0028] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0030] Figure 1 is a flow chart of a data encryption method according to an exemplary embodiment of the present disclosure;
[0031] Figure 2 is a schematic diagram of performance test results of a data encryption method shown in an exemplary embodiment of the present disclosure;
[0032] Figure 3 is a flow chart of another data encryption method according to an exemplary embodiment of the present disclosure;
[0033] Figure 4 is a flow chart of a data decryption method according to an exemplary embodiment of the present disclosure;
[0034] Figure 5 is a structural schematic diagram of a data encryption device according to an exemplary embodiment of the present disclosure;
[0035] Figure 6 is a structural schematic diagram of a data decryption device according to an exemplary embodiment of the present disclosure;
[0036] Figure 7 It is a schematic structural diagram of an electronic device according to an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION
[0037] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0038] The terms used in this disclosure are for the purpose of describing specific embodiments only and are not intended to limit the disclosure. The singular forms of "a", "said" and "the" used in this disclosure and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0039] It should be understood that although the terms first, second, third, etc. may be used in the present disclosure to describe various information, such information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of the present disclosure, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0040] The data encryption method and the data decryption method of the embodiments of the present disclosure are described in detail below in conjunction with the accompanying drawings.
[0041] Figure 1 FIG. 1 is a flow chart of a data encryption method according to an exemplary embodiment of the present disclosure. The data encryption method is used to encrypt a data packet to be encrypted. Figure 1 As shown, the exemplary embodiment method may include the following steps:
[0042] Step S101, cutting the data packet to be encrypted to obtain at least two sub-data packets.
[0043] The data packet to be encrypted is a compressed data packet. The at least two sub-data packets include: a first sub-data packet and a second sub-data packet that are adjacent to each other; and the second sub-data packet is located after the first sub-data packet.
[0044] For example, assuming that after the data packet to be encrypted is cut, 6 sub-data packets are obtained, namely: Z1, Z2, Z3...Z6, then any two adjacent sub-data packets can be called the first sub-data packet and the second sub-data packet. For example, sub-data packet Z1 is called the first sub-data packet, sub-data packet Z2 is called the second sub-data packet, and Z2 is located after Z1. The "after" can be a sequence that represents the timing of cutting. For example, in the cutting process, Z1 is obtained first, and then Z2. For another example, among the above 6 sub-data packets, Z4 and Z5, Z4 can be called the first sub-data packet, and Z5 can be called the second sub-data packet.
[0045] On the one hand, compression can reduce the amount of data in the data packet to be encrypted, thereby reducing the amount of data to be encrypted and speeding up the encryption. On the other hand, compression can increase the entropy density of the data packet to be encrypted. The smaller the compression, the greater the entropy density, and the more disordered the data in the data packet to be encrypted, so that the data in the data packet to be encrypted with high entropy density after compression can be used as the key.
[0046] Step S102, encrypting the at least two sub-data packets respectively to obtain encrypted sub-data packets corresponding to each sub-data packet, including: using the first sub-data packet as an encryption key, and using the encryption key to perform encryption operation on the second sub-data packet to obtain an encrypted sub-data packet corresponding to the second sub-data packet.
[0047] In an optional example, the first sub-data packet may be used as an encryption key, and an XOR operation may be performed on the encryption key and the second sub-data packet to obtain an encrypted sub-data packet corresponding to the second sub-data packet.
[0048] It should be noted that the encryption operation on the second sub-data packet may also be performed using the encryption key in other ways, not limited to the above-mentioned XOR operation, and the present disclosure does not limit this.
[0049] The data encryption method of the present invention is described in detail below using the XOR operation as an example.
[0050] The exclusive OR (xor) operation is also called a half-addition operation, and its operation rules are equivalent to binary addition without carry. In binary, 1 represents true and 0 represents false, so the exclusive OR operation rules are: 0⊕0=0, 1⊕0=1, 0⊕1=1, 1⊕1=0 (the same is 0, different is 1), these rules are the same as addition, but without carry, so the exclusive OR operation is often regarded as a carry-free addition operation.
[0051] The data encryption method of this step is described by taking the following as an example. The encryption method can be applied between any two of the first sub-data packets and the second sub-data packets obtained by cutting the data packet to be encrypted:
[0052] For example: the first sub-packet obtained through the above step S101 is 0010, and the second sub-packet is 1011. The data encryption method of this step will use the first sub-packet 0010 as the encryption key, and perform an XOR operation on the corresponding position of the encryption key and the corresponding position of the second sub-packet 1011, and the result is 1001. The 1001 is the encrypted sub-packet corresponding to the second sub-packet 1011.
[0053] For another example, the sub-data packets obtained through the above step S101 may include: 0010, 1011 and 0001, wherein 0010 may be referred to as the first sub-data packet, and 1011 may be referred to as the second sub-data packet. Then, the first sub-data packet 0010 may be used as an encryption key, and the corresponding position of the encryption key may be XORed with the corresponding position of the second sub-data packet 1011 to obtain the encrypted sub-data packet 1001 corresponding to the second sub-data packet 1011. Next, for the two sub-data packets 1011 and 0001, 1011 may be referred to as the first sub-data packet, and 0001 may be referred to as the second sub-data packet, and the first sub-data packet 1011 may be used as an encryption key, and the corresponding position of the encryption key may be XORed with the corresponding position of the second sub-data packet 0001 to obtain the encrypted sub-data packet 1010 corresponding to 0001.
[0054] It should be noted that the description of the sub-data packets 0010, 1011, etc. in the above examples is merely exemplary. In actual applications, the length of each sub-data packet obtained by cutting the data packet to be encrypted can be much larger than the length in the above examples.
[0055] In an optional example, before encrypting the at least two sub-data packets to obtain encrypted sub-data packets corresponding to each sub-data packet, an initial key may be randomly generated, and then the first sub-data packet in the at least two sub-data packets is encrypted using the initial key to obtain an encrypted sub-data packet corresponding to the first sub-data packet. The first sub-data packet is the first sub-data packet in the at least two sub-data packets to be encrypted.
[0056] The initial key may be randomly generated based on actual usage. For example, it may be randomly generated using a hash algorithm based on the current system startup seconds and the current CPU utilization. For another example, it may be randomly generated using a hash algorithm based on the current encryption time and the current CPU utilization. The present disclosure does not specifically limit the method for randomly generating the initial key.
[0057] Let’s continue with the above example:
[0058] The first sub-packet obtained through the above step S101 is 0010, and the randomly generated initial key is 1100. Then, the first sub-packet in the at least two sub-packets, that is, the first sub-packet 0010, is encrypted by the initial key, and the encrypted sub-packet corresponding to the first sub-packet is 1110.
[0059] In an optional example, the at least two sub-data packets may be reversed before the encryption process to increase the difficulty of cracking and improve the security of encryption. In this case, the third sub-data packet 0001 in the above example needs to be encrypted using the initial key 1100. In this case, the third sub-data packet is the first sub-data packet.
[0060] In this example, when the current application scenario is a real-time communication scenario, the randomly generated initial key can be encrypted with the peer public key and then written into the communication header, that is, the initial key can only be obtained using the peer private key. The encryption method used here is a commonly used asymmetric encryption method, which can be implemented using existing technology and will not be described in detail. When the current application scenario is a historical data storage scenario, since the user encrypts and decrypts the data himself, it is only necessary to place the initial key in a "safe". When the user needs to decrypt the data packet, the initial key can be obtained from the "safe" using the password set by the user.
[0061] In an optional example, before the data packet to be encrypted is cut to obtain at least two sub-data packets, the key length of the initial key may be determined, and the initial key may be randomly generated based on the key length.
[0062] The longer the key length of the initial key is, the higher the security is and the lower the possibility of being cracked is. In actual applications, it is found that when the key length is longer than 256 bits, it has better security.
[0063] The key length of the initial key can be selected according to the actual application scenario. Specifically, when the information in the data packet to be encrypted in the current application scenario is top secret information, a longer key length can be selected, for example, 512 bits. When the information in the data packet to be encrypted in the current application scenario is ordinary secret information, a relatively short key length can be selected, for example, 256 bits. The importance of the top secret information is higher than that of the ordinary secret information.
[0064] Alternatively, when the current data packet to be encrypted contains real-time communication data, a relatively short key length may be selected to facilitate fast communication, and when the current data packet to be encrypted contains historical storage data, a longer key length may be selected to better ensure the security of the entire historical storage data.
[0065] Optionally, a longer key length may be selected during encryption processing to better ensure encryption security. This disclosure does not make specific limitations on this.
[0066] Furthermore, the data packet to be encrypted can be cut according to the key length of the initial key to obtain at least two sub-data packets, wherein the length of one or zero sub-data packets among the at least two sub-data packets is less than the key length, and the length of the other sub-data packets is equal to the key length.
[0067] For example, if the length of the randomly generated initial key is L, and the length of the data packet to be encrypted is 3L-1, the data packet to be encrypted is cut according to the key length L, and the lengths of the at least two sub-data packets obtained are L, L, and L-1 respectively. At this time, when encrypting the sub-data packet with a length of L-1, the first L-1 bits of the previous data packet to be encrypted can be intercepted as the encryption key.
[0068] For another example, the key length of the randomly generated initial key is L, and the length of the data packet to be encrypted is 5L. Then, the data packet to be encrypted is cut according to the key length L, and the lengths of the at least two sub-data packets obtained are both L.
[0069] From the data encryption method of this step, we can know that in this example, the sum of the key lengths of the encryption keys corresponding to each sub-data packet is equal to the length of the data packet to be encrypted, and Shannon, the founder of information science, has proved that XOR encryption with a random key not less than the length of the plaintext cannot be cracked. Therefore, the data encryption method of the disclosed embodiment has good security.
[0070] Step S103, concatenating the encrypted sub-data packets corresponding to the sub-data packets to obtain an encrypted data packet corresponding to the data packet to be encrypted.
[0071] Let’s continue with the above example:
[0072] The encrypted sub-packet 1110 corresponding to the first sub-packet, the encrypted sub-packet 1001 corresponding to the second sub-packet, and the encrypted sub-packet 1010 corresponding to the third sub-packet can be concatenated to obtain an encrypted data packet 111010011010 corresponding to the data packet to be encrypted.
[0073] Figure 2 This is a schematic diagram of the performance test results of the data encryption method and the subsequent data decryption method in the technical solution of the present disclosure. In this schematic diagram, the vertical axis is time. Figure 2 It can be seen that the technical solution disclosed in the present invention is significantly faster than the other two common data encryption methods and data decryption methods.
[0074] The data encryption method provided by the embodiment of the present disclosure uses the previous sub-data packet as an encryption key, and performs an XOR operation on the encryption key and the next sub-data packet to obtain an encrypted sub-data packet corresponding to the next sub-data packet. Since each sub-data packet is a data packet with a high entropy density after compression, it has good encryption security. At the same time, the data encryption method provided by the embodiment of the present disclosure uses an XOR operation to encrypt the data packet, the algorithm is simple, the encryption speed is fast, and the encryption efficiency is high.
[0075] Figure 3 It is a flowchart of another data encryption method according to an exemplary embodiment of the present disclosure.
[0076] In the description of this embodiment, the same steps as those in any of the above embodiments will be briefly described without further details. For details, please refer to any of the above embodiments. In this embodiment, a compressed data packet of the historical storage data of the wind turbine every day is used as the data packet to be encrypted for detailed description. Figure 3 As shown, the exemplary embodiment method may include the following steps:
[0077] Step S301, determining the key length of the initial key.
[0078] In this example, the daily historical storage data of the wind turbine is encrypted. To ensure the security of the complete data, the key length of the initial key can be determined to be 512 bits.
[0079] Step S302: randomly generate the initial key.
[0080] In an optional example, the 512-bit initial key may be randomly generated using "system startup seconds + current CPU utilization" and a hash algorithm.
[0081] In an optional example, before determining the key length of the initial key, the length of a compression header in the compressed data packet may be obtained; the compression header includes attribute information of the compressed data packet. And the initial key is randomly generated so that the length of the generated initial key is greater than the length of the compression header.
[0082] Usually, the beginning of the file of a compressed data packet is some information corresponding to the compression method. For example, the compression header in the compressed data packet generated after ZIP compression must be ZIP and some other fixed information, which is referred to as the attribute information in the description of this example. Since the attribute information corresponding to the same compression method is fixed, relevant technical personnel may infer the key based on the attribute information. Therefore, the key length of the generated initial key can be made greater than the length of the compression header, so that the first sub-data packet cut according to the key length of the initial key, in addition to the attribute information, also contains disordered data with high entropy density in the compressed data packet, thereby increasing the difficulty of cracking the encryption key.
[0083] Step S303, cutting the data packet to be encrypted according to the key length of the initial key, so that among at least two obtained sub-data packets, one or zero sub-data packets have a length less than the key length, and the lengths of the other sub-data packets are equal to the key length.
[0084] The at least two sub-data packets include: a first sub-data packet and a second sub-data packet that are adjacent to each other; and the second sub-data packet is located after the first sub-data packet.
[0085] Step S304, encrypting the at least two sub-data packets respectively to obtain encrypted sub-data packets corresponding to each sub-data packet, including: using the first sub-data packet as an encryption key, and performing an XOR operation on the encryption key and the second sub-data packet to obtain an encrypted sub-data packet corresponding to the second sub-data packet.
[0086] In an optional example, before using the first sub-data packet as the encryption key, a hash operation may be performed on the first sub-data packet to obtain a random string corresponding to the first sub-data packet; and the random string may be used as the encryption key.
[0087] In this example, by performing a hash operation on the first sub-data packet, the disorder of the data in the first sub-data packet can be further improved, and the random string obtained after the hash operation is used as the encryption key, which can further improve the security of encryption.
[0088] In an optional example, if the first sub-data packet has 512 bits, before using the first sub-data packet as the encryption key, the first 256 bits and the last 256 bits of the first sub-data packet may be hashed to obtain two corresponding random strings, and the two random strings are concatenated to serve as the encryption key, thereby further improving encryption security.
[0089] Since in the process of decrypting a data packet, when the decryption of the first data packet fails, the decryption of subsequent data packets is more difficult. Therefore, in an optional example, the above-mentioned hash operation can be performed only on the first sub-data packet, thereby speeding up the encryption speed and improving the encryption efficiency. The first sub-data packet is the first sub-data packet to be encrypted among the at least two sub-data packets.
[0090] In an optional example, before encrypting the first sub-packet of the at least two sub-packets using the initial key, a hash operation may be performed on the first sub-packet to obtain a random string corresponding to the first sub-packet; and the first sub-packet may be encrypted by performing an XOR operation on the initial key and the random string.
[0091] As mentioned above, in actual application, if the first sub-packet in a data packet can be cracked, subsequent cracking will be relatively easy. Therefore, the encryption of the first sub-packet should be performed with caution.
[0092] In this example, before encrypting the first sub-packet, a hash operation may be performed on the first sub-packet, so as to further obfuscate the data in the first sub-packet, improve the security of encryption, and increase the difficulty of cracking.
[0093] Step S305: concatenate the encrypted sub-data packets corresponding to the sub-data packets to obtain an encrypted data packet corresponding to the data packet to be encrypted.
[0094] The data encryption method provided by the embodiment of the present disclosure performs a hash operation on the first sub-packet before using the first sub-packet as the encryption key, and then uses the random string obtained by the hash operation as the encryption key, or performs a hash operation on the first sub-packet before encrypting the first sub-packet, thereby further obfuscating the data in the first sub-packet and improving the security of the encryption.
[0095] Figure 4 The figure is a flow chart of a data decryption method according to an exemplary embodiment of the present disclosure.
[0096] like Figure 4 As shown, the exemplary embodiment method may include the following steps:
[0097] Step S401, cutting the encrypted data packet to obtain at least two sub-data packets.
[0098] The at least two sub-data packets include: a first sub-data packet to be decrypted and a second sub-data packet to be decrypted that are adjacent; and the second sub-data packet to be decrypted is located after the first sub-data packet to be decrypted.
[0099] In an optional example, before cutting the encrypted data packet to obtain the at least two sub-data packets, an initial key may be obtained first.
[0100] Specifically, when the current application scenario is a real-time communication scenario, the key in the communication header can be restored using the private key of the party. When the current application scenario is a historical data storage scenario, the initial key can be obtained from the "safe".
[0101] After the initial key is acquired, the encrypted data packet may be cut according to the key length of the initial key to obtain the at least two sub-data packets.
[0102] Step S402, decrypting the at least two sub-data packets respectively to obtain decrypted sub-data packets corresponding to each sub-data packet, including: using the decrypted sub-data packet obtained after decrypting the first sub-data packet to be decrypted as a decryption key, and using the decryption key to perform a decryption operation on the second sub-data packet to be decrypted to obtain a decrypted sub-data packet corresponding to the second sub-data packet to be decrypted.
[0103] In an optional example, before respectively decrypting the at least two sub-data packets to obtain decrypted sub-data packets corresponding to each sub-data packet, the first sub-data packet to be decrypted in the at least two sub-data packets can be decrypted using the initial key to obtain a decrypted sub-data packet corresponding to the first sub-data packet to be decrypted, and the first sub-data packet to be decrypted is the first sub-data packet to be decrypted in the at least two sub-data packets.
[0104] In an optional example, after obtaining the decrypted sub-packet corresponding to the first sub-packet to be decrypted, the decrypted sub-packet can be used as a decryption key, and the decryption key is XORed with the second sub-packet to be decrypted to obtain the decrypted sub-packet corresponding to the second sub-packet to be decrypted. The data decryption method of this step is described by taking the following as an example:
[0105] For example, if the initial key obtained is 1100, the first sub-data packet to be decrypted obtained in step S301 is 1110, and the second sub-data packet to be decrypted is 1001, then the first sub-data packet to be decrypted, i.e., the first sub-data packet to be decrypted 1110, is subjected to an XOR operation using the initial key 1100 to obtain a decrypted sub-data packet 0010 corresponding to the first sub-data packet to be decrypted. Further, the decrypted sub-data packet 0010 obtained after decrypting the first sub-data packet to be decrypted is used as a decryption key, and the decryption key is subjected to an XOR operation with the second sub-data packet to be decrypted 1001 to obtain a decrypted sub-data packet 1011 corresponding to the second sub-data packet to be decrypted.
[0106] In an optional example, if during the encryption process, before using the first sub-packet as the encryption key, a hash operation is performed on the first sub-packet to obtain a random string corresponding to the first sub-packet, and the random string is used as the encryption key. Then, before using the decrypted sub-packet obtained after decrypting the first sub-packet to be decrypted as the decryption key, a corresponding hash operation should be performed on the decrypted sub-packet to obtain a random string corresponding to the decrypted sub-packet, and the random string should be used as the decryption key.
[0107] Step S403: concatenate the decrypted sub-data packets corresponding to the sub-data packets to obtain a decrypted data packet corresponding to the encrypted data packet.
[0108] Let’s continue with the above example:
[0109] The decrypted sub-data packet 0010 corresponding to the first sub-data packet to be decrypted and the decrypted sub-data packet 1011 corresponding to the second sub-data packet to be decrypted may be concatenated to obtain the decrypted sub-data packet 00101011 corresponding to the encrypted sub-data packet.
[0110] It should be noted that the data decryption method exemplified in the embodiment of the present disclosure is applicable to any two adjacent sub-data packets to be decrypted. The above description is merely exemplary and is intended to introduce the principle of the data decryption method in the embodiment of the present disclosure.
[0111] The data decryption method provided by the embodiment of the present disclosure uses an XOR operation to decrypt a data packet. The algorithm is simple and the decryption speed is fast, thereby achieving high decryption efficiency.
[0112] For the aforementioned method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations, but those skilled in the art should know that the present disclosure is not limited by the described order of actions, because according to the present disclosure, certain steps can be performed in other orders or simultaneously.
[0113] Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required by the present disclosure.
[0114] Corresponding to the aforementioned application function implementation method embodiment, the present disclosure also provides an application function implementation device and a corresponding terminal embodiment.
[0115] Figure 5 is a schematic diagram of the structure of a data encryption device in an exemplary embodiment of the present disclosure. Figure 5 As shown, the data encryption device may include:
[0116] The to-be-encrypted data packet cutting module 51 is used to cut the to-be-encrypted data packet to obtain at least two sub-data packets, wherein the at least two sub-data packets include: a first sub-data packet and a second sub-data packet that are adjacent to each other; and the second sub-data packet is located after the first sub-data packet;
[0117] The encryption module 52 is used to perform encryption processing on the at least two sub-data packets respectively to obtain encrypted sub-data packets corresponding to each sub-data packet, including: using the first sub-data packet as an encryption key, and performing encryption operation on the second sub-data packet using the encryption key to obtain an encrypted sub-data packet corresponding to the second sub-data packet;
[0118] The encrypted sub-data packet splicing module 53 is used to splice the encrypted sub-data packets corresponding to the sub-data packets to obtain an encrypted data packet corresponding to the data packet to be encrypted.
[0119] Optionally, the encryption module 52, when used to use the first sub-data packet as an encryption key and perform an encryption operation on the second sub-data packet using the encryption key to obtain an encrypted sub-data packet corresponding to the second sub-data packet, includes:
[0120] The first sub-data packet is used as an encryption key, and an XOR operation is performed on the encryption key and the second sub-data packet to obtain an encrypted sub-data packet corresponding to the second sub-data packet.
[0121] Optionally, the encryption module 52, when used to encrypt the at least two sub-data packets respectively to obtain encrypted sub-data packets corresponding to each sub-data packet, includes:
[0122] Randomly generate an initial key;
[0123] The first sub-packet in the at least two sub-packets is encrypted using the initial key to obtain an encrypted sub-packet corresponding to the first sub-packet, wherein the first sub-packet is the first sub-packet in the at least two sub-packets to be encrypted.
[0124] Optionally, the to-be-encrypted data packet cutting module 51, when used to cut the to-be-encrypted data packet to obtain at least two sub-data packets, includes:
[0125] Determining a key length of the initial key;
[0126] The data packet to be encrypted is cut according to the key length to obtain at least two sub-data packets, wherein the length of one or zero sub-data packets among the at least two sub-data packets is less than the key length, and the length of the other sub-data packets is equal to the key length.
[0127] Optionally, the encryption module 52, when used to randomly generate an initial key, includes:
[0128] Acquire the length of a compression header in the compressed data packet; the compression header includes attribute information of the compressed data packet;
[0129] An initial key is randomly generated so that the length of the generated initial key is greater than the length of the compression header.
[0130] Optionally, the encryption module 52, when used to encrypt the first sub-data packet of the at least two sub-data packets by using the initial key, includes:
[0131] Performing a hash operation on the first sub-data packet to obtain a random string corresponding to the first sub-data packet;
[0132] The random string corresponding to the first sub-data packet is encrypted using the initial key.
[0133] Optionally, when the encryption module 52 is used to use the first sub-data packet as an encryption key, it includes:
[0134] Performing a hash operation on the first sub-data packet to obtain a random string corresponding to the first sub-data packet;
[0135] The random string is used as the encryption key.
[0136] Figure 6 is a schematic diagram of the structure of a data decryption device in an exemplary embodiment of the present disclosure. Figure 6 As shown, the data decryption device may include:
[0137] The encrypted data packet cutting module 61 is used to cut the encrypted data packet to obtain at least two sub-data packets, wherein the at least two sub-data packets include: a first sub-data packet to be decrypted and a second sub-data packet to be decrypted that are adjacent to each other; and the second sub-data packet to be decrypted is located after the first sub-data packet to be decrypted;
[0138] The decryption module 62 is used to perform decryption processing on the at least two sub-data packets respectively to obtain decrypted sub-data packets corresponding to each sub-data packet, including: using the decrypted sub-data packet obtained after decrypting the first sub-data packet to be decrypted as a decryption key, and using the decryption key to perform a decryption operation on the second sub-data packet to be decrypted to obtain a decrypted sub-data packet corresponding to the second sub-data packet to be decrypted;
[0139] The decrypted sub-data packet splicing module 63 is used to splice the decrypted sub-data packets corresponding to the sub-data packets to obtain a decrypted data packet corresponding to the encrypted data packet.
[0140] Optionally, the decryption module 62, when used to use the decrypted sub-data packet obtained after decrypting the first sub-data packet to be decrypted as a decryption key, and use the decryption key to perform a decryption operation on the second sub-data packet to be decrypted to obtain a decrypted sub-data packet corresponding to the second sub-data packet to be decrypted, includes:
[0141] The decrypted sub-data packet obtained by decrypting the first sub-data packet to be decrypted is used as a decryption key, and the decryption key is XOR-ed with the second sub-data packet to be decrypted to obtain a decrypted sub-data packet corresponding to the second sub-data packet to be decrypted.
[0142] Optionally, the decryption module 62, when used to perform decryption processing on the at least two sub-data packets respectively to obtain decrypted sub-data packets corresponding to each sub-data packet, includes:
[0143] Get the initial key;
[0144] The first sub-packet to be decrypted in the at least two sub-packets is decrypted using the initial key to obtain a decrypted sub-packet corresponding to the first sub-packet to be decrypted. The first sub-packet to be decrypted is the first sub-packet to be decrypted in the at least two sub-packets.
[0145] Optionally, the decryption module 62, when used to use the decrypted sub-data packet obtained by decrypting the first sub-data packet to be decrypted as a decryption key, includes:
[0146] Performing a hash operation on a decrypted sub-data packet obtained after decrypting the first sub-data packet to be decrypted, to obtain a random string corresponding to the decrypted sub-data packet;
[0147] The random string is used as the decryption key.
[0148] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can refer to the partial description of the method embodiments. The device embodiments described above are only schematic, wherein 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, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the disclosed solution. A person of ordinary skill in the art may understand and implement it without creative work.
[0149] Accordingly, an embodiment of the present disclosure provides an electronic device, comprising: a processor; a memory for storing instructions executable by the processor; wherein the processor is configured to execute the data encryption method and the data decryption method of any embodiment of the present disclosure.
[0150] Figure 7 1 is a schematic diagram of the structure of an electronic device 700 according to an exemplary embodiment. For example, the electronic device 700 may be a user device, and may specifically be a mobile phone, a computer, a digital broadcast terminal, a message transceiver device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, a wearable device such as a smart watch, a smart glasses, a smart bracelet, a smart running shoe, etc.
[0151] Reference Figure 7 , the electronic device 700 may include one or more of the following components: a processing component 702 , a memory 704 , a power component 706 , a multimedia component 708 , an audio component 710 , an input / output (I / O) interface 712 , a sensor component 714 , and a communication component 716 .
[0152] The processing component 702 generally controls the overall operation of the electronic device 700, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 702 may include one or more processors 720 to execute instructions to complete all or part of the steps of the above-mentioned method. In addition, the processing component 702 may include one or more modules to facilitate the interaction between the processing component 702 and other components. For example, the processing component 702 may include a multimedia module to facilitate the interaction between the multimedia component 708 and the processing component 702.
[0153] The memory 704 is configured to store various types of data to support operations on the device 700. Examples of such data include instructions for any application or method operating on the electronic device 700, contact data, phone book data, messages, pictures, videos, etc. The memory 704 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0154] The power supply component 706 provides power to the various components of the electronic device 700. The power supply component 706 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the electronic device 700.
[0155] The multimedia component 708 includes a screen that provides an output interface between the electronic device 700 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 708 includes a front camera and / or a rear camera. When the electronic device 700 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
[0156] The audio component 710 is configured to output and / or input audio signals. For example, the audio component 710 includes a microphone (MIC), and when the electronic device 700 is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 704 or sent via the communication component 716. In some embodiments, the audio component 710 also includes a speaker for outputting audio signals.
[0157] I / O interface 712 provides an interface between processing component 702 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: a home button, a volume button, a start button, and a lock button.
[0158] The sensor assembly 714 includes one or more sensors for providing various aspects of status assessment for the electronic device 700. For example, the sensor assembly 714 can detect the open / closed state of the electronic device 700, the relative positioning of the components, such as the display and keypad of the electronic device 700, and the sensor assembly 714 can also detect the position change of the electronic device 700 or a component of the electronic device 700, the presence or absence of contact between the user and the electronic device 700, the orientation or acceleration / deceleration of the electronic device 700, and the temperature change of the electronic device 700. The sensor assembly 714 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 714 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 714 may also include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0159] The communication component 716 is configured to facilitate wired or wireless communication between the electronic device 700 and other devices. The electronic device 700 can access a wireless network based on a communication standard, such as WiFi, 4G or 5G, 4G LTE, 5G NR or a combination thereof. In an exemplary embodiment, the communication component 716 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 716 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0160] In an exemplary embodiment, the electronic device 700 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the above methods.
[0161] In an exemplary embodiment, a computer-readable storage medium is also provided, such as a memory 704 including instructions. When the instructions in the storage medium are executed by a processor 720 of an electronic device 700, the electronic device 700 is enabled to execute the data encryption method and the data decryption method of any embodiment of the present disclosure.
[0162] The non-transitory computer-readable storage medium may be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, and the like.
[0163] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. The present disclosure is intended to cover any variations, uses or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The description and examples are to be considered exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.
[0164] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. A data encryption method, characterized in that: The method is used to encrypt a data packet to be encrypted; The data packet to be encrypted is a compressed data packet, and the method comprises: Cutting the data packet to be encrypted to obtain at least two sub-data packets, wherein the at least two sub-data packets include: a first sub-data packet and a second sub-data packet that are adjacent to each other; and the second sub-data packet is located after the first sub-data packet; Encrypting the at least two sub-data packets respectively to obtain encrypted sub-data packets corresponding to the sub-data packets, including: randomly generating an initial key, encrypting the first sub-data packet of the at least two sub-data packets by using the initial key to obtain an encrypted sub-data packet corresponding to the first sub-data packet; using the first sub-data packet as an encryption key, and using the encryption key to perform encryption operation on the second sub-data packet to obtain an encrypted sub-data packet corresponding to the second sub-data packet; the first sub-data packet is the first sub-data packet of the at least two sub-data packets to be encrypted; The encrypted sub-data packets corresponding to the sub-data packets are concatenated to obtain an encrypted data packet corresponding to the data packet to be encrypted.
2. The method according to claim 1, characterized in that The step of using the first sub-data packet as an encryption key and performing an encryption operation on the second sub-data packet using the encryption key to obtain an encrypted sub-data packet corresponding to the second sub-data packet includes: The first sub-data packet is used as an encryption key, and an XOR operation is performed on the encryption key and the second sub-data packet to obtain an encrypted sub-data packet corresponding to the second sub-data packet.
3. The method according to claim 1, characterized in that The step of cutting the data packet to be encrypted to obtain at least two sub-data packets includes: Determining a key length of the initial key; The data packet to be encrypted is cut according to the key length to obtain at least two sub-data packets, wherein the length of one or zero sub-data packets among the at least two sub-data packets is less than the key length, and the length of the other sub-data packets is equal to the key length.
4. The method according to claim 1, characterized in that The randomly generating an initial key comprises: Acquire the length of a compression header in the compressed data packet; the compression header includes attribute information of the compressed data packet; An initial key is randomly generated so that the length of the generated initial key is greater than the length of the compression header.
5. The method according to claim 1, characterized in that The encrypting the first sub-data packet of the at least two sub-data packets by using the initial key comprises: Performing a hash operation on the first sub-data packet to obtain a random string corresponding to the first sub-data packet; The random string corresponding to the first sub-data packet is encrypted using the initial key.
6. The method according to claim 1, characterized in that The using the first sub-data packet as an encryption key comprises: Performing a hash operation on the first sub-data packet to obtain a random string corresponding to the first sub-data packet; The random string is used as the encryption key.
7. A data decryption method, characterized in that: The method is used to decrypt an encrypted data packet; the method comprises: Cutting the encrypted data packet to obtain at least two sub-data packets, wherein the at least two sub-data packets include: a first sub-data packet to be decrypted and a second sub-data packet to be decrypted, which are adjacent to each other; and the second sub-data packet to be decrypted is located after the first sub-data packet to be decrypted; Decrypting the at least two sub-data packets respectively to obtain decrypted sub-data packets corresponding to the respective sub-data packets, including: obtaining an initial key, decrypting the first sub-data packet to be decrypted in the at least two sub-data packets by using the initial key to obtain a decrypted sub-data packet corresponding to the first sub-data packet to be decrypted; using the decrypted sub-data packet obtained after decrypting the first sub-data packet to be decrypted as a decryption key, and using the decryption key to decrypt the second sub-data packet to be decrypted to obtain a decrypted sub-data packet corresponding to the second sub-data packet to be decrypted; the first sub-data packet to be decrypted is the first sub-data packet to be decrypted in the at least two sub-data packets; The decrypted sub-data packets corresponding to the sub-data packets are concatenated to obtain the decrypted data packet corresponding to the encrypted data packet.
8. The method according to claim 7, characterized in that The method of using the decrypted sub-data packet obtained by decrypting the first sub-data packet to be decrypted as a decryption key, and using the decryption key to perform a decryption operation on the second sub-data packet to be decrypted to obtain a decrypted sub-data packet corresponding to the second sub-data packet to be decrypted, comprises: The decrypted sub-data packet obtained by decrypting the first sub-data packet to be decrypted is used as a decryption key, and the decryption key is XOR-ed with the second sub-data packet to be decrypted to obtain a decrypted sub-data packet corresponding to the second sub-data packet to be decrypted.
9. The method according to claim 7, characterized in that: The step of using the decrypted sub-data packet obtained by decrypting the first sub-data packet to be decrypted as a decryption key comprises: Performing a hash operation on a decrypted sub-data packet obtained after decrypting the first sub-data packet to be decrypted, to obtain a random string corresponding to the decrypted sub-data packet; The random string is used as the decryption key.
10. A data encryption device, characterized in that: The device is used to encrypt a data packet to be encrypted; the data packet to be encrypted is a compressed data packet, and the device comprises: A data packet cutting module to be encrypted, used for cutting the data packet to be encrypted to obtain at least two sub-data packets, wherein the at least two sub-data packets include: a first sub-data packet and a second sub-data packet that are adjacent to each other; and the second sub-data packet is located after the first sub-data packet; an encryption module, configured to perform encryption processing on the at least two sub-data packets respectively to obtain encrypted sub-data packets corresponding to the respective sub-data packets, including: randomly generating an initial key, and performing encryption processing on the first sub-data packet of the at least two sub-data packets by using the initial key to obtain an encrypted sub-data packet corresponding to the first sub-data packet; using the first sub-data packet as an encryption key, and performing encryption operation on the second sub-data packet by using the encryption key to obtain an encrypted sub-data packet corresponding to the second sub-data packet; the first sub-data packet is the first sub-data packet of the at least two sub-data packets to be encrypted; The encrypted sub-data packet splicing module is used to splice the encrypted sub-data packets corresponding to the sub-data packets to obtain an encrypted data packet corresponding to the data packet to be encrypted.
11. A data decryption device, characterized in that: The device is used to decrypt an encrypted data packet; the device comprises: An encrypted data packet cutting module is used to cut the encrypted data packet to obtain at least two sub-data packets, wherein the at least two sub-data packets include: a first sub-data packet to be decrypted and a second sub-data packet to be decrypted that are adjacent to each other; and the second sub-data packet to be decrypted is located after the first sub-data packet to be decrypted; a decryption module, configured to perform decryption processing on the at least two sub-data packets respectively to obtain decrypted sub-data packets corresponding to each sub-data packet, including: obtaining an initial key, decrypting the first sub-data packet to be decrypted in the at least two sub-data packets by using the initial key to obtain a decrypted sub-data packet corresponding to the first sub-data packet to be decrypted; using the decrypted sub-data packet obtained after decrypting the first sub-data packet to be decrypted as a decryption key, and performing a decryption operation on the second sub-data packet to be decrypted by using the decryption key to obtain a decrypted sub-data packet corresponding to the second sub-data packet to be decrypted; the first sub-data packet to be decrypted is the first sub-data packet to be decrypted in the at least two sub-data packets; The decrypted sub-data packet splicing module is used to splice the decrypted sub-data packets corresponding to the sub-data packets to obtain the decrypted data packet corresponding to the encrypted data packet.
12. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method described in any one of claims 1 to 6 or any one of claims 7 to 9 is implemented.
13. An electronic device, characterized in that: include: processor; a memory for storing processor-executable instructions; The processor is configured to execute the data encryption method described in any one of claims 1 to 6, or the data decryption method described in any one of claims 7 to 9.
