CN111865557A - Check code generation method and device - Google Patents

Check code generation method and device Download PDF

Info

Publication number
CN111865557A
CN111865557A CN201910331809.5A CN201910331809A CN111865557A CN 111865557 A CN111865557 A CN 111865557A CN 201910331809 A CN201910331809 A CN 201910331809A CN 111865557 A CN111865557 A CN 111865557A
Authority
CN
China
Prior art keywords
data
byte length
check code
preset
original
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.)
Granted
Application number
CN201910331809.5A
Other languages
Chinese (zh)
Other versions
CN111865557B (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

Images

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 check code generation method and a check code generation device, wherein an abstract algorithm is utilized to calculate acquired original data to obtain information abstract data corresponding to the original data, secondary compression calculation is carried out 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 abstract algorithm ensures that the original data is not easy to be tampered, and the information abstract data generated by the abstract algorithm is further compressed in byte length to obtain the check code with shorter byte length, so that a data packet formed by the original data and the check code is reduced during data transmission, and therefore, the data transmission efficiency is improved on the basis of ensuring the safety.

Description

Check 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 security and effectiveness of data transmission and prevent data from being maliciously tampered in the transmission process, data is usually checked. In the conventional verification process, an abstract Algorithm (e.g., MD (Message digest Algorithm), SHA (Secure Hash Algorithm), MAC (Message authentication Codes), etc.) 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 for transmission. After receiving the data packet, the receiving end splits the data portion and the check code portion from the data packet, and then calculates the data portion by using the same abstract algorithm to obtain the information abstract data. And comparing the information abstract data with the split check code part, and if the information abstract data are different from the split check code part, indicating that the original data are tampered.
In the above process, although the digest algorithm has higher security, the message digest data has a fixed length and is generally longer, so that the length of the message digest data directly used as the check code is longer, the encapsulated data packet is generally very large, and a large bandwidth resource is occupied during transmission, which results in lower data transmission efficiency.
Disclosure of Invention
The embodiment of the invention aims to provide a check code generation method and a check code generation device so as to improve the data transmission efficiency. The specific technical scheme is as follows:
in a first aspect, an embodiment of the present invention provides a check code generation method, where the method includes:
acquiring original data;
calculating the original data by using an abstract algorithm to obtain information abstract data corresponding to the original data;
and 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.
Optionally, the performing, according to a preset byte length, a secondary compression operation on the information summary data to generate a check code corresponding to the original data includes:
Selecting a secondary compression operation algorithm corresponding to a 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 comprises a bit operation;
the performing 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:
calculating the size of a sliding window according to the byte length of the information abstract data and a preset byte length;
extracting data in a sliding window from the first byte of the information summary data according to the size of the sliding window;
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;
moving the sliding window backward by one byte, re-executing the preset bit operation algorithm, and performing bit operation on the data in the sliding window to generate check data with the length of 1 byte until the last data in the information abstract data is subjected to bit operation;
And forming a check code corresponding to the original data according to the generated check data.
Optionally, after performing secondary compression operation on the information digest data according to the preset byte length to generate the 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 raw data includes:
receiving a data packet to be checked;
splitting the data packet to be verified to obtain original data and an original verification code;
after performing secondary compression operation on the information summary data according to the preset byte length to generate the check code corresponding to the original data, the method further includes:
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 original data;
the calculation module is used for calculating the original data by using an abstract algorithm to obtain information abstract data corresponding to the original data;
And the generating module is used for performing secondary compression operation on the information summary 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 summary 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 a 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;
alternatively, the first and second electrodes may be,
calculating the size of a sliding window according to the byte length of the information abstract data and a preset byte length; extracting data in a sliding window from the first byte of the information summary data according to the size of the sliding window; 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; moving the sliding window backward by one byte, re-executing the preset bit operation algorithm, and performing bit operation on the data in the sliding window to generate check data with the length of 1 byte until the last data in the information abstract data is subjected to bit operation; and forming a check code corresponding to the original data according to the generated check data.
Optionally, 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.
Optionally, the obtaining module is specifically configured to:
receiving a data packet to be checked;
splitting the data packet to be verified to obtain original data and an original verification code;
the device 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, which includes a processor and a memory, where the memory stores machine executable instructions that can be executed by the processor, and the machine executable instructions are loaded and executed by the processor, so as to implement the method provided in the first aspect of the embodiment of the present invention.
In a fourth aspect, an embodiment of the present invention provides a machine-readable storage medium, where machine-executable instructions are stored, and when the machine-executable instructions are loaded and executed by a processor, the method provided by the first aspect of the embodiment of the present invention is implemented.
The method and the device for generating the check code provided by the embodiment of the invention utilize an abstract algorithm to operate the acquired original data to obtain the information abstract data corresponding to the original data, and perform secondary compression operation on the information abstract data 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 abstract data, and the byte length of the check code is equal to the preset byte length. On the basis of generating the information abstract data by using an abstract algorithm, carrying out secondary compression operation on the information abstract data according to the preset byte length, and carrying out length compression on the information abstract data to obtain a check code with shorter byte length. The abstract algorithm ensures that the original data is not easy to be tampered, and the information abstract data generated by the abstract algorithm is further compressed in byte length to obtain the check code with shorter byte length, so that a data packet formed by the original data and the check code is reduced 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 present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts.
Fig. 1 is a schematic flow chart of a check code generation method according to an embodiment of the present invention;
fig. 2 is a schematic flow chart of data transmission by the network electronic device at the data transmitting end according to the embodiment of the present invention;
fig. 3 is a schematic flow chart of the data receiving end network electronic device receiving data according to the embodiment of the present invention;
FIG. 4 is a flowchart illustrating an example of a check code generation method according to an embodiment of the present invention;
FIG. 5 is a diagram illustrating an embodiment of generating a check code with a length of 2 bytes by using a sliding window technique;
fig. 6 is a schematic structural diagram of a check code generating apparatus 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 technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
In order to improve data transmission efficiency, embodiments of the present invention provide a check code generation method and apparatus, a network electronic device, and a machine-readable storage medium. Next, a check code generation method provided in an embodiment of the present invention is first described.
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 sending end of data transmission and a receiving end of the data transmission. The mode for realizing the check code generation method provided by the embodiment of the invention can be at least one of software, hardware circuit and logic circuit arranged in the network electronic equipment.
As shown in fig. 1, a check code generation method provided in the embodiment of the present invention may include the following steps.
And S101, acquiring original data.
The execution main body of the check code generation method provided by the embodiment of the invention can be a sending end of data transmission and can also be a receiving end of the data transmission. For a sending end, original data is data to be transmitted; for the receiving end, the original data is the data part obtained by splitting the data packet after receiving the data packet sent by the sending end.
And S102, calculating the original data by using an abstract algorithm to obtain information abstract data corresponding to the original data.
The digest algorithm is an important branch in the cryptographic algorithm, and functions such as data signature and data integrity check are realized by extracting specified information from original data, so that the digest algorithm has high safety and reliability, is often used for encrypting sensitive information, and is also called as a Hash algorithm or a Hash algorithm. The commonly used summarization algorithms include MD algorithm, SHA algorithm, MAC algorithm, etc., which are not illustrated herein.
After the summary algorithm operation is performed on the original data, the 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 long, 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.
S103, 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 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 expected to be reached by the 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 device. The secondary compression operation is a compression operation mode for compressing the byte length of the information summary data, and the check code obtained after compression has a shorter byte length than the information summary data before compression. The operation results obtained by different secondary compression operations have different byte lengths, for example, the byte length of the operation results of XOR (exclusive or), SUM (SUM), odd-even, etc. operations is generally 1 byte, and the byte length of the operation result of complex compound operations is 2 bytes or 3 bytes. The secondary compression operation is carried out on the information abstract data, so that the byte length of the information abstract data can be compressed to the preset byte length, and 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 secondary compression operation algorithms corresponding to different byte lengths in advance, and the secondary compression operation algorithms may include bit operation algorithms, complex operation algorithms, and the like, for example, XOR operations corresponding to 1 byte length, SUM operations, complex operations 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 the secondary compression operation on the information digest data, so as to obtain the check code with the byte length of 1 byte.
Optionally, the secondary compression operation may include a bit operation. Correspondingly, S103 may be specifically implemented by the following steps:
The first step, according to the byte length of the information abstract data and the preset byte length, the size of the sliding window is calculated.
And secondly, extracting data in the sliding window according to the size of the sliding window from the first byte of the information abstract data.
And thirdly, 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.
And fourthly, moving the sliding window backward by one byte, and re-executing the third step until the last data in the information abstract data is subjected to bit operation.
And fifthly, forming a check code corresponding to the original data according to the generated check data.
In an implementation manner of the embodiment of the present invention, when performing the secondary compression operation, bit operations such as XOR operation and SUM operation may be used to obtain a calculation result with a length of 1 byte, and one bit operation may be performed to obtain one piece of check data. The size of the sliding window of the data subjected to one bit operation can be calculated according to the byte length of the information digest data and the preset byte length, for example, if the byte length of the information digest data is 16 bytes, and the preset byte length is 2 bytes, the size d of the sliding window is 16-2+1 or 15, that is, 15 data need to be extracted from the information digest data at one time for performing the bit operation.
The method comprises the steps of extracting data in a sliding window from a first byte of information abstract data according to the size of the sliding window to perform bit operation to obtain check data with the length of 1 byte, sliding the sliding window (moving back by one byte), re-extracting the data in the sliding window to perform bit operation to obtain the check data with the length of 1 byte, and combining the check data until each data in the information abstract data completes the bit operation to obtain a plurality of check data, wherein the number of the check data is equal to the preset byte length, and the check code with the byte length being the preset byte length can be obtained. The combination mode of the check data is to arrange and combine the check data from front to back in sequence according to the sequence of calculation.
By applying the embodiment of the invention, the obtained original data is operated by using the abstract algorithm to obtain the information abstract data corresponding to the original data, and the information abstract data is subjected to secondary compression operation 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 abstract data, and the byte length of the check code is equal to the preset byte length. On the basis of generating the information abstract data by using an abstract algorithm, carrying out secondary compression operation on the information abstract data according to the preset byte length, and carrying out length compression on the information abstract data to obtain a check code with shorter byte length. The abstract algorithm ensures that the original data is not easy to be tampered, and the information abstract data generated by the abstract algorithm is further compressed in byte length to obtain the check code with shorter byte length, so that a data packet formed by the original data and the check code is reduced during data transmission, and therefore, the data transmission efficiency is improved on the basis of ensuring the safety.
Although the safety and reliability of the abstract algorithm are high, the byte length of the information abstract data directly used as the check code is long in the traditional check code generation method based on the simple abstract algorithm; although the check code generated by calculation has a byte length of only 1 byte, the check code generated by calculation is not high in security, has a risk of being tampered and is poor in flexibility. 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, the advantages of safety and reliability of the abstract algorithm and short 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 change is made to the original data, even if only 1 byte is modified, the obtained check code can be greatly different, and due to the irreversibility of the digest algorithm, even if an attacker knows the check code, the attacker can also difficultly forge the corresponding original data.
According to the embodiment of the invention, after the abstract algorithm operation is carried out on the original data, the secondary compression operation is carried out according to the actual requirement, so that the check code with the byte length meeting the requirement is obtained, the flexibility of the check code generation process is enhanced, and the actual requirement can be flexibly met. And by compressing the information abstract data, the shortest byte length of the check code can be compressed to 1 byte, 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 present invention may be applied to a data sending end network electronic device, and send data after generating a check code. Accordingly, the flow of data transmission of the network electronic device at the data transmitting end is shown in fig. 2, and includes the following steps.
S201, acquiring original data.
S202, the abstract algorithm is utilized to operate the original data, and the information abstract data corresponding to the original data are obtained.
S203, 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 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 again here. The original data is the original data 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 may be encapsulated in an end-to-end manner, or in other data encapsulation manners. After data encapsulation, a data packet to be transmitted can be obtained.
And S205, sending the data packet to be transmitted.
After the data packet to be transmitted is obtained by packaging the data sending end network electronic equipment, the data packet can be sent to the data receiving end network electronic equipment.
Correspondingly, the embodiment of the present invention can also be applied to a data receiving end network electronic device, and the flow of receiving data by the data receiving end network electronic device is shown in fig. 3, and includes the following steps.
S301, receiving a data packet to be checked.
S302, the data packet to be checked is split to obtain original data and an original check code.
For the data receiving end network electronic equipment, after receiving a data packet to be checked sent by the data sending end network electronic equipment, original data is obtained by splitting the data packet to be checked, and when the data packet is split, an original check code can be split. The specific data packet splitting manner may be splitting 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 previous bytes may be split.
And S303, calculating the original data by using an abstract algorithm to obtain information abstract data corresponding to the original data.
S304, 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 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, the check code generation method in the embodiment shown in fig. 1 may be adopted to generate the 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 according to the comparison result.
After the check code corresponding to the original data is generated, the generated check code may be compared with the original check code. If the data packets are the same, the original data in the data packets to be verified are not tampered, and the data packets to be verified are valid; if the data packets to be verified are different, the original data in the data packets to be verified are maliciously tampered, and the data packets to be verified are invalid.
By applying the embodiment of the invention, the obtained original data is operated by using the abstract algorithm to obtain the information abstract data corresponding to the original data, and the information abstract data is subjected to secondary compression operation 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 abstract data, and the byte length of the check code is equal to the preset byte length. The check code generation method is adopted in both the data sending end network electronic equipment and the data receiving end network electronic equipment, so that the data packets transmitted between the data sending end network electronic equipment and the data receiving end network electronic equipment are ensured to be small, and the safety and reliability of data are ensured by adopting a corresponding data check mode.
For convenience of understanding, the check code generation method provided by the embodiment of the present invention is described in detail below with reference to specific examples, and as shown in fig. 4, the method example includes the following steps.
S401, performing abstract algorithm operation on the original data A to obtain information abstract data B, wherein the byte length of the information abstract data B is B bytes.
In this example, the digest algorithm adopted is MD5 (fifth version MD algorithm), and the byte length B of the obtained information digest data B is 16 bytes, which is long.
S402, acquiring the preset byte length c.
In this example, the preset byte length c is a preset 2-byte length.
And S403, determining the size d of the sliding window, namely b-c + 1.
In this example, b is 16, c is 2, and the window size d is 16-2+1 is 15.
S404, starting from the first byte of the information digest data B, according to the size d of the sliding window, data with a length of d bytes is extracted, and bit operation is performed to obtain check data c1 with a length of 1 byte.
In this example, the bit operation is 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, save the check data C1 to the first byte position of the final check code C.
S406, determine whether the byte length of the check data stored in the check code C is equal to the preset byte length C, if not, execute S407.
S407, moving the sliding window backward 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, save the check data C2 to the second byte position of the final check code C.
After executing S408, returning to execute S406 until the byte length of the check data saved in the check code C is equal to the preset byte length C, stopping the calculation, and determining the check code C.
In the present example, the process of generating the check code of 2 bytes length by using the sliding window technique is shown in fig. 5, and the information digest data B obtained by the digest algorithm has a byte length of 16 bytes (B0 to B15). Extracting 15 data from B0 to B14 by a first sliding window to perform bit operation to obtain check data c1, and storing the check data c1 to the first byte position of a final check code; and moving the sliding window backwards, extracting 15 data from B1 to B15 for 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 finally obtained check code C is a check code of 2 bytes in length.
Corresponding to the foregoing method embodiment, an embodiment of the present invention provides a check code generating apparatus, and as shown in fig. 6, the apparatus may include:
an obtaining module 610, configured to obtain raw data;
a calculating module 620, configured to perform an operation on the raw data by using a digest algorithm to obtain information digest data corresponding to the raw data;
a generating module 630, configured to perform secondary compression operation on the information digest 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 digest data, and the byte length of the check code is equal to the preset byte length.
Optionally, the generating module 630 may be specifically configured to:
selecting a secondary compression operation algorithm corresponding to a 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;
alternatively, the first and second electrodes may be,
calculating the size of a sliding window according to the byte length of the information abstract data and a preset byte length; extracting data in a sliding window from the first byte of the information summary data according to the size of the sliding window; 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; moving the sliding window backward by one byte, re-executing the preset bit operation algorithm, and performing bit operation on the data in the sliding window to generate check data with the length of 1 byte until the last data in the information abstract data is subjected to bit operation; and forming a check code corresponding to the original data according to the 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 obtaining module 610 may be specifically configured to:
receiving a data packet to be checked;
splitting the data packet to be verified to obtain original data and an original verification 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 the abstract algorithm to obtain the information abstract data corresponding to the original data, and the information abstract data is subjected to secondary compression operation 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 abstract data, and the byte length of the check code is equal to the preset byte length. On the basis of generating the information abstract data by using an abstract algorithm, carrying out secondary compression operation on the information abstract data according to the preset byte length, and carrying out length compression on the information abstract data to obtain a check code with shorter byte length. The abstract algorithm ensures that the original data is not easy to be tampered, and the information abstract data generated by the abstract algorithm is further compressed in byte length to obtain the check code with shorter byte length, so that a data packet formed by the original data and the check code is reduced during data transmission, and therefore, the data transmission efficiency is improved on the basis of ensuring the safety.
An embodiment of the present invention further provides a network electronic device, as shown in fig. 7, including a processor 701 and a memory 702, where the memory 702 stores a machine executable instruction that can be executed by the processor 701, and the machine executable instruction is loaded and executed by the processor 701, so as to implement the check code generation method provided in the embodiment of the present invention.
The Memory may include a RAM (Random Access Memory) or an NVM (Non-volatile Memory), such as at least one disk Memory. Optionally, the memory may also be at least one memory device located remotely from the processor.
The Processor may be a general-purpose Processor, including a Central Processing Unit (CPU), a Network Processor (NP), and the like; but also a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field-Programmable Gate Array) or other Programmable logic device, discrete Gate or transistor logic device, discrete hardware component.
The memory 702 and the processor 701 may be connected by a wire or a wireless connection for data transmission, and the network electronic device and other devices may communicate through a wire or a wireless communication interface. Fig. 7 shows an example of data transmission via a bus, and the connection method is not limited to a specific connection method.
In the embodiment of the present invention, the processor can realize that: and 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. On the basis of generating the information abstract data by using an abstract algorithm, carrying out secondary compression operation on the information abstract data according to the preset byte length, and carrying out length compression on the information abstract data to obtain a check code with shorter byte length. The abstract algorithm ensures that the original data is not easy to be tampered, and the information abstract data generated by the abstract algorithm is further compressed in byte length to obtain the check code with shorter byte length, so that a data packet formed by the original data and the check code is reduced during data transmission, and therefore, the data transmission efficiency is improved on the basis of ensuring the safety.
In addition, the embodiment of the present invention further provides a machine-readable storage medium, where 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 a check code provided in the embodiment of the present invention is implemented.
In the embodiment of the present invention, the machine-readable storage medium stores a machine-executable instruction for executing the check code generation method provided in the embodiment of the present invention when running, so that it is possible to implement: and 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. On the basis of generating the information abstract data by using an abstract algorithm, carrying out secondary compression operation on the information abstract data according to the preset byte length, and carrying out length compression on the information abstract data to obtain a check code with shorter byte length. The abstract algorithm ensures that the original data is not easy to be tampered, and the information abstract data generated by the abstract algorithm is further compressed in byte length to obtain the check code with shorter byte length, so that a data packet formed by the original data and the check code is reduced during data transmission, and therefore, the data transmission efficiency is improved on the basis of ensuring the safety.
For the embodiments of the network electronic device and the machine-readable storage medium, the contents of the related methods are substantially similar to those of the foregoing embodiments, so that the description is relatively simple, and for the relevant points, reference may be made to the partial description of the embodiments of the methods.
It is noted that, herein, relational terms such as first and second, and the like may be 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. Also, 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 an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
All the embodiments in the present specification are described in a related manner, and the same and similar parts among the embodiments may be referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, as for the device, the network electronic device and the machine-readable storage medium embodiments, since they are substantially similar to the method embodiments, the description is relatively simple, and in relation to the description, reference may be made to some parts of the description of the method embodiments.
The above description is only for the preferred embodiment of the present invention, and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention shall fall within the protection scope of the present invention.

Claims (10)

1. A check code generation method, comprising:
acquiring original data;
calculating the original data by using an abstract algorithm to obtain information abstract data corresponding to the original data;
and 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.
2. The method according to claim 1, wherein performing secondary compression operation on the information digest 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 a 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.
3. The method of claim 1, wherein the secondary compression operation comprises a bit operation;
the performing 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:
calculating the size of a sliding window according to the byte length of the information abstract data and a preset byte length;
extracting data in a sliding window from the first byte of the information summary data according to the size of the sliding window;
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;
Moving the sliding window backward by one byte, re-executing the preset bit operation algorithm, and performing bit operation on the data in the sliding window to generate check data with the length of 1 byte until the last data in the information abstract data is subjected to bit operation;
and forming a check code corresponding to the original data according to the generated check data.
4. The method according to claim 1, wherein after performing a secondary compression operation on the information digest data according to a preset byte length to generate a 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.
5. The method of claim 1, wherein the obtaining raw data comprises:
receiving a data packet to be checked;
splitting the data packet to be verified to obtain original data and an original verification code;
after performing secondary compression operation on the information summary data according to the preset byte length to generate the check code corresponding to the original data, the method further includes:
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.
6. An apparatus for generating a check code, the apparatus comprising:
the acquisition module is used for acquiring original data;
the calculation module is used for calculating the original data by using an abstract algorithm to obtain information abstract data corresponding to the original data;
and the generating module is used for performing secondary compression operation on the information summary 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 summary data, and the byte length of the check code is equal to the preset byte length.
7. The apparatus of claim 6, wherein the generating module is specifically configured to:
selecting a secondary compression operation algorithm corresponding to a 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;
alternatively, the first and second electrodes may be,
calculating the size of a sliding window according to the byte length of the information abstract data and a preset byte length; extracting data in a sliding window from the first byte of the information summary data according to the size of the sliding window; 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; moving the sliding window backward by one byte, re-executing the preset bit operation algorithm, and performing bit operation on the data in the sliding window to generate check data with the length of 1 byte until the last data in the information abstract data is subjected to bit operation; and forming a check code corresponding to the original data according to the generated check data.
8. The apparatus of claim 6, further comprising:
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.
9. The apparatus of claim 6, wherein the obtaining module is specifically configured to:
receiving a data packet to be checked;
splitting the data packet to be verified to obtain original data and an original verification code;
the device 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.
10. 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 one of claims 1 to 5.
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 true CN111865557A (en) 2020-10-30
CN111865557B 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)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114389755A (en) * 2022-01-12 2022-04-22 上海黑眸智能科技有限责任公司 Data verification method, device, storage medium and terminal
CN116400946A (en) * 2023-02-24 2023-07-07 深圳市丰润达科技有限公司 Block difference-based switch upgrading method, device, equipment and storage medium
CN116594948A (en) * 2023-05-12 2023-08-15 深圳市安保医疗科技股份有限公司 USB data transmission method, device, computer equipment and storage medium
CN116594948B (en) * 2023-05-12 2024-06-21 深圳市安保医疗科技股份有限公司 USB data transmission method, device, computer 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中国优秀硕士学位论文全文数据库》, pages 1 *

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114389755A (en) * 2022-01-12 2022-04-22 上海黑眸智能科技有限责任公司 Data verification method, device, storage medium and terminal
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
CN116594948A (en) * 2023-05-12 2023-08-15 深圳市安保医疗科技股份有限公司 USB data transmission method, device, computer equipment and storage medium
CN116594948B (en) * 2023-05-12 2024-06-21 深圳市安保医疗科技股份有限公司 USB data transmission method, device, computer equipment and storage medium

Also Published As

Publication number Publication date
CN111865557B (en) 2023-12-05

Similar Documents

Publication Publication Date Title
CN104933368B (en) A kind of detection method and device of cyberspace vulnerability
CN110324115B (en) Data transmission method and device, storage medium and terminal equipment
CN110597839A (en) Transaction data processing method, device, equipment and storage medium
JP2010508719A (en) Synthetic message authentication code
CN111865557B (en) Verification code generation method and device
CN116107612B (en) Firmware air upgrading device, charging pile, device, method and program product
CN114338510B (en) Data forwarding method and system for controlling and forwarding separation
CN112600838B (en) CAN bus data encryption method and device, storage medium and electronic equipment
JP2010510756A (en) A processing method for message integrity with tolerance for non-sequential arrival of message data
CN107770183B (en) Data transmission method and device
CN113704789A (en) Vehicle-mounted communication safety processing method, device, equipment and storage medium
CN113517982A (en) Password generation method, password execution method and terminal
CN111953497A (en) Message authentication code generation device and method based on HMAC algorithm
CN113922972B (en) Data forwarding method and device based on MD5 identification code
CN112184441A (en) Data processing method, data processing device, node equipment and storage medium
US10608822B2 (en) Efficient calculation of message authentication codes for related data
JP6992309B2 (en) Transmitter, receiver, and communication method
CN111262837B (en) Data encryption method, data decryption method, system, equipment and medium
CN113542308A (en) Information processing method, system and storage medium, electronic device
CN113489589A (en) Data encryption and decryption method and device and electronic equipment
CN112184440A (en) Data processing method, data processing device, node equipment and storage medium
CN113438226A (en) Message generating and analyzing method, device and system based on hybrid transmission protocol
CN115412271A (en) Data watermark adding method and data security analysis method and device
KR102019558B1 (en) Efficient signature verification method for digital signatures using implicit certificates
CN112333699A (en) Internet of things communication protocol encryption method, equipment and storage 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