CN111865557B - Verification code generation method and device - Google Patents

Verification code generation method and device Download PDF

Info

Publication number
CN111865557B
CN111865557B CN201910331809.5A CN201910331809A CN111865557B CN 111865557 B CN111865557 B CN 111865557B CN 201910331809 A CN201910331809 A CN 201910331809A CN 111865557 B CN111865557 B CN 111865557B
Authority
CN
China
Prior art keywords
data
check code
byte length
original
byte
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910331809.5A
Other languages
Chinese (zh)
Other versions
CN111865557A (en
Inventor
黄荣宇
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hangzhou Ezviz Software Co Ltd
Original Assignee
Hangzhou Ezviz Software Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hangzhou Ezviz Software Co Ltd filed Critical Hangzhou Ezviz Software Co Ltd
Priority to CN201910331809.5A priority Critical patent/CN111865557B/en
Publication of CN111865557A publication Critical patent/CN111865557A/en
Application granted granted Critical
Publication of CN111865557B publication Critical patent/CN111865557B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/06Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols the encryption apparatus using shift registers or memories for block-wise or stream coding, e.g. DES systems or RC4; Hash functions; Pseudorandom sequence generators
    • H04L9/0643Hash functions, e.g. MD5, SHA, HMAC or f9 MAC
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/04Protocols for data compression, e.g. ROHC

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Power Engineering (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

The embodiment of the invention provides a method and a device for generating check codes, which are used for calculating acquired original data by utilizing a summary algorithm to obtain information summary data corresponding to the original data, and carrying out secondary compression operation on the information summary data according to a preset byte length to generate the check codes corresponding to the original data, wherein the preset byte length is smaller than the byte length of the information summary data, and the byte length of the check codes is equal to the preset byte length. The method not only ensures that the original data is not easy to be tampered by a digest algorithm, but also compresses the byte length of the information digest data generated by the digest algorithm to obtain a check code with shorter byte length, so that the data packet formed by the original data and the check code is smaller during data transmission, and therefore, the data transmission efficiency is improved on the basis of ensuring the safety.

Description

Verification code generation method and device
Technical Field
The present invention relates to the field of communications technologies, and in particular, to a method and an apparatus for generating a check code.
Background
In order to ensure the safety and effectiveness of data transmission and prevent data from being tampered maliciously in the transmission process, data is usually checked. In the conventional verification process, a digest algorithm (for example, MD (Message Digest Algorithm, message digest algorithm), SHA (Secure Hash Algorithm ), MAC (Message Authentication Codes, hash algorithm with message authentication code) and the like) is used to operate on original data to obtain information digest data corresponding to the original data, and the information digest data is used as a verification code of the original data, and is packaged with the original data into a data packet to be transmitted. After receiving the data packet, the receiving end splits the data part and the check code part from the data packet, and then calculates the data part by adopting the same summarization algorithm to obtain information summary data. And comparing the information abstract data with the split check code part, and if the information abstract data is different from the split check code part, indicating that the original data is tampered.
In the above process, although the security of the summary algorithm is higher, the information summary data has a fixed length and is generally longer, so that the length of the information summary data directly serving as a check code is longer, the packaged data packet is generally larger, and the data transmission efficiency is lower because the packaged data packet occupies larger bandwidth resources during transmission.
Disclosure of Invention
The embodiment of the invention aims to provide a check code generation method and device for improving data transmission efficiency. The specific technical scheme is as follows:
in a first aspect, an embodiment of the present invention provides a method for generating a check code, where the method includes:
acquiring original data;
calculating the original data by using a summary algorithm to obtain information summary data corresponding to the original data;
performing secondary compression operation on the information abstract data according to a preset byte length, and generating a check code corresponding to the original data, wherein the preset byte length is smaller than the byte length of the information abstract data, and the byte length of the check code is equal to the preset byte length.
Optionally, the performing a secondary compression operation on the information summary data according to a preset byte length to generate a check code corresponding to the original data includes:
selecting a secondary compression operation algorithm corresponding to the preset byte length according to the preset byte length, wherein the byte length of an operation result of the secondary compression operation algorithm is equal to the preset byte length;
and performing secondary compression operation on the information abstract data by using the secondary compression operation algorithm to generate a check code corresponding to the original data.
Optionally, the secondary compression operation includes a bit operation;
and performing secondary compression operation on the information abstract data according to the preset byte length to generate a check code corresponding to the original data, wherein the check code comprises the following components:
calculating the size of a sliding window according to the byte length of the information abstract data and the preset byte length;
extracting data in a sliding window according to the size of the sliding window from the first byte of the information abstract data;
performing bit operation on the data in the sliding window by using a preset bit operation algorithm to generate check data with the length of 1 byte;
shifting the sliding window by one byte, re-executing the bit operation on the data in the sliding window by using a preset bit operation algorithm, and generating check data with the length of 1 byte until the bit operation is completed on the last data in the information abstract data;
and forming a check code corresponding to the original data according to each generated check data.
Optionally, after performing a secondary compression operation on the information summary data according to the preset byte length to generate a check code corresponding to the original data, the method further includes:
packaging the original data and the check code to obtain a data packet to be transmitted;
and sending the data packet to be transmitted.
Optionally, the acquiring the raw data includes:
receiving a data packet to be checked;
splitting the data packet to be checked to obtain original data and an original check code;
after performing secondary compression operation on the information abstract data according to the preset byte length and generating the check code corresponding to the original data, the method further comprises the following steps:
comparing the generated check code with the original check code;
and judging whether the data packet to be checked is valid or not according to the comparison result.
In a second aspect, an embodiment of the present invention provides a check code generating apparatus, where the apparatus includes:
the acquisition module is used for acquiring the original data;
the computing module is used for calculating the original data by utilizing a summary algorithm to obtain information summary data corresponding to the original data;
the generation module is used for carrying out secondary compression operation on the information abstract data according to the preset byte length, generating a check code corresponding to the original data, wherein the preset byte length is smaller than the byte length of the information abstract data, and the byte length of the check code is equal to the preset byte length.
Optionally, the generating module is specifically configured to:
selecting a secondary compression operation algorithm corresponding to the preset byte length according to the preset byte length, wherein the byte length of an operation result of the secondary compression operation algorithm is equal to the preset byte length; performing secondary compression operation on the information abstract data by using the secondary compression operation algorithm to generate a check code corresponding to the original data;
or,
calculating the size of a sliding window according to the byte length of the information abstract data and the preset byte length; extracting data in a sliding window according to the size of the sliding window from the first byte of the information abstract data; performing bit operation on the data in the sliding window by using a preset bit operation algorithm to generate check data with the length of 1 byte; shifting the sliding window by one byte, re-executing the bit operation on the data in the sliding window by using a preset bit operation algorithm, and generating check data with the length of 1 byte until the bit operation is completed on the last data in the information abstract data; and forming a check code corresponding to the original data according to each generated check data.
Optionally, the apparatus further includes:
the packaging module is used for packaging the original data and the check code to obtain a data packet to be transmitted;
and the sending module is used for sending the data packet to be transmitted.
Optionally, the acquiring module is specifically configured to:
receiving a data packet to be checked;
splitting the data packet to be checked to obtain original data and an original check code;
the apparatus further comprises:
the comparison module is used for comparing the generated check code with the original check code;
and the judging module is used for judging whether the data packet to be checked is valid or not according to the comparison result.
In a third aspect, an embodiment of the present invention provides a network electronic device, including a processor and a memory, where the memory stores machine executable instructions executable by the processor, where the machine executable instructions are loaded and executed by the processor to implement the method provided by the first aspect of the embodiment of the present invention.
In a fourth aspect, embodiments of the present invention provide a machine-readable storage medium having stored thereon machine-executable instructions which, when loaded and executed by a processor, implement the method provided by the first aspect of the embodiments of the present invention.
According to the method and the device for generating the check code, the obtained original data is operated by using a summary algorithm to obtain information summary data corresponding to the original data, the information summary data is operated in a secondary compression mode according to the preset byte length to generate the check code corresponding to the original data, wherein the preset byte length is smaller than the byte length of the information summary data, and the byte length of the check code is equal to the preset byte length. On the basis of generating information abstract data by using an abstract algorithm, performing secondary compression operation on the information abstract data according to a preset byte length, and performing length compression on the information abstract data to obtain a check code with a shorter byte length. The method not only ensures that the original data is not easy to be tampered by a digest algorithm, but also compresses the byte length of the information digest data generated by the digest algorithm to obtain a check code with shorter byte length, so that the data packet formed by the original data and the check code is smaller during data transmission, and therefore, the data transmission efficiency is improved on the basis of ensuring the safety.
Drawings
In order to more clearly illustrate the embodiments of the invention or the technical solutions in the prior art, the drawings that are required in the embodiments or the description of the prior art will be briefly described, it being obvious that the drawings in the following description are only some embodiments of the invention, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flow chart of a method for generating check codes according to an embodiment of the present invention;
fig. 2 is a schematic flow chart of data transmission by a network electronic device at a data transmitting end according to an embodiment of the present invention;
fig. 3 is a schematic flow chart of a data receiving end network electronic device receiving data according to an embodiment of the present invention;
FIG. 4 is a flowchart illustrating an example of a method for generating a check code according to an embodiment of the present invention;
FIG. 5 is a schematic diagram of generating a check code of 2 bytes in length using a sliding window technique according to an embodiment of the present invention;
FIG. 6 is a schematic diagram of a check code generating device according to an embodiment of the present invention;
fig. 7 is a schematic structural diagram of a network electronic device according to an embodiment of the present invention.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present invention, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
In order to improve data transmission efficiency, the embodiment of the invention provides a method and a device for generating check codes, network electronic equipment and a machine-readable storage medium. The method for generating the check code provided by the embodiment of the invention is first described below.
The execution main body of the check code generation method provided by the embodiment of the invention can be network electronic equipment, such as a client, a router, a switch, a server and the like, and can be a transmitting end of data transmission or a receiving end of data transmission. The mode of implementing the check code generation method provided by the embodiment of the invention can be at least one of software, a hardware circuit and a logic circuit arranged in the network electronic equipment.
As shown in fig. 1, a method for generating a check code according to an embodiment of the present invention may include the following steps.
S101, acquiring original data.
The execution main body of the check code generation method provided by the embodiment of the invention can be a transmitting end of data transmission or a receiving end of data transmission. For a transmitting end, the original data is the data to be transmitted; for the receiving end, the original data is a data part obtained by splitting the data packet after receiving the data packet sent by the sending end.
S102, calculating the original data by using a summary algorithm to obtain information summary data corresponding to the original data.
The digest algorithm is an important branch in the cryptographic algorithm, and is used for realizing functions of data signing, data integrity verification and the like by extracting specified information from original data, has high safety and reliability and is commonly used for encryption of sensitive information, and is also called as a Hash algorithm or a Hash algorithm. Common digest algorithms are MD algorithm, SHA algorithm, MAC algorithm, etc., and are not illustrated here.
After the original data is subjected to the operation of the summarization algorithm, information summary data corresponding to the original data can be obtained, the obtained information summary data has a fixed byte length, and the byte length of the information summary data is generally longer, for example, the byte length of the information summary data calculated by the MD algorithm is at least 16 bytes, and the byte length of the information summary data calculated by the SHA algorithm is at least 20 bytes.
And S103, performing secondary compression operation on the information abstract data according to a preset byte length to generate a check code corresponding to the original data, wherein the preset byte length is smaller than the byte length of the information abstract data, and the byte length of the check code is equal to the preset byte length.
The preset byte length is the byte length reached by the expected check code, and is usually a parameter manually input by a technician according to actual requirements, and can also be an attribute parameter configured on the network electronic equipment. The secondary compression operation is a compression operation mode for compressing the byte length of the information abstract data, and the check code obtained after compression has a shorter byte length compared with the information abstract data before compression. The byte length of the operation result obtained by different secondary compression operations is different, for example, the byte length of the operation result of XOR (exclusive or) operation, SUM (summation) operation, odd-even operation and the like is generally 1 byte, and the byte length of the operation result of complex compound operation is 2 bytes or 3 bytes. The byte length of the information abstract data can be compressed to a preset byte length by performing secondary compression operation on the information abstract data, so that the actual requirements of technicians or the configuration of network electronic equipment are met.
Optionally, S103 may be specifically implemented by the following steps:
selecting a secondary compression operation algorithm corresponding to the preset byte length according to the preset byte length, wherein the byte length of an operation result of the secondary compression operation algorithm is equal to the preset byte length; and performing secondary compression operation on the information abstract data by using a secondary compression operation algorithm to generate a check code corresponding to the original data.
The network electronic device may store, in advance, secondary compression operation algorithms corresponding to different byte lengths, where the secondary compression operation algorithms may include a bit operation algorithm, a compound operation algorithm, and the like, for example, an XOR operation corresponding to 1 byte length, a SUM operation, a compound operation corresponding to 2 byte lengths, and the like. And selecting a corresponding secondary compression operation algorithm according to the preset byte length to perform secondary compression operation on the information abstract data to obtain a check code corresponding to the original data. For example, the preset byte length is 1 byte, and the corresponding XOR operation may be selected to perform a secondary compression operation on the information summary data, so as to obtain a check code with a byte length of 1 byte.
Alternatively, the secondary compression operation may comprise a bit operation. Correspondingly, S103 may be specifically implemented by the following steps:
first, calculating the size of a sliding window according to the byte length of the information abstract data and the preset byte length.
And secondly, starting from the first byte of the information abstract data, and extracting the data in the sliding window according to the size of the sliding window.
Thirdly, carrying out bit operation on the data in the sliding window by using a preset bit operation algorithm to generate check data with the length of 1 byte.
And step four, moving the sliding window one byte back, and re-executing the step three until the bit operation is completed on the last data in the information abstract data.
And fifthly, forming a check code corresponding to the original data according to the generated check data.
In one implementation manner of the embodiment of the present invention, when performing the secondary compression operation, an XOR operation, a SUM operation, or the like may be used to obtain a bit operation of the calculation result with 1 byte length, and a primary bit operation may be performed to obtain a check data. According to the byte length of the information abstract data and the preset byte length, the size of the sliding window of the data subjected to one bit operation can be calculated, for example, the byte length of the information abstract data is 16 bytes, the preset byte length is 2 bytes, and the size of the sliding window d=16-2+1=15, namely, 15 data are required to be extracted from the information abstract data at one time to carry out the bit operation.
Starting from the first byte of the information abstract data, extracting data in the sliding window according to the size of the sliding window, performing bit operation to obtain check data with 1 byte length, sliding the sliding window (moving backwards by one byte), extracting data in the sliding window again, performing bit operation to obtain check data with 1 byte length, and combining the check data until each data in the information abstract data completes bit operation to obtain a plurality of check data, wherein the number of the check data is equal to the preset byte length, so that the check code with the byte length of the preset byte length can be obtained. The combination mode of the check data is to arrange and combine the check data in sequence from front to back according to the sequence of calculation.
By applying the embodiment of the invention, the obtained original data is operated by using a summary algorithm to obtain the information summary data corresponding to the original data, and the information summary data is operated by secondary compression according to the preset byte length to generate the check code corresponding to the original data, wherein the preset byte length is smaller than the byte length of the information summary data, and the byte length of the check code is equal to the preset byte length. On the basis of generating information abstract data by using an abstract algorithm, performing secondary compression operation on the information abstract data according to a preset byte length, and performing length compression on the information abstract data to obtain a check code with a shorter byte length. The method not only ensures that the original data is not easy to be tampered by a digest algorithm, but also compresses the byte length of the information digest data generated by the digest algorithm to obtain a check code with shorter byte length, so that the data packet formed by the original data and the check code is smaller during data transmission, and therefore, the data transmission efficiency is improved on the basis of ensuring the safety.
In the traditional check code generation method based on the simple digest algorithm, although the digest algorithm has higher safety and reliability, the byte length of the information digest data directly used as the check code is longer; the check code generation method based on simple bit operation has the advantages that although the calculated check code has the byte length of only 1 byte, the safety is not high, the risk of being tampered exists, and the flexibility is poor. According to the embodiment of the invention, after the information abstract data corresponding to the original data is obtained by calculation through the abstract algorithm, the information abstract data is subjected to secondary compression operation, so that the advantages of safety and reliability of the abstract algorithm and the advantage of shorter byte length of the secondary compression operation are combined, and the byte length of the information abstract data is effectively compressed on the basis of ensuring the safety. If any modification is made to the original data, even if only 1 byte is modified, the resulting check code will be quite different, and due to the irreversibility of the digest algorithm, it is very difficult for an attacker to forge the corresponding original data even if he knows the check code.
According to the embodiment of the invention, after the operation of the summary algorithm is carried out on the original data, the secondary compression operation is carried out according to the actual demand, so that the check code with byte length meeting the demand is obtained, the flexibility of the check code generation process is enhanced, and the actual demand can be flexibly met. And by compressing the information abstract data, the byte length of the check code can be compressed to 1 byte at the shortest, so that the length of the check code is greatly optimized, and the check code is short.
Based on the embodiment shown in fig. 1, the embodiment of the invention can be applied to the network electronic equipment at the data transmitting end, and the data is transmitted after the check code is generated. Accordingly, the flow of data transmission by the network electronic device at the data transmitting end is shown in fig. 2, and the method comprises the following steps.
S201, acquiring original data.
S202, the original data is operated by utilizing a summary algorithm, and information summary data corresponding to the original data is obtained.
And S203, performing secondary compression operation on the information abstract data according to a preset byte length to generate a check code corresponding to the original data, wherein the preset byte length is smaller than the byte length of the information abstract data, and the byte length of the check code is equal to the preset byte length.
S201 to S203 in the embodiment shown in fig. 2 are the same as S101 to S103 in the embodiment shown in fig. 1, and are not described here again. The original data is the original data which needs to be transmitted to the receiving end.
S204, packaging the original data and the check code to obtain a data packet to be transmitted.
After the check code is obtained through calculation, the original data and the check code can be packaged, the packaging mode can be the mode of connecting the original data and the check code end to end, and the packaging mode can be the mode of packaging other data. After the data encapsulation, the data packet to be transmitted can be obtained.
S205, sending the data packet to be transmitted.
After the data sending end network electronic equipment obtains the data packet to be transmitted through encapsulation, the data packet can be sent to the data receiving end network electronic equipment, in order to strengthen data security, the data packet can be encrypted before being sent, and the encrypted data packet is sent to the data receiving end network electronic equipment.
Correspondingly, the embodiment of the invention can also be applied to the network electronic equipment at the data receiving end, and the flow of the network electronic equipment at the data receiving end for receiving the data is shown in the figure 3 and comprises the following steps.
S301, receiving a data packet to be checked.
S302, splitting the data packet to be checked to obtain the original data and the original check code.
For the network electronic equipment at the data receiving end, the original data is obtained by splitting the data packet to be checked after the data packet to be checked sent by the network electronic equipment at the data sending end is received, and the original check code can be split when the data packet is split. The specific data packet splitting manner can be split according to a predefined rule, for example, if the last byte in the predefined data packet is the original check code, the original check code of the last byte and the original data of all the preceding bytes can be split.
S303, calculating the original data by using a summary algorithm to obtain information summary data corresponding to the original data.
S304, performing secondary compression operation on the information abstract data according to a preset byte length to generate a check code corresponding to the original data, wherein the preset byte length is smaller than the byte length of the information abstract data, and the byte length of the check code is equal to the preset byte length.
For the split original data, a check code generation mode of the embodiment shown in fig. 1 can be adopted to generate a check code corresponding to the original data.
S305, comparing the generated check code with the original check code.
S306, judging whether the data packet to be checked is valid or not according to the comparison result.
After the check code corresponding to the original data is generated, the generated check code can be compared with the original check code. If the data packets are the same, indicating that the original data in the data packets to be checked are not tampered, and that the data packets to be checked are valid; if the data packets are different, the original data in the data packets to be checked are maliciously tampered, and the data packets to be checked are invalid.
By applying the embodiment of the invention, the obtained original data is operated by utilizing a summary algorithm to obtain the information summary data corresponding to the original data, and the information summary data is operated by secondary compression according to the preset byte length to generate the check code corresponding to the original data, wherein the preset byte length is smaller than the byte length of the information summary data, and the byte length of the check code is equal to the preset byte length. The verification code generation method is adopted in both the data transmitting end network electronic equipment and the data receiving end network electronic equipment, so that the data packets transmitted between the data transmitting end network electronic equipment and the data receiving end network electronic equipment are ensured to be smaller, and the corresponding data verification mode is adopted, so that the safety and the reliability of the data are ensured.
In order to facilitate understanding, a detailed description of the method for generating a check code according to the embodiment of the present invention is provided below with reference to a specific example, and as shown in fig. 4, the method example includes the following steps.
S401, performing summary algorithm operation on the original data A to obtain information summary data B, wherein the byte length of the information summary data B is B bytes.
In this example, the digest algorithm used is MD5 (fifth version of MD algorithm), and the byte length B of the obtained information digest data B is 16 bytes, which is long.
S402, acquiring a preset byte length c.
In this example, the preset byte length c is 2 bytes of length preset.
S403, determining a sliding window size d=b-c+1.
In this example, b=16, c=2, then the sliding window size d=16-2+1=15.
S404, starting from the first byte of the information abstract data B, extracting data with the length of d bytes according to the sliding window size d, and performing bit operation to obtain check data c1 with the length of 1 byte.
In this example, the bit operation uses an XOR operation, and the byte length of the check data obtained by performing one bit operation on the data in the sliding window is 1 byte.
S405, storing the check data C1 to the first byte position of the final check code C.
S406, judging whether the byte length of the check data stored in the check code C is equal to the preset byte length C, if not, executing S407.
S407, moving the sliding window back by one byte, extracting data with the length of d bytes according to the size d of the sliding window, and performing bit operation to obtain check data c2 with the length of 1 byte.
S408, storing the check data C2 to the second byte position of the final check code C.
After S408 is performed, S406 is performed back until the byte length of the check data stored in the check code C is equal to the preset byte length C, and the calculation is stopped to determine the check code C.
In this example, as shown in fig. 5, the procedure of generating a check code of 2 bytes in length using the sliding window technique, the byte length of the information digest data B obtained by the digest algorithm is 16 bytes (B0 to B15). The first sliding window extracts 15 data from B0 to B14 to perform bit operation to obtain check data c1, and the check data c1 is stored to the first byte position of the final check code; and (3) moving the sliding window backward, extracting 15 data from B1 to B15, performing bit operation to obtain check data c2, and storing the check data c2 to the second byte position of the final check code. As shown in fig. 5, the resulting check code C is a check code of 2 bytes in length.
Corresponding to the above method embodiment, the embodiment of the present invention provides a check code generating device, as shown in fig. 6, which may include:
an acquisition module 610, configured to acquire raw data;
the calculation module 620 is configured to operate on the raw data by using a summary algorithm to obtain information summary data corresponding to the raw data;
the generating module 630 is configured to perform a secondary compression operation on the information summary data according to a preset byte length, and generate a check code corresponding to the original data, where the preset byte length is smaller than the byte length of the information summary data, and the byte length of the check code is equal to the preset byte length.
Optionally, the generating module 630 may specifically be configured to:
selecting a secondary compression operation algorithm corresponding to the preset byte length according to the preset byte length, wherein the byte length of an operation result of the secondary compression operation algorithm is equal to the preset byte length; performing secondary compression operation on the information abstract data by using the secondary compression operation algorithm to generate a check code corresponding to the original data;
or,
calculating the size of a sliding window according to the byte length of the information abstract data and the preset byte length; extracting data in a sliding window according to the size of the sliding window from the first byte of the information abstract data; performing bit operation on the data in the sliding window by using a preset bit operation algorithm to generate check data with the length of 1 byte; shifting the sliding window by one byte, re-executing the bit operation on the data in the sliding window by using a preset bit operation algorithm, and generating check data with the length of 1 byte until the bit operation is completed on the last data in the information abstract data; and forming a check code corresponding to the original data according to each generated check data.
Optionally, the apparatus may further include:
the packaging module is used for packaging the original data and the check code to obtain a data packet to be transmitted;
and the sending module is used for sending the data packet to be transmitted.
Optionally, the acquiring module 610 may specifically be configured to:
receiving a data packet to be checked;
splitting the data packet to be checked to obtain original data and an original check code;
the apparatus may further include:
the comparison module is used for comparing the generated check code with the original check code;
and the judging module is used for judging whether the data packet to be checked is valid or not according to the comparison result.
By applying the embodiment of the invention, the obtained original data is operated by using a summary algorithm to obtain the information summary data corresponding to the original data, and the information summary data is operated by secondary compression according to the preset byte length to generate the check code corresponding to the original data, wherein the preset byte length is smaller than the byte length of the information summary data, and the byte length of the check code is equal to the preset byte length. On the basis of generating information abstract data by using an abstract algorithm, performing secondary compression operation on the information abstract data according to a preset byte length, and performing length compression on the information abstract data to obtain a check code with a shorter byte length. The method not only ensures that the original data is not easy to be tampered by a digest algorithm, but also compresses the byte length of the information digest data generated by the digest algorithm to obtain a check code with shorter byte length, so that the data packet formed by the original data and the check code is smaller during data transmission, and therefore, the data transmission efficiency is improved on the basis of ensuring the safety.
The embodiment of the invention also provides a network electronic device, as shown in fig. 7, which comprises a processor 701 and a memory 702, wherein the memory 702 stores machine executable instructions capable of being executed by the processor 701, and the machine executable instructions are loaded and executed by the processor 701 to implement the check code generation method provided by the embodiment of the invention.
The Memory may include RAM (Random Access Memory ) or NVM (Non-volatile Memory), such as at least one magnetic disk Memory. Optionally, the memory may also be at least one memory device located remotely from the aforementioned processor.
The processor may be a general-purpose processor, including a CPU (Central Processing Unit ), NP (Network Processor, network processor), etc.; but also DSP (Digital Signal Processor ), ASIC (Application Specific Integrated Circuit, application specific integrated circuit), FPGA (Field-Programmable Gate Array, field programmable gate array) or other programmable logic device, discrete gate or transistor logic device, discrete hardware components.
The memory 702 and the processor 701 may be in data transmission through a wired connection or a wireless connection, and the network electronic device and the other devices may communicate through a wired communication interface or a wireless communication interface. Fig. 7 shows only an example of data transmission through a bus, and is not limited to a specific connection method.
In the embodiment of the invention, the processor can realize by reading the machine executable instructions stored in the memory and loading and executing the machine executable instructions: and calculating the acquired original data by using a summary algorithm to obtain information summary data corresponding to the original data, performing secondary compression operation on the information summary data according to a preset byte length, and generating a check code corresponding to the original data, wherein the preset byte length is smaller than the byte length of the information summary data, and the byte length of the check code is equal to the preset byte length. On the basis of generating information abstract data by using an abstract algorithm, performing secondary compression operation on the information abstract data according to a preset byte length, and performing length compression on the information abstract data to obtain a check code with a shorter byte length. The method not only ensures that the original data is not easy to be tampered by a digest algorithm, but also compresses the byte length of the information digest data generated by the digest algorithm to obtain a check code with shorter byte length, so that the data packet formed by the original data and the check code is smaller during data transmission, and therefore, the data transmission efficiency is improved on the basis of ensuring the safety.
In addition, the embodiment of the invention also provides a machine-readable storage medium, and machine-executable instructions are stored in the machine-readable storage medium, and when the machine-executable instructions are loaded and executed by a processor, the method for generating the check code provided by the embodiment of the invention is realized.
In the embodiment of the present invention, the machine-readable storage medium stores machine-executable instructions for executing the check code generation method provided in the embodiment of the present invention at runtime, so that it is possible to implement: and calculating the acquired original data by using a summary algorithm to obtain information summary data corresponding to the original data, performing secondary compression operation on the information summary data according to a preset byte length, and generating a check code corresponding to the original data, wherein the preset byte length is smaller than the byte length of the information summary data, and the byte length of the check code is equal to the preset byte length. On the basis of generating information abstract data by using an abstract algorithm, performing secondary compression operation on the information abstract data according to a preset byte length, and performing length compression on the information abstract data to obtain a check code with a shorter byte length. The method not only ensures that the original data is not easy to be tampered by a digest algorithm, but also compresses the byte length of the information digest data generated by the digest algorithm to obtain a check code with shorter byte length, so that the data packet formed by the original data and the check code is smaller during data transmission, and therefore, the data transmission efficiency is improved on the basis of ensuring the safety.
For the network electronic device and the machine-readable storage medium embodiments, since the method content related thereto is substantially similar to the method embodiments described above, the description is relatively simple, and the relevant points are referred to in the description of the method embodiments.
It is noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
In this specification, each embodiment is described in a related manner, and identical and similar parts of each embodiment are all referred to each other, and each embodiment mainly describes differences from other embodiments. In particular, for apparatus, network electronics, and machine-readable storage medium embodiments, the description is relatively simple as it is substantially similar to method embodiments, with reference to the description of method embodiments in part.
The foregoing description is only of the preferred embodiments of the present invention and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.

Claims (7)

1. A method for generating a check code, the method comprising:
acquiring original data;
calculating the original data by using a summary algorithm to obtain information summary data corresponding to the original data;
calculating a sliding window size according to the byte length of the information abstract data and a preset byte length, wherein the preset byte length is smaller than the byte length of the information abstract data, and the sliding window size is the length of data extracted from the information abstract data each time;
extracting data in a sliding window according to the size of the sliding window from the first byte of the information abstract data;
performing bit operation on the data in the sliding window by using a preset bit operation algorithm to generate check data with the length of 1 byte;
shifting the sliding window by one byte, re-executing the bit operation on the data in the sliding window by using a preset bit operation algorithm, and generating check data with the length of 1 byte until the bit operation is completed on the last data in the information abstract data;
and sequentially arranging and combining the generated check data from front to back according to the calculated sequence to form a check code corresponding to the original data, wherein the byte length of the check code is equal to the preset byte length.
2. The method according to claim 1, wherein after the sequentially arranging and combining the generated check data from front to back according to the calculated sequence to form the check code corresponding to the original data, the method further comprises:
packaging the original data and the check code to obtain a data packet to be transmitted;
and sending the data packet to be transmitted.
3. The method of claim 1, wherein the obtaining the raw data comprises:
receiving a data packet to be checked;
splitting the data packet to be checked to obtain original data and an original check code;
after the generated verification data are sequentially arranged and combined from front to back according to the calculated sequence to form the verification code corresponding to the original data, the method further comprises the steps of:
comparing the generated check code with the original check code;
and judging whether the data packet to be checked is valid or not according to the comparison result.
4. A check code generation apparatus, the apparatus comprising:
the acquisition module is used for acquiring the original data;
the computing module is used for calculating the original data by utilizing a summary algorithm to obtain information summary data corresponding to the original data;
the generation module is used for calculating the size of a sliding window according to the byte length of the information abstract data and the preset byte length; extracting data in a sliding window according to the size of the sliding window from the first byte of the information abstract data; performing bit operation on the data in the sliding window by using a preset bit operation algorithm to generate check data with the length of 1 byte; shifting the sliding window by one byte, re-executing the bit operation on the data in the sliding window by using a preset bit operation algorithm, and generating check data with the length of 1 byte until the bit operation is completed on the last data in the information abstract data; sequentially arranging and combining the generated check data from front to back according to the sequence of calculation to form a check code corresponding to the original data; the preset byte length is smaller than the byte length of the information abstract data, the byte length of the check code is equal to the preset byte length, and the sliding window size is the length of data extracted from the information abstract data each time.
5. The apparatus of claim 4, wherein the apparatus further comprises:
the packaging module is used for packaging the original data and the check code to obtain a data packet to be transmitted;
and the sending module is used for sending the data packet to be transmitted.
6. The apparatus of claim 4, wherein the obtaining module is specifically configured to:
receiving a data packet to be checked;
splitting the data packet to be checked to obtain original data and an original check code;
the apparatus further comprises:
the comparison module is used for comparing the generated check code with the original check code;
and the judging module is used for judging whether the data packet to be checked is valid or not according to the comparison result.
7. A network electronic device comprising a processor and a memory, wherein the memory stores machine executable instructions executable by the processor, the machine executable instructions being loaded and executed by the processor to implement the method of any of claims 1-3.
CN201910331809.5A 2019-04-24 2019-04-24 Verification code generation method and device Active CN111865557B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910331809.5A CN111865557B (en) 2019-04-24 2019-04-24 Verification code generation method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910331809.5A CN111865557B (en) 2019-04-24 2019-04-24 Verification code generation method and device

Publications (2)

Publication Number Publication Date
CN111865557A CN111865557A (en) 2020-10-30
CN111865557B true CN111865557B (en) 2023-12-05

Family

ID=72952019

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910331809.5A Active CN111865557B (en) 2019-04-24 2019-04-24 Verification code generation method and device

Country Status (1)

Country Link
CN (1) CN111865557B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114389755B (en) * 2022-01-12 2023-08-11 深圳华芯信息技术股份有限公司 Data verification method and device, storage medium and terminal
CN116400946A (en) * 2023-02-24 2023-07-07 深圳市丰润达科技有限公司 Block difference-based switch upgrading method, device, equipment and storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102122960A (en) * 2011-01-18 2011-07-13 西安理工大学 Multi-character combination lossless data compression method for binary data
DE102012220334B3 (en) * 2012-11-08 2013-11-28 Deutsches Zentrum für Luft- und Raumfahrt e.V. Method for restoring lost and corrupted data transmitted from transmission apparatus to receiver, involves performing calculation-, transmission and stopping processes until number of iterations is reached such that window position is moved
CN108632873A (en) * 2018-08-02 2018-10-09 武汉虹信通信技术有限责任公司 A kind of LTE uplink signal field strength measurement method and apparatus based on synchronization process

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102122960A (en) * 2011-01-18 2011-07-13 西安理工大学 Multi-character combination lossless data compression method for binary data
DE102012220334B3 (en) * 2012-11-08 2013-11-28 Deutsches Zentrum für Luft- und Raumfahrt e.V. Method for restoring lost and corrupted data transmitted from transmission apparatus to receiver, involves performing calculation-, transmission and stopping processes until number of iterations is reached such that window position is moved
CN108632873A (en) * 2018-08-02 2018-10-09 武汉虹信通信技术有限责任公司 A kind of LTE uplink signal field strength measurement method and apparatus based on synchronization process

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
杂凑函数结构研究现状及新的结构设计;李正;《CNKI中国优秀硕士学位论文全文数据库》;第1页 *

Also Published As

Publication number Publication date
CN111865557A (en) 2020-10-30

Similar Documents

Publication Publication Date Title
CN111628868B (en) Digital signature generation method and device, computer equipment and storage medium
CN106464499B (en) Communication network system, transmission node, reception node, message checking method, transmission method, and reception method
CN111865557B (en) Verification code generation method and device
CN112383522B (en) Function parameter data transmission encryption method, system, device and readable storage medium
CN115603907A (en) Method, device, equipment and storage medium for encrypting storage data
CN117640256B (en) Data encryption method, recommendation device and storage medium of wireless network card
KR101731645B1 (en) Method of processing data protected against fault injection attacks and associated device
CN114785524A (en) Electronic seal generation method, device, equipment and medium
WO2018076291A1 (en) Method and system for generating permission token, and device
JP2010510756A (en) A processing method for message integrity with tolerance for non-sequential arrival of message data
CN112600838B (en) CAN bus data encryption method and device, storage medium and electronic equipment
CN114205142A (en) Data transmission method and device, electronic equipment and storage medium
CN113704789A (en) Vehicle-mounted communication safety processing method, device, equipment and storage medium
CN112184441B (en) Data processing method, device, node equipment and storage medium
CN113517982A (en) Password generation method, password execution method and terminal
JP7499775B2 (en) Method for authenticating messages in resource-limited systems - Patents.com
RU2710670C2 (en) Cryptographic system and method
US10608822B2 (en) Efficient calculation of message authentication codes for related data
CN113489589A (en) Data encryption and decryption method and device and electronic equipment
CN114422209A (en) Data processing method, device and storage medium
CN112184440A (en) Data processing method, data processing device, node equipment and storage medium
KR102019558B1 (en) Efficient signature verification method for digital signatures using implicit certificates
CN113872753B (en) Encryption transmission method and device based on SHA256 sequence form data
KR20170044501A (en) Method for transmitting hidden information using message composed of string digital code
CN111262837A (en) Data encryption method, data decryption method, system, equipment and medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant