Message encryption method, decryption method and sending method
By performing fragment encryption and exclusive OR processing of packets in the TCP/UDP communication link, combined with random sending, the problem of insufficient security of the communication link is solved, and high-security data transmission in a fixed IP address environment is realized .
Patent Information
- Application Number
- CN202411409894.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-10
- Publication Date
- 2025-01-10
AI Technical Summary
The TCP/UDP communication link lacks sufficient security guarantee and is prone to malicious monitoring to cause data leakage. The existing encryption technology is not applicable to fixed IP addresses and is difficult to improve security.
By sharding the target message and encrypting the shard message and encryption factor in combination with the XOR algorithm, encrypting the shard message is generated and randomly sent when sending, increasing the difficulty of being deciphered.
It improves the security and difficulty of message transmission, avoids the risks of monitoring and reverse decoding, and is suitable for LAN environments with fixed IP addresses.
Smart Images

Figure CN119299168A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of data transmission, and in particular to a message encryption method, a decryption method and a sending method. Background Art
[0002] The currently widely used TCP / UDP communication technology is based on the second layer / third layer header for data transmission. This technology has been used in many occasions. However, it has an obvious flaw: the communication link is easily monitored by malicious parties, resulting in the leakage of communication messages, or the listener monitors the link message for a long time to reverse decrypt it, thus causing data leakage. Summary of the invention
[0003] In view of this, an embodiment of the present application provides a message encryption method, a decryption method and a sending method, by fragmenting the encrypted message and splitting the fragmented encrypted message, combining the encryption factor after splitting, and combining the XOR algorithm to encrypt the target message to achieve the purpose of secure message transmission.
[0004] In a first aspect, an embodiment of the present application provides a message encryption method, including:
[0005] Fragmenting the target message to form multiple fragmented messages;
[0006] According to the fragment length and encryption factor of each fragment message, the corresponding fragment message is encrypted in combination with a preset logical operation to generate a corresponding fragment encrypted message; wherein the encryption factor of the first fragment message is an initial encryption factor, and the encryption factors of the remaining fragment messages are data associated with the encryption factor of the previous fragment message;
[0007] An identification header is added to each of the fragmented encrypted messages to form multiple fragmented sending encrypted messages corresponding to the current target message.
[0008] In some embodiments, the fragmenting of the target message to form a plurality of fragmented messages includes:
[0009] Determine the byte number interval and / or the number of fragments of each fragment message;
[0010] The target message is fragmented according to the byte number interval and / or the number of fragments to generate a plurality of the fragmented messages.
[0011] In some embodiments, encrypting the corresponding fragment message according to the fragment length and encryption factor of each fragment message in combination with a preset logical operation to generate a corresponding fragment encrypted message includes:
[0012] Each of the fragment messages is split according to a preset splitting rule to form a plurality of split messages including a target number of bytes; and an XOR operation is performed on each of the split messages and the encryption factor corresponding to the current fragment message according to a preset logical operation to obtain the associated encryption factor of the plurality of XOR messages and the next fragment message;
[0013] Combine the multiple XOR messages, the length data of the current fragment message and the associated encryption factor of the next fragment message to form the fragment encrypted message; wherein the length data is the preset byte data obtained by converting the fragment length of the current fragment message.
[0014] In some embodiments, the splitting of each fragment message according to a preset splitting rule to form a plurality of split messages including a target number of bytes; and performing an XOR operation on each of the split messages and the encryption factor corresponding to the current fragment message according to a preset logical operation to obtain the associated encryption factor of the plurality of XOR messages and the next fragment message, including:
[0015] Splitting each of the fragmented messages to form a plurality of the split messages including the target number of bytes; wherein the target number of bytes is the same as the number of bytes of the encryption factor; if the number of bytes of the last split message is less than the target number of bytes, adding preset data after the last split message so that the number of bytes of the last split message is equal to the target number of bytes;
[0016] Performing XOR on each of the split messages and the encryption factor of the current fragment message to form a plurality of XOR messages;
[0017] The XOR message formed by XORing the last split message of the current fragment message with the encryption factor is used as the associated encryption factor of the next fragment message.
[0018] In some embodiments, adding an identification header to each of the fragmented encrypted messages to form a fragmented sending encrypted message includes:
[0019] Form an identification header according to the fragment sequence number of the current fragment message and the timestamp when the current fragment sends the encrypted message;
[0020] The identification header is added to the corresponding fragmented encrypted message to form the fragmented sending encrypted message.
[0021] In a second aspect, an embodiment of the present application provides a message decryption method for decrypting a message encrypted according to the above message encryption method, comprising:
[0022] Integrate and process the encrypted messages sent by multiple fragments according to the identification packet header to form an encrypted message that is consistent with the order of the target message;
[0023] Obtain the fragment length and encryption factor in the encrypted message sent by each fragment, and decrypt the current encrypted message according to the fragment length and encryption factor in the encrypted message sent by each fragment in combination with a preset logical operation to obtain a decrypted target message.
[0024] In some embodiments, the obtaining of the fragment length and the encryption factor in the encrypted message sent by each fragment, and decrypting the current encrypted message according to the fragment length and the encryption factor in the encrypted message sent by each fragment in combination with a preset logical operation to obtain a decrypted target message includes:
[0025] In combination with the generation rule of the encrypted message sent by the fragments, the corresponding message to be decrypted, the fragment length and the encryption factor are obtained from each of the encrypted messages sent by the fragments;
[0026] Splitting each of the to-be-decrypted messages to form a plurality of split decrypted messages including a target number of bytes;
[0027] Based on each split decrypted message corresponding to the current segmented encrypted message, the segment length and the encryption factor, the current segmented encrypted message is decrypted in combination with an XOR operation to obtain a target decrypted split message;
[0028] Combining the plurality of target decrypted split messages in sequence to obtain a decrypted target message.
[0029] In some embodiments, the generating rule of sending the encrypted message in combination with the fragments, obtaining the corresponding message to be decrypted, the fragment length and the encryption factor from each of the fragments sending the encrypted message, includes:
[0030] In combination with the generation rule of the fragmented encrypted message, obtain the fragment length of the fragmented message corresponding to the current fragmented encrypted message contained in the current fragmented encrypted message, and the encryption factor of the fragmented message corresponding to the next fragmented encrypted message of the current fragmented encrypted message;
[0031] Removing the identification header, the fragment length and the encryption factor contained in the encrypted message currently sent by the fragment, so as to obtain the message to be decrypted corresponding to the encrypted message currently sent by the fragment;
[0032] The decrypting the encrypted message sent by the current segment based on each split decrypted message corresponding to the encrypted message sent by the current segment, the segment length and the encryption factor, and decrypting the encrypted message sent by the current segment in combination with an XOR operation to obtain a target decrypted split message, including:
[0033] Performing XOR on each of the split decrypted messages and the encryption factor corresponding to the current message to be decrypted according to a preset rule to obtain a plurality of XOR decrypted messages;
[0034] Combining the multiple XOR decrypted messages corresponding to each of the split decrypted messages in order to form a decrypted split message;
[0035] The number of supplementary bytes of the supplementary preset data included in the decrypted split message is determined according to the fragment length, and the number of supplementary bytes following the decrypted split message is deleted to form a target decrypted split message.
[0036] In a third aspect, an embodiment of the present application provides a message sending method, including:
[0037] In response to the message sending operation, at least one of the fragmented encrypted messages is randomly obtained from the corresponding sending queue for sending; wherein, the fragmented encrypted message is obtained according to the above-mentioned message encryption method; the sending queue is a queue formed by all the fragmented encrypted messages corresponding to the current target message.
[0038] In some embodiments, before the step of sequentially obtaining at least one of the fragmented encrypted messages from the corresponding sending queue for sending, the step further includes:
[0039] Add a message ID to the encrypted message sent for each fragment; wherein each target message corresponds to a message ID;
[0040] The encrypted message is sent in conjunction with the obfuscated data packet.
[0041] The embodiments of the present application have the following beneficial effects: the present application randomly fragments the target message, and then performs XOR processing on the fragment message and the encryption factor according to the fragment length and encryption factor of each fragment message in combination with XOR operation to generate a fragment encrypted message corresponding to each fragment message. Through this encryption method, the present application can improve the security of message transmission. In addition, when the embodiment of the present application transmits the encrypted message, since multiple fragments are generated after encryption to send encrypted messages, when sending the message, the present application does not send it in sequence, but randomly sends multiple fragments to send encrypted messages, thereby further avoiding the risk of being monitored during the message transmission process. Even if it is monitored, the encryption method and random sending method of the present application can increase the difficulty of being deciphered. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0043] Figure 1 A schematic diagram of the structure of a message transmission system according to an embodiment of the present application is shown;
[0044] Figure 2 A first flow chart of the message encryption method according to an embodiment of the present application is shown;
[0045] Figure 3 A second flow chart of the message encryption method according to an embodiment of the present application is shown;
[0046] Figure 4 A third flow chart of the message encryption method according to an embodiment of the present application is shown;
[0047] Figure 5 A first flow chart of the message decryption method according to an embodiment of the present application is shown;
[0048] Figure 6 A second flow chart of the message decryption method according to an embodiment of the present application is shown;
[0049] Figure 7 A third flow chart of the message decryption method according to an embodiment of the present application is shown;
[0050] Figure 8 A fourth flow chart of the message decryption method according to an embodiment of the present application is shown;
[0051] Fig. 9 A flow chart of a message sending method according to an embodiment of the present application is shown. DETAILED DESCRIPTION
[0052] The technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments.
[0053] The components of the embodiments of the present application generally described and shown in the drawings herein may be arranged and designed in various configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.
[0054] Hereinafter, the terms "including", "having" and their cognates that can be used in various embodiments of the present application are intended only to indicate specific features, numbers, steps, operations, elements, components or a combination of the foregoing items, and should not be understood as first excluding the existence of one or more other features, numbers, steps, operations, elements, components or a combination of the foregoing items or increasing the possibility of one or more features, numbers, steps, operations, elements, components or a combination of the foregoing items. In addition, the terms "first", "second", "third" and the like are only used to distinguish descriptions and cannot be understood as indicating or implying relative importance.
[0055] Unless otherwise defined, all terms (including technical terms and scientific terms) used herein have the same meanings as those generally understood by those skilled in the art to which the various embodiments of the present application belong. The terms (such as those defined in generally used dictionaries) will be interpreted as having the same meanings as the contextual meanings in the relevant technical field and will not be interpreted as having idealized meanings or overly formal meanings unless clearly defined in the various embodiments of the present application.
[0056] In conjunction with the accompanying drawings, some embodiments of the present application are described in detail below. In the absence of conflict, the following embodiments and features in the embodiments can be combined with each other.
[0057] Since TCP / UDP communication links lack sufficient security protection, once they are monitored by a third party, data leakage will occur. In the prior art, IPsec encryption technology is usually used to encrypt the transmitted data through a five-tuple configuration (the five-tuple includes: 1. Source IP address (SourceIPAddress): the network address of the data packet sender; 2. Destination IP address (DestinationIPAddress): the network address of the data packet receiver; 3. Source port number (SourcePortNumber): the process port of the application layer of the data packet sender; 4. Destination port number (DestinationPortNumber): the process port of the application layer of the data packet receiver; 5. Protocol number (ProtocolNumber): the transport layer protocol used by the data packet, such as TCP (6), UDP (17), etc.). Although it can enhance security to a certain extent, it will change the original IP address and the target IP address information, so it is not applicable to those devices in the local area network with relatively fixed IP addresses.
[0058] Based on this, the present application proposes a message encryption method, decryption method and sending method suitable for transmitting data through TCP / UDP and with a fixed IP address, wherein TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) are both protocols for transmitting data on the Internet. They both belong to the transport layer protocol, but they are significantly different in design objectives, functional characteristics, service quality, etc. TCP is a connection-oriented, reliable, byte stream-based transmission protocol. Its main features include: 1. Connection establishment: Before data transmission, TCP will first establish a connection through a three-way handshake to ensure the consistency and order of data transmission. 2. Flow control: Use a sliding window mechanism to avoid overflow of the receiving end buffer due to excessive speed of the sender. 3. Error detection and recovery: Ensure the integrity of data transmission through checksum, sequence number and confirmation response mechanism. If the data packet is lost or damaged, retransmission can be requested. 4. Congestion control: Automatically adjust the sending rate to prevent network congestion. 5. End-to-end communication: Provide full-duplex communication and support one-to-one or many-to-one communication.
[0059] UDP is a connectionless, unreliable transmission protocol. Its main features include: 1. Connectionless: UDP does not need to establish a connection and directly sends data packets, which reduces overhead. 2. Fast transmission: Since there is no need to establish a connection and confirm, UDP's data transmission speed is usually faster than TCP. 3. No guarantee of sequence: Data may arrive in the order in which it is sent, or it may be out of order. 4. No guarantee of reliability: There is no error detection and retransmission mechanism, and data loss and damage cannot be repaired. 5. Simplicity: Compared with TCP, UDP is simpler to implement and consumes less resources.
[0060] In terms of application scenarios, UDP is often used in real-time interaction of online games (such as messaging between players, action synchronization, etc.), voice or video calls (such as Skype, WeChat voice calls, etc.), network broadcasting such as TV, radio streaming services, multicast, small file transfer, etc. TCP is often used in file transfer services (FTP (File Transfer Protocol) and SFTP (Secure File Transfer Protocol) and other protocols use TCP to transfer files), Web services (such as HTTP (Hypertext Transfer Protocol) for obtaining web page content from a Web server), email services (such as SMTP (Simple Mail Transfer Protocol) for sending emails, POP3 (Post Office Protocol version 3) and IMAP (Internet Message Access Protocol) for receiving emails from a mail server), media services and instant messaging and VoIP (TCP-based messaging and VoIP services) and other fields.
[0061] The following first describes the message transmission system. Figure 1 As shown, the message transmission system includes a first network device end 100 and a second network device end 200, wherein data can be transmitted between the first network device end 100 and the second network device end 200; the first network device end 100 and the second network device end 200 can be personal computers, servers, mobile devices, routers, smart home appliances, Internet of Things devices and other devices that can access the network, and can also be Web servers.
[0062] The first network device end 100 and the second network device end 200 can both be used for sending and receiving messages. The message transmission system of the present application is described below with the first network device end 100 as the sending end and the second network device end 200 as the receiving end.
[0063] When the first network device end 100 sends a message to the second network device end 200, the first network device end 100 responds to the message sending operation, first encrypts the target message to be sent, and sends it to the second network device end 200 after encryption. After the second network device end 200 receives the encrypted message, it decrypts the encrypted message to obtain the original target message, so as to achieve secure transmission of data.
[0064] The message encryption method is described below in conjunction with some specific embodiments.
[0065] Figure 2A schematic flow chart of a message encryption method according to an embodiment of the present application is shown. Exemplarily, the message encryption method comprises the following steps:
[0066] Step S100, fragmenting the target message to form a plurality of fragmented messages.
[0067] For the security of subsequent target message transmission, the target message is divided into multiple fragment messages in this step, wherein the message in each fragment message is continuous; the number of bytes in the multiple fragment messages may be the same or different.
[0068] In some implementations, when the target message is fragmented, the number of fragments and the byte number interval of each fragment message are first determined; then the target message is randomly fragmented according to the determined number of fragments and the byte number interval of each fragment message. If the number of bytes of the target message is 2000, the determined number of fragments is 5, and the byte number interval of each fragment message is 200 bytes-700 bytes, then the number of bytes of each fragment message can be 300 bytes, 360 bytes, 500 bytes, 540 bytes, 300 bytes, or can also be 350 bytes, 400 bytes, 550 bytes, 300 bytes, 400 bytes. It can be understood that the above-mentioned fragmentation processing of the target message containing 2000 bytes is exemplary, as long as the preset number of fragments and the byte number interval of each fragment message are met.
[0069] In another embodiment, when the target message is processed by fragmentation, only the byte number interval of each fragment message can be determined, and the number of fragments is not limited. If the byte number of the target message is 2000, and the byte number interval of each fragment message is 300-500, then the target message can be divided into 300 bytes, 400 bytes, 360 bytes, 440 bytes and 500 bytes, and the target message can also be divided into 300 bytes, 300 bytes, 300 bytes, 400 bytes, 300 bytes and 400 bytes. It can be understood that the above-mentioned fragmentation processing of the target message containing 2000 bytes is exemplary, as long as the preset byte number interval of each fragment message is met.
[0070] In another embodiment, when the target message is fragmented, only the number of fragments of each fragment message can be determined, and the byte number interval of each fragment message is not limited, but the number of bytes of each fragment message must not be too small, such as not less than 50 bytes, to avoid subsequent encryption failure. For example, if the number of bytes of the target message is 2000, when the target message is fragmented, the number of fragments can be set to 5, 6, 7 or 8, etc.
[0071] In addition, in the above three implementation methods for target message fragmentation, the user can also set the number of fragments and the byte range of each fragment message according to needs. If you want high transmission efficiency, you can consider fewer final fragments. If you want higher security, you can consider more final fragments. However, usually, the number of fragments will be reasonably determined after comprehensively considering transmission efficiency and security when the total number of bytes of the target message is determined.
[0072] Step S200, encrypting the corresponding fragmented message according to the fragment length and encryption factor of each fragmented message in combination with a preset logical operation to generate a corresponding fragmented encrypted message.
[0073] Among them, the encryption factor of the first fragment message is the initial encryption factor, and the encryption factors of the remaining fragment messages are associated encryption factors formed according to the previous fragment message and the encryption factor corresponding to the previous fragment message. It can be understood that the encryption factors in each fragment message are interrelated.
[0074] In this step, each fragment message is encrypted separately to generate a corresponding fragment encrypted message, and each fragment message is associated during encryption.
[0075] For example, Figure 3 As shown, step S200 includes:
[0076] Step S210, split each fragment message according to the preset splitting rule to form multiple fragment messages including the target number of bytes; and perform an XOR operation on the encryption factor corresponding to each split message and the current fragment message according to the preset logical operation to obtain the associated encryption factor of multiple XOR messages and the next fragment message.
[0077] In this step, in order to improve the security of message encryption and increase the difficulty of deciphering the message after being monitored during transmission, the fragmented message is split again to obtain multiple fragmented messages including the target number of bytes, and then the fragmented messages are XORed with the corresponding encryption factors according to the preset logical operation to obtain multiple XOR messages and the associated encryption factors of the next fragmented message. Then, the fragmented message corresponding to the next fragmented message can be XORed with the encryption factor generated by the previous fragmented message according to the preset logical operation until all the fragmented messages of the current target message are processed.
[0078] For example, Figure 4 As shown, step S210 specifically includes:
[0079] Step S211, split each fragment message to form multiple split messages including the target number of bytes.
[0080] Among them, the target number of bytes is the same as the number of bytes of the encryption factor; in this embodiment, a 16-byte initial encryption factor can be generated according to device information, MAC, time and other device-related parameters, and the number of bytes of each split message is also 16 bytes.
[0081] In this step, when each fragment message is split, the fragment message is split in order from front to back, that is, if the fragment message includes multiple bytes, the splitting starts from the first byte, that is, 1-16 bytes are a split message, 17-32 bytes are a split message, 33-48 bytes are a split message, and so on, until the current fragment message is split.
[0082] If the number of bytes of the last split message is less than the target number of bytes, the preset data is added after the last split message so that the number of bytes of the last split message is equal to the target number of bytes. It can be understood that if the number of bytes of the last split message is less than 16 bytes, the last split message is supplemented with 16 bytes, and the vacancies less than 16 bytes can be filled with 0 for supplementation. If the number of bytes of a fragment message is 200 bytes, when the fragment message is split, the number of bytes of the first 12 split messages meets 16 bytes, and only 8 bytes are left at the end, so 8 bytes of 0 are supplemented for the last split message so that the last split message is also 16 bytes.
[0083] Exemplarily, in order to generate a 16-byte initial encryption factor based on device information (such as MAC address), time and other related parameters, the following steps can be used in this embodiment:
[0084] (1) Collect input parameters: the device's MAC address (usually 6 bytes), the current timestamp (which can be the system's current time, stored in a certain format, such as a UNIX timestamp), possible other device identifiers or parameters, such as hardware version, operating system version, etc. (depending on the required security and specific application requirements), etc.; (2) Concatenate input parameters: Concatenate these parameters into a string or array in a specific order. (3) Use a hash function: Select a secure hash algorithm (such as SHA-256) to perform a hash operation on the concatenated string; the hash function can convert an input of any length into an output of a fixed length. In this embodiment, the focus is on a hash value with an output length of 16 bytes (i.e., 128 bits). (4) Intercept the required byte portion: Since the hash function may output more than 16 bytes of data, in this embodiment, the first 16 bytes need to be selected as the final encryption factor. In addition, if more complex processing logic is required, further salting, rotation, and other operations can also be considered for the hash output, but the basic process is to generate the hash first and then extract the required length.
[0085] Step S212, performing XOR operations on each split message and the encryption factor of the current fragment message respectively to form multiple XOR messages.
[0086] If the split message includes A, B and C, and the encryption factor of the current fragment message is W, then A and W are XORed to obtain the corresponding XOR message, B and W are XORed to obtain the corresponding XOR message, C and W are XORed to obtain the corresponding XOR message, and then 3 XOR messages are obtained.
[0087] Step S213: XOR the last split message of the current fragment message with the encryption factor to form an XOR message as the associated encryption factor of the next fragment message.
[0088] Step S220, combining multiple XOR messages, the length data of the current fragment message and the associated encryption factor of the next fragment message to form a fragment encrypted message.
[0089] The length data is data of preset bytes obtained by converting the fragment length of the current fragment message.
[0090] Exemplarily, in this embodiment, the last split message of the current fragment message is XORed with the encryption factor of the current fragment message, and the XOR message formed is used as the encryption factor of the next fragment message. In this way, the encryption factors between the fragment messages are associated, thereby improving the security of the data. In addition, in this embodiment, for the subsequent decryption process of the message, it is also necessary to obtain the fragment length of the current fragment message and convert it into length data of preset bytes; if the fragment message is 200 bytes, it can be converted into a two-byte length value 0x00C8. After obtaining each XOR message, length data and encryption factor of the next fragment message, these three values are combined to form a fragment encrypted message, and its combination form can be XOR message + length data + encryption factor of the next fragment message.
[0091] Step S300, adding an identification header to each fragmented encrypted message to form multiple fragmented encrypted messages corresponding to the current target message.
[0092] In order to correctly identify the message during subsequent decryption, in this embodiment, an identification header needs to be added to each fragmented encrypted message, wherein the identification header is formed according to the fragment sequence number of the current fragmented message and the timestamp formed when the current fragment sends the encrypted message; wherein the number of bytes occupied by the identification header is also preset, which can be 2 bytes, 4 bytes, 8 bytes, etc. The formed identification header is added to the corresponding fragmented encrypted message to form the corresponding fragmented sent encrypted message.
[0093] After each fragment message is encrypted according to the above encryption method to form a corresponding fragment and send an encrypted message, the sending process begins.
[0094] For example, Fig. 9 As shown, the message sending method includes:
[0095] Step S600, adding a message ID to the encrypted message sent for each fragment.
[0096] Step S700, in response to a message sending operation, at least one fragmented encrypted message is randomly obtained from a corresponding sending queue in sequence for sending.
[0097] Before sending, multiple fragmented encrypted messages corresponding to each target message can be sequentially placed in a sending queue. When the first network device sends the target message, a random sending method is adopted, that is, the fragmented encrypted messages in the sending queue are not sent in the order of arrangement. At least one fragmented encrypted message is randomly selected from the unsent fragmented encrypted messages in the sending queue for sending each time. This embodiment first randomly fragments and then encrypts, and then sends the fragmented encrypted messages out of order after encryption, thereby achieving the effect of resisting illegal monitoring of links.
[0098] In some implementations, before the fragmented encrypted message is placed in the sending queue, a message ID may be added to each fragmented encrypted message, wherein each target message corresponds to a message ID. In this way, it is possible to distinguish which target message the fragmented encrypted message belongs to. In this way, if fragmented encrypted messages of multiple target messages need to be sent at the same time, they can be distinguished by the message ID on the fragmented encrypted message.
[0099] In some implementations, during the period of sending the encrypted message in fragments, an obfuscated data packet is sent simultaneously, wherein the encryption factor and data segment of the obfuscated data packet are both incorrect data, which can increase the difficulty of reverse decryption by an eavesdropper.
[0100] Among them, obfuscated packets are some meaningless data, repeated data, or data generated according to a certain pattern. These data have no actual meaning or are irrelevant to the information to be transmitted. Obfuscated packets will be encapsulated into a format similar to the normal fragmented encrypted message. In the actual process of sending encrypted messages, the program will insert obfuscated packets at a specific time point. The specific time to insert obfuscated packets can be determined in the following ways: Random selection: During the entire process of sending encrypted messages, the program can randomly select a time point to insert obfuscated packets; Interleaved with encrypted messages: Obfuscated packets can be sent interleaved with normal encrypted fragments, so that even if the listener intercepts the message, it is difficult to distinguish which are the real encrypted fragments and which are obfuscated packets; Insertion at a specific time: A time window can be set, and within this window, a group of obfuscated packets is inserted after each group of normal encrypted fragments are sent.
[0101] After the second network device receives all the fragmented encrypted messages corresponding to the target message, it starts to decrypt the received encrypted message. It should be noted that when the first network device receives the encrypted message, the fragmented encrypted messages with the unified message ID are placed in the same receiving queue, and the received fragmented encrypted messages can be distinguished by the message ID on the fragmented encrypted messages, so as to avoid the influence between different target messages.
[0102] Exemplary, such as Figure 5 As shown, the decryption step of the received encrypted message includes: step S400, integrating the encrypted messages sent in multiple fragments according to the identification header to form an encrypted message consistent with the target message sequence.
[0103] In this step, by identifying the fragment sequence number and timestamp of each fragment sending the encrypted message, the order of the fragments sending the encrypted message can be distinguished, and then the encrypted message consistent with the target message order can be obtained.
[0104] If the received encrypted message includes not only fragmented encrypted messages but also obfuscated data packets, then since the number of bytes occupied by the identification header is fixed, by obtaining the data of the occupied bytes of the identification header agreed in each fragmented encrypted message and obfuscated data packet, and then based on the rules formed by the fragment sequence number and timestamp, it is possible to preliminarily identify which are obfuscated data packets and then remove them.
[0105] Step S500, obtaining the fragment length and encryption factor in the encrypted message sent by each fragment, and decrypting the current encrypted message according to the fragment length and encryption factor in the encrypted message sent by each fragment in combination with a preset logical operation to obtain a decrypted target message.
[0106] Exemplary, such as Figure 6 As shown, step S500 includes:
[0107] Step S510, combining the generation rule of the encrypted message sent by the fragments, obtain the corresponding message to be decrypted, the fragment length and the encryption factor from each fragmented encrypted message.
[0108] Since the target message is encrypted and generated according to certain rules, the bytes in which the message to be decrypted, the fragment length and the encryption factor are respectively contained in the fragmented encrypted message can be obtained according to the generation rules.
[0109] For example, Figure 7 As shown, step S510 specifically includes:
[0110] Step S511, in combination with the generation rule of the fragmented encrypted message, obtain the fragment length of the fragmented message corresponding to the current fragmented encrypted message contained in the current fragmented encrypted message, and the encryption factor of the fragmented message corresponding to the next fragmented encrypted message of the current fragmented encrypted message.
[0111] Since the generation of the fragmented encrypted message is obtained by adding an identification header to the corresponding fragmented encrypted message, and the fragmented encrypted message is formed by combining the corresponding XOR message, length data and the associated encryption factor of the next fragmented message, that is to say, the combination rule of the fragmented encrypted message is determined. According to the combination rule, the fragment length and encryption factor in the fragmented encrypted message can be obtained. Among them, the fragment length is the fragment length of the fragmented message corresponding to the current fragmented encrypted message; the encryption factor obtained is the encryption factor of the fragmented message corresponding to the next fragmented encrypted message of the current fragmented encrypted message.
[0112] Step S512: remove the identification header, the fragment length and the encryption factor contained in the encrypted message sent by the current fragment, so as to obtain the message to be decrypted corresponding to the encrypted message sent by the current fragment.
[0113] Since each fragmented encrypted message is formed by combining the corresponding identification message, XOR message, length data and the associated encryption factor of the next fragment message, the message to be decrypted corresponding to each fragmented encrypted message can be obtained by removing the identification header, length data and the associated encryption factor of the next fragment message in each fragmented encrypted message.
[0114] Step S520, split each message to be decrypted to form a plurality of split decrypted messages including the target number of bytes.
[0115] In this step, the message to be decrypted is split in order from front to back, and the number of bytes of each split decrypted message obtained by splitting is the same as the number of bytes of the encryption factor, so as to facilitate the subsequent decryption process.
[0116] Step S530, based on each split decrypted message corresponding to the encrypted message sent by the current segment, the segment length and the encryption factor, the encrypted message sent by the current segment is decrypted in combination with an XOR operation to obtain a target decrypted split message.
[0117] For example, Figure 8 As shown, step S530 specifically includes:
[0118] Step S531, performing XOR on the encryption factors corresponding to each split decrypted message and the current message to be decrypted according to a preset rule to obtain multiple XOR decrypted messages.
[0119] The encryption factor corresponding to the current message to be decrypted is obtained from the encrypted message sent by the previous fragment of the encrypted message corresponding to the fragment of the currently split decrypted message.
[0120] For the first fragment in the receiving queue that sends an encrypted message, the encryption factor of the corresponding message to be decrypted is the initial encryption factor; the initial encryption factor can be an encryption factor agreed upon by the first network device end and the second network device end; or it can be sent to the second network device end together with the fragmented encrypted message sent by the first network device end.
[0121] As for the method of generating multiple XOR decryption messages, the method adopted in this embodiment is: each split decryption message is XORed with the corresponding encryption factor respectively to form multiple XOR decryption messages.
[0122] In some embodiments, since the decryption method and encryption method of this embodiment correspond to each other, and since the order of each split decrypted message is consistent with the order of each fragment message in the encryption step, the multiple split messages in the encryption process corresponding to the multiple XOR decrypted messages obtained in this step can be determined, and the multiple XOR decrypted messages obtained in this step should be the same as the multiple split messages in the encryption process. Therefore, after obtaining the multiple XOR decrypted messages, the obtained multiple XOR decrypted messages can be verified. During the verification, the multiple split messages can be XORed in sequence, and the multiple XOR decrypted messages can be XORed in sequence. If the result of XORing the multiple split messages in sequence is the same as the result of XORing the multiple XOR decrypted messages in sequence, it means that the corresponding decrypted split message formed subsequently is correct. If it is inconsistent, it means that an error occurs in the transmitted target message, and the subsequent received fragmented encrypted message with the current message ID will no longer be processed.
[0123] Step S532: Combine multiple XOR decrypted messages corresponding to each split decrypted message in sequence to form a decrypted split message.
[0124] Step S533, determining the number of supplementary bytes of the supplementary preset data included in the decrypted split message according to the fragment length, and deleting the number of supplementary bytes at the end of the decrypted split message to form a target decrypted split message.
[0125] Because during the encryption process, when each fragment message is split to form multiple split messages including the target number of bytes, if the number of bytes of the last split message is less than the target number of bytes, preset data is added after the last split message to make the number of bytes of the last split message equal to the target number of bytes; therefore, during decryption, the added preset data needs to be deleted.
[0126] Step S540, combining the multiple target decrypted split messages in order to obtain a decrypted target message.
[0127] It can be understood that the decryption process of this embodiment is set corresponding to the encryption process, that is, the decryption process in this embodiment is set according to the encryption process.
[0128] The present application randomly fragments the target message, and then splits each fragment message to obtain multiple fragment messages with the same number of bytes corresponding to each fragment message, and each fragment message in each fragment message is XORed with the encryption factor of the current fragment message, thereby forming multiple XOR messages corresponding to the current fragment message, and the encryption factor of each fragment message is not the same. The encryption factor of the next fragment message of the current fragment message is the data generated by XORing the last fragment message of the current fragment message with the encryption factor of the current fragment message. It can be seen that the encryption factors of each fragment message are interrelated. The embodiment of the present application first randomly fragments the message, then splits the randomly fragmented fragmented message, and then XORs the split messages obtained with the encryption factors of the current fragmented message, thereby increasing the difficulty of deciphering the target message even if it is monitored during transmission; further, during the encryption process, the encryption factors of each fragmented message are not the same, but are indeed related, so that during decryption, deciphering can be facilitated based on the correlation of the encryption factors in each fragmented message, but since the encryption factors of each fragmented message are different, the difficulty of the message being monitored and deciphered is further increased.
[0129] In addition, when the embodiment of the present application sends the encrypted message, since the encrypted message is generated in multiple fragments, when sending the message, the present application does not send it in sequence, but randomly sends the encrypted message to multiple fragments. When sending, the present application can also add obfuscation packets to further avoid the risk of being monitored during the message transmission process. Even if it is monitored, the difficulty of deciphering can be increased through the encryption method and random sending method of the present application.
[0130] The present application also provides a terminal device. Exemplarily, the terminal device includes a processor and a memory, wherein the memory stores a computer program, and the processor runs the computer program, thereby enabling the terminal device to execute the above-mentioned message encryption method, message decryption method and message sending method.
[0131] Among them, the processor can be an integrated circuit chip with signal processing capabilities. The processor can be a general-purpose processor, including a central processing unit (CPU), a graphics processing unit (GPU) and a network processor (NP), a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or at least one of other programmable logic devices, discrete gates or transistor logic devices, and discrete hardware components. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc., which can implement or execute the disclosed methods, steps and logic block diagrams in the embodiments of the present application.
[0132] The memory may be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), etc. The memory is used to store a computer program, and the processor may execute the computer program accordingly after receiving an execution instruction.
[0133] The present application also provides a computer-readable storage medium for storing the computer program used in the above-mentioned terminal device. For example, the computer-readable storage medium may include, but is not limited to, various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0134] In several embodiments provided in the present application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and structure diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of a code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in an alternative implementation, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the structure diagram and / or the flow diagram, and the combination of boxes in the structure diagram and / or the flow diagram, can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.
[0135] In addition, the functional modules or units in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
[0136] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or the part of the technical 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 smart phone, a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in the various embodiments of the present application.
[0137] The above description is only a specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application.
Claims
1. A message encryption method, characterized in that: include: Fragmenting the target message to form multiple fragmented messages; According to the fragment length and encryption factor of each fragment message, the corresponding fragment message is encrypted in combination with a preset logical operation to generate a corresponding fragment encrypted message; wherein the encryption factor of the first fragment message is an initial encryption factor, and the encryption factors of the remaining fragment messages are data associated with the encryption factor of the previous fragment message; An identification header is added to each of the fragmented encrypted messages to form multiple fragmented sending encrypted messages corresponding to the current target message.
2. The message encryption method according to claim 1, characterized in that: The target message is fragmented to form a plurality of fragmented messages, including: Determine the byte number interval and / or the number of fragments of each fragment message; The target message is fragmented according to the byte number interval and / or the number of fragments to generate a plurality of the fragmented messages.
3. The message encryption method according to claim 1, characterized in that: The encrypting the corresponding fragment message according to the fragment length and the encryption factor of each fragment message in combination with a preset logical operation to generate a corresponding fragment encrypted message includes: Splitting each of the fragment messages according to a preset splitting rule to form a plurality of split messages including a target number of bytes; and performing an XOR operation on each of the split messages and the encryption factor corresponding to the current fragment message according to a preset logical operation to obtain the associated encryption factors of the plurality of XOR messages and the next fragment message; Combine the multiple XOR messages, the length data of the current fragment message and the associated encryption factor of the next fragment message to form the fragment encrypted message; wherein the length data is the preset byte data obtained by converting the fragment length of the current fragment message.
4. The message encryption method according to claim 3, characterized in that: The step of splitting each of the fragment messages according to a preset splitting rule to form a plurality of split messages including a target number of bytes; and performing an XOR operation on each of the split messages and an encryption factor corresponding to the current fragment message according to a preset logical operation to obtain the associated encryption factor of the plurality of XOR messages and the next fragment message, including: Splitting each of the fragmented messages to form a plurality of the split messages including the target number of bytes; wherein the target number of bytes is the same as the number of bytes of the encryption factor; if the number of bytes of the last split message is less than the target number of bytes, adding preset data after the last split message so that the number of bytes of the last split message is equal to the target number of bytes; Performing XOR on each of the split messages and the encryption factor of the current fragment message to form a plurality of XOR messages; The XOR message formed by XORing the last split message of the current fragment message with the encryption factor is used as the associated encryption factor of the next fragment message.
5. The message encryption method according to claim 1, characterized in that: The step of adding an identification header to each of the fragmented encrypted messages to form a fragmented encrypted message includes: Form an identification header according to the fragment sequence number of the current fragment message and the timestamp when the current fragment sends the encrypted message; The identification header is added to the corresponding fragmented encrypted message to form the fragmented sending encrypted message.
6. A message decryption method, characterized in that: Used to decrypt a message encrypted by the message encryption method according to any one of claims 1 to 5, comprising: Integrate and process the encrypted messages sent by multiple fragments according to the identification packet header to form an encrypted message that is consistent with the order of the target message; Obtain the fragment length and encryption factor in the encrypted message sent by each fragment, and decrypt the current encrypted message according to the fragment length and encryption factor in the encrypted message sent by each fragment in combination with a preset logical operation to obtain a decrypted target message.
7. The message decryption method according to claim 6, characterized in that: The obtaining of the fragment length and the encryption factor in the encrypted message sent by each fragment, and decrypting the current encrypted message according to the fragment length and the encryption factor in the encrypted message sent by each fragment in combination with a preset logical operation to obtain a decrypted target message, includes: In combination with the generation rule of the encrypted message sent by the fragments, the corresponding message to be decrypted, the fragment length and the encryption factor are obtained from each of the encrypted messages sent by the fragments; Splitting each of the to-be-decrypted messages to form a plurality of split decrypted messages including a target number of bytes; Based on each split decrypted message corresponding to the current segmented encrypted message, the segment length and the encryption factor, the current segmented encrypted message is decrypted in combination with an XOR operation to obtain a target decrypted split message; Combining the plurality of target decrypted split messages in sequence to obtain a decrypted target message.
8. The message decryption method according to claim 7, characterized in that: The generating rule of sending the encrypted message in combination with the fragments, obtaining the corresponding message to be decrypted, the fragment length and the encryption factor from each of the fragments sending the encrypted message, comprises: In combination with the generation rule of the fragmented encrypted message, obtain the fragment length of the fragmented message corresponding to the current fragmented encrypted message contained in the current fragmented encrypted message, and the encryption factor of the fragmented message corresponding to the next fragmented encrypted message of the current fragmented encrypted message; Removing the identification header, the fragment length and the encryption factor contained in the encrypted message currently sent by the fragment, so as to obtain the message to be decrypted corresponding to the encrypted message currently sent by the fragment; The decrypting the encrypted message sent by the current segment based on each split decrypted message corresponding to the encrypted message sent by the current segment, the segment length and the encryption factor, and decrypting the encrypted message sent by the current segment in combination with an XOR operation to obtain a target decrypted split message, including: Performing XOR on the encryption factors corresponding to each of the split decrypted messages and the current message to be decrypted according to a preset rule to obtain multiple XOR decrypted messages; Combining the multiple XOR decrypted messages corresponding to each of the split decrypted messages in order to form a decrypted split message; The number of supplementary bytes of the supplementary preset data included in the decrypted split message is determined according to the fragment length, and the number of supplementary bytes following the decrypted split message is deleted to form a target decrypted split message.
9. A message sending method, characterized in that: include: In response to a message sending operation, at least one of the fragmented encrypted messages is randomly obtained from the corresponding sending queue for sending; wherein, the fragmented encrypted message is obtained according to the message encryption method according to any one of claims 1-5; the sending queue is a queue formed by all the fragmented encrypted messages corresponding to the current target message.
10. The message sending method according to claim 9, characterized in that: Before the step of sequentially obtaining at least one of the fragmented encrypted messages from the corresponding sending queue for sending, the step further includes: Add a message ID to the encrypted message sent for each fragment; wherein each target message corresponds to a message ID; The encrypted message is sent in combination with the obfuscated data packet.