A hybrid block hash encryption method, device, equipment and medium
Through the hybrid chunked hash encryption method, the use of keys to sort data blocks and hash function encryption, solving the problem of low security in a specific environment by existing encryption technology, and achieving efficient and secure encryption protection of data.
Patent Information
- Application Number
- CN202410094364.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-23
- Publication Date
- 2024-11-08
- Estimated Expiration
- 2044-01-23
AI Technical Summary
Existing encryption technologies are less secure under certain specific environments and conditions, making it difficult to effectively protect the security of data.
Using the hybrid chunking hash encryption method, by dividing the data to be encrypted into data blocks and into multiple byte blocks, sorting the byte blocks according to the odd and even digits of the key, and then encrypting it with the hash function. Encrypt twice to improve data security.
It increases the difficulty of attackers to crack passwords and reverse derivation of original data, improves the security of data, and keeps the ciphertext length consistent with the original data length, reduces the calculation amount, is suitable for network transmission, and has high computing efficiency.
Smart Images

Figure CN117938492B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of cryptography, and in particular to a hybrid block hash encryption method, device, equipment and medium. Background Art
[0002] With the development of information technology, data security has become increasingly important. Existing encryption technologies usually use symmetric encryption, asymmetric encryption, hash functions and other methods to encrypt transmitted data. Although this ensures data security to a certain extent, under certain specific environments and conditions, the security of these encryption technologies still has room for improvement. Summary of the invention
[0003] The object of the present invention is to provide a hybrid block hash encryption method, device, equipment and medium to solve the problem of low security of existing data encryption methods.
[0004] In order to achieve the above object, the present invention provides the following technical solutions:
[0005] In a first aspect, the present invention provides a hybrid block hash encryption method, comprising:
[0006] Obtain the data to be encrypted and the key;
[0007] Dividing the data to be encrypted into blocks according to a preset block length to obtain at least one data block;
[0008] Grouping the data blocks according to a preset number of bytes to obtain a plurality of byte blocks corresponding to the data blocks;
[0009] Sorting the data in each byte block according to the number of odd and even bits of the key to obtain a sorted byte block;
[0010] Encrypting the sorted byte blocks using a hash function to obtain a plurality of encrypted byte blocks;
[0011] Combine multiple encrypted byte blocks in order to obtain the ciphertext corresponding to the data block.
[0012] Compared with the prior art, the present invention provides a hybrid block hash encryption method, including: obtaining data to be encrypted and a key; dividing the data to be encrypted into blocks according to a preset block length to obtain at least one data block; grouping the data blocks according to a preset number of bytes to obtain multiple byte blocks corresponding to the data blocks; sorting the data in each byte block according to the number of bits where the odd numbers and the even numbers of the key are located to obtain sorted byte blocks; encrypting the sorted byte blocks using a hash function to obtain multiple encrypted byte blocks; merging the multiple encrypted byte blocks in order to obtain the ciphertext corresponding to the data block. This scheme divides the data to be encrypted into data blocks, and divides the data blocks into multiple byte blocks, and then selects the data for hash encryption according to the method of sorting the data in the byte blocks by the key, disrupts the order of the byte block data, and implements the first encryption, which increases the difficulty for attackers to crack the password without knowing the key, and then uses the hash function to encrypt the sorted byte blocks, converts data of any length into a hash value of a fixed length, and implements the second encryption, which increases the difficulty for attackers to reversely deduce the original data when they know the hash value, and the two encryptions can greatly improve the security of the data. At the same time, all the byte blocks after hash encryption are merged to obtain the final ciphertext, which can keep the length of the ciphertext consistent with the length of the original data, which is beneficial for network transmission of data. In addition, this scheme reduces the amount of calculation by grouping the data blocks and then hashing each group. It can be performed in memory, has high computing efficiency, and only relies on hash functions and simple data operations such as grouping and sorting. It can be implemented on many platforms. By selecting different preset numbers of bytes for grouping and combining with hash functions, the strength and performance of encryption can be adjusted.
[0013] In a second aspect, the present invention provides a hybrid block hash encryption device, comprising:
[0014] A module for obtaining data to be encrypted and a key, used for obtaining data to be encrypted and a key;
[0015] The to-be-encrypted data block division module is used to divide the to-be-encrypted data into blocks according to a preset block length to obtain at least one data block;
[0016] A grouping module, used for grouping the data blocks according to a preset number of bytes to obtain a plurality of byte blocks corresponding to the data blocks;
[0017] A sorting module, used for sorting the data in each byte block according to the number of odd numbers and the number of even numbers of the key to obtain sorted byte blocks;
[0018] A hash encryption module, used for encrypting the sorted byte blocks using a hash function to obtain a plurality of encrypted byte blocks;
[0019] The merging module is used to merge multiple encrypted byte blocks in sequence to obtain the ciphertext corresponding to the data block.
[0020] In a third aspect, the present invention provides a hybrid block hash encryption device, comprising:
[0021] A communication unit / communication interface, used to obtain data to be encrypted and a key;
[0022] A processing unit / processor, configured to divide the data to be encrypted into blocks according to a preset block length to obtain at least one data block;
[0023] Grouping the data blocks according to a preset number of bytes to obtain a plurality of byte blocks corresponding to the data blocks;
[0024] Sorting the data in each byte block according to the number of odd and even bits of the key to obtain a sorted byte block;
[0025] Encrypting the sorted byte blocks using a hash function to obtain a plurality of encrypted byte blocks;
[0026] Combine multiple encrypted byte blocks in order to obtain the ciphertext corresponding to the data block.
[0027] In a fourth aspect, the present invention provides a computer-readable storage medium, wherein instructions are stored in the computer-readable storage medium, and when the instructions are executed, the above-mentioned hybrid block hash encryption method is implemented.
[0028] Compared with the prior art, the beneficial effects of the second aspect device type solution, the third aspect equipment type solution, and the fourth aspect computer-readable storage medium type solution provided by the present invention are the same as the beneficial effects of the hybrid block hash encryption method described in the above technical solution, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0030] Figure 1 A flow chart of a hybrid block hash encryption method provided by the present invention;
[0031] Figure 2 A schematic diagram of the structure of a hybrid block hash encryption device provided by the present invention;
[0032] Figure 3 A schematic diagram of the structure of a hybrid block hash encryption device provided by the present invention. DETAILED DESCRIPTION
[0033] In order to clearly describe the technical solutions of the embodiments of the present invention, in the embodiments of the present invention, words such as "first" and "second" are used to distinguish the same items or similar items with basically the same functions and effects. For example, the first threshold and the second threshold are only used to distinguish different thresholds, and their order is not limited. Those skilled in the art can understand that words such as "first" and "second" do not limit the quantity and execution order, and words such as "first" and "second" do not necessarily limit them to be different.
[0034] It should be noted that, in the present invention, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the present invention should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.
[0035] In the present invention, "at least one" means one or more, and "plurality" means two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. The character " / " generally indicates that the associated objects before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, the combination of a and b, the combination of a and c, the combination of b and c, or the combination of a, b and c, where a, b, c can be single or multiple.
[0036] In data transmission, the transmitted data is usually encrypted using an asymmetric encryption algorithm, a symmetric encryption algorithm or a hash function. As computer capabilities increase, current encryption methods have low security.
[0037] To solve the above problems, the present invention provides a hybrid block hash encryption method, device, equipment and medium, which will be described below in conjunction with the accompanying drawings.
[0038] like Figure 1 As shown, the present invention provides a hybrid block hash encryption method, comprising the following steps:
[0039] Step 101: Obtain data to be encrypted and a key;
[0040] The key used for encryption is the same as the key used for decryption.
[0041] Step 102: Divide the data to be encrypted into blocks according to a preset block length to obtain at least one data block;
[0042] Before dividing the encrypted data into blocks according to the preset block length, it is necessary to determine whether the length of the encrypted data is an integer multiple of the preset block length; if so, the encrypted data is divided into blocks according to the preset block length; if not, the encrypted data is padded with zeros at the end to make the length of the encrypted data an integer multiple of the preset block length, and the encrypted data after zero padding is divided into blocks according to the preset block length.
[0043] Step 103: grouping the data blocks according to a preset number of bytes to obtain a plurality of byte blocks corresponding to the data blocks;
[0044] The preset number of bytes can be one byte, two bytes, three bytes or other byte numbers. The preset number of bytes is selected according to user needs. The smaller the preset number of bytes, the more byte blocks are grouped and the stronger the encryption strength is.
[0045] Step 104: sorting the data in each byte block according to the number of odd-numbered bits and the number of even-numbered bits of the key to obtain sorted byte blocks;
[0046] In data transmission, the byte block can be represented by binary form or other encoding methods, and the key can be a binary string. The number of bits of the key is the same as the number of bits of the binary byte block. The number of bits corresponding to 1 in the key is set as the target odd bit, and the number of bits corresponding to 0 in the key is set as the target even bit; 0 in the key corresponds to the 2i-th byte block in the data block, and 1 in the key corresponds to the 2i+1-th byte block in the data block. i is greater than or equal to 0.
[0047] Specifically, when the number of bits of a byte block in a data block is an odd number, sorting the data in each byte block includes: determining the number of bits where the odd number of the key is located as the target number of bits, and calling the number of bits where the odd number of the key is located as the target odd number of bits; extracting the numerical values corresponding to the target number of bits in the byte block in sequence and merging them to obtain the first data; extracting the numerical values corresponding to the bits other than the target number of bits in the byte block in sequence and merging them to obtain the second data; arranging the second data after the first data to obtain the sorted byte block.
[0048] When the number of bits of a byte block in a data block is an even number; sorting the data in each byte block includes: determining the number of bits where the even number of the key is located as the target number of bits, and calling the number of bits where the even number of the key is located as the target even number of bits; extracting the values corresponding to the target number of bits in the byte block in sequence and merging them to obtain the first data; extracting the values corresponding to the bits other than the target number of bits in the byte block in sequence and merging them to obtain the second data; arranging the second data after the first data to obtain the sorted byte block.
[0049] In the process of sorting the byte blocks, the data selected by the key, that is, the data corresponding to the key, is written in sequence to the first few bits of the byte block, and the data not selected by the key is written in sequence to the last few bits of the byte block.
[0050] Step 105: using a hash function to encrypt the sorted byte blocks to obtain a plurality of encrypted byte blocks; the encrypted byte blocks contain a hash value of a fixed length.
[0051] Step 106: Combine multiple encrypted byte blocks in order to obtain the ciphertext corresponding to the data block.
[0052] From the above description, it can be seen that the scheme divides the data to be encrypted into data blocks, and divides the data blocks into multiple byte blocks, and then selects the data for hash encryption according to the method of sorting the data in the byte blocks according to the key, disrupts the order of the byte block data, and realizes the first encryption, which increases the difficulty for attackers to crack the password without knowing the key, and then uses the hash function to encrypt the sorted byte blocks, converts data of any length into a hash value of fixed length, and realizes the second encryption, which increases the difficulty for attackers to reversely deduce the original data when they know the hash value. The two encryptions can greatly improve the security of the data. At the same time, all the byte blocks after hash encryption are merged to obtain the final ciphertext, which can make the length of the ciphertext consistent with the length of the original data, which is beneficial for network transmission data. In addition, the scheme reduces the amount of calculation by grouping the data blocks and then hashing each group, which can be performed in memory, has high computing efficiency, and only relies on hash functions and simple data operations such as grouping and sorting, and can be implemented on many platforms. By selecting different preset byte numbers for grouping, combined with hash functions, the strength and performance of encryption can be adjusted.
[0053] As an optional manner, the target number of bits includes target odd bits and target even bits, and the number of target odd bits and the number of target even bits of the key may be the same or different. When the number of target odd bits and the number of target even bits of the key are the same, the second data is arranged after the first value, and the sorted byte blocks obtained include:
[0054] Write the values corresponding to the target number of bits in the byte block into the first Pn / 2 bits in sequence, and write the remaining values in the byte block into the last Pn / 2 bits in sequence to obtain a sorted byte block, where Pn is the number of bits in the byte block.
[0055] As an optional method, when the number of data blocks obtained by dividing the encrypted data into blocks is greater than or equal to two, the multiple encrypted byte blocks are merged in sequence to obtain the ciphertext corresponding to the data block, and the following steps are further included:
[0056] Each data block is encrypted using an internationally recognized secure hash function, such as the SM3 or SHA-256 hash function standard, and multiple encrypted data blocks are merged in the order of the original data blocks to obtain the ciphertext corresponding to the multiple data blocks.
[0057] Next, the hybrid block hash encryption method is explained using the encrypted data "Hello, World!" as an example.
[0058] Assume that the preset block length is 14 bytes. Since "Hello, World!" is 13 bytes, a 0 needs to be added to the end of the data.
[0059] Odd-even grouping: Divide the data block into blocks according to the preset number of bytes, and perform odd-even grouping on the byte blocks, dividing the byte blocks in the data block into byte blocks of odd bits and byte blocks of even bits; taking the preset number of bytes as 2 as an example, the data blocks are grouped into groups of two bytes each, and the grouped data are obtained: ["He", "ll", "o," "W," "or", "ld," "!"], "He", "o," "or," "!" are byte blocks of odd bits, "ll", "W," "ld" are byte blocks of even bits, and the byte block data is represented in binary form, which is not shown here.
[0060] Odd-even mapping: Use the key to select, 0 corresponds to the 2ith bit, 1 corresponds to the 2i+1th bit, that is, sort the data in each byte block according to the number of odd and even bits of the key. Assuming the key is 1010101010101010, the target odd bits are: 1, 3, 5, 7, 9, 11, 13, 15, and the target even bits are 2, 4, 6, 8, 10, 12, 14, 16, the process of odd-even mapping is as follows:
[0061] "He"→"He" (select the values of the 1st, 3rd, 5th, 7th, 9th, 11th, 13th, and 15th bits)
[0062] "ll"→"l" (select the value of the 2nd, 4th, 6th, 8th, 10th, 12th, 14th, 16th bit)
[0063] "o,"→"o,"(select the values of the 1st, 3rd, 5th, 7th, 9th, 11th, 13th, and 15th bits)
[0064] "W"→"W" (select the value of the 2nd, 4th, 6th, 8th, 10th, 12th, 14th, 16th bit)
[0065] "or"→"or" (select the values of the 1st, 3rd, 5th, 7th, 9th, 11th, 13th, and 15th bits)
[0066] "ld"→"d" (select the value of the 2nd, 4th, 6th, 8th, 10th, 12th, 14th, 16th bit)
[0067] "!" → "!" (select the values of the 1st, 3rd, 5th, 7th, 9th, 11th, 13th, and 15th bits)
[0068] The value selected by the key in each byte block is written into the first Pn / 2 bytes, and the data not selected by the key is written into the last Pn / 2 bytes in sequence.
[0069] Hash function processing: Use the hash function to encrypt each byte block after sorting to generate a hash value of fixed length. Assuming that the output length of the hash function is 32 bytes, the hash values are ["He_hash", "l_hash", "o,_hash", "W_hash", "or_hash", "ld_hash", "!_hash"]
[0070] Merge: Merge the hashed byte blocks in the order of the original byte blocks to obtain the ciphertext: "He_hashl_hasho,_hash W_hashor_hashld_hash!_hash".
[0071] The embodiment of the present invention can divide the functional modules according to the above method example. For example, each functional module can be divided according to each function, or two or more functions can be integrated into one processing module. The above integrated module can be implemented in the form of hardware or in the form of software functional modules. It should be noted that the division of modules in the embodiment of the present invention is schematic and is only a logical function division. There may be other division methods in actual implementation.
[0072] In the case of dividing each functional module into corresponding functional modules, Figure 2 The schematic diagram of the structure of a hybrid block hash encryption device provided by the present invention is shown. Figure 2 As shown, the device comprises:
[0073] The module 201 for obtaining the data to be encrypted and the key is used to obtain the data to be encrypted and the key;
[0074] The to-be-encrypted data block division module 202 is used to divide the to-be-encrypted data into blocks according to a preset block length to obtain at least one data block;
[0075] A data block grouping module 203 is used to group the data blocks according to a preset number of bytes to obtain a plurality of byte blocks corresponding to the data blocks;
[0076] A sorting module 204, configured to sort the data in each byte block according to the number of odd and even bits of the key to obtain sorted byte blocks;
[0077] A hash encryption module 205, configured to encrypt the sorted byte blocks using a hash function to obtain a plurality of encrypted byte blocks;
[0078] The merging module 206 is used to merge the multiple encrypted byte blocks in sequence to obtain the ciphertext corresponding to the data block.
[0079] Optionally, the number of bits of the byte block in the data block is an odd number of bits; the sorting module 204 may specifically include:
[0080] An odd-numbered bit selection unit, used for determining the number of bits where the odd numbers of the key are located as the target number of bits;
[0081] A value merging unit is selected to sequentially extract values corresponding to target bits in the byte block and merge them to obtain first data;
[0082] The unselected value merging unit is used to sequentially extract the values corresponding to the bits other than the target bit in the byte block and merge them to obtain the second data;
[0083] A sorting unit is used to arrange the second data after the first data to obtain a sorted byte block.
[0084] Optionally, the number of bits of the byte block in the data block is an even number; the sorting module 204 specifically includes:
[0085] An even-numbered bit selection unit, used for determining the number of bits where the odd numbers of the key are located as the target number of bits;
[0086] Select a value merging unit to sequentially extract values corresponding to target bits in the byte block and merge them to obtain first data;
[0087] A sorting unit, used for sequentially extracting values corresponding to bits other than the target bit in the byte block and merging them to obtain second data;
[0088] Arrange the second data after the first data to obtain an ordered byte block.
[0089] Optionally, the target number of bits includes target odd bits and target even bits, the key is a binary string, the number of bits corresponding to 1 in the key is the target odd bits, and the number of bits corresponding to 0 in the key is the target even bits; the target odd bits and target even bits of the key are the same, and the sorting unit can be specifically used to:
[0090] Write the values corresponding to the target number of bits in the byte block into the first Pn / 2 bits in sequence, and write the remaining values in the byte block into the last Pn / 2 bits in sequence to obtain a sorted byte block, where Pn is the number of bits in the byte block.
[0091] Optionally, the data block grouping module 203 may be used to:
[0092] Determining whether the length of the data to be encrypted is an integer multiple of the preset block length;
[0093] If yes, the data to be encrypted is divided into blocks according to a preset block length;
[0094] If not, the length of the data to be encrypted is padded with zeros at the end, so that the length of the data to be encrypted is an integer multiple of the preset block length, and the data to be encrypted after the zero padding is divided into blocks according to the preset block length.
[0095] Optionally, the device also includes a data block overall encryption module, which is used to encrypt each of the data blocks using the SM3 or SHA-256 hash function standard, and merge multiple encrypted data blocks in sequence to obtain ciphertexts corresponding to multiple data blocks.
[0096] Optionally, the data of the byte block is represented in binary form, and the number of bits of the key is the same as the number of binary bits of the byte block.
[0097] The above mainly introduces the solution provided by the embodiment of the present invention from the perspective of the interaction between various modules. It can be understood that in order to realize the above functions, it includes hardware structures and / or software modules corresponding to the execution of various functions. It should be easy for those skilled in the art to realize that, in combination with the units and algorithm steps of each example described in the embodiments disclosed herein, the present invention can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present invention.
[0098] In the case of using the corresponding integrated unit, Figure 3 A schematic diagram of the structure of a hybrid block hash encryption device provided by the present invention is shown. Figure 3 As shown, the device includes:
[0099] A communication unit / communication interface, used to obtain data to be encrypted and a key;
[0100] A processing unit / processor, configured to divide the data to be encrypted into blocks according to a preset block length to obtain at least one data block;
[0101] Grouping the data blocks according to a preset number of bytes to obtain a plurality of byte blocks corresponding to the data blocks;
[0102] Sorting the data in each byte block according to the number of odd and even bits of the key to obtain a sorted byte block;
[0103] Encrypting the sorted byte blocks using a hash function to obtain a plurality of encrypted byte blocks;
[0104] Combine multiple encrypted byte blocks in order to obtain the ciphertext corresponding to the data block.
[0105] In some possible implementations, the above device may further include a storage module for storing program codes and data of the base station.
[0106] Wherein, the processing unit may be a processor or a controller, for example, a central processing unit (CPU), a general processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. It may implement or execute various exemplary logic blocks, modules and circuits described in conjunction with the disclosure of the present invention. The processor may also be a combination that implements a computing function, for example, a combination of one or more microprocessors, a combination of a DSP and a microprocessor, and the like. The communication module may be a transceiver, a transceiver circuit or a communication interface, and the like. The storage module may be a memory.
[0107] like Figure 3As shown, the processor may be a general-purpose central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits for controlling the execution of the program of the present invention. The communication interface may be one or more. The communication interface may use any transceiver-like device for communicating with other devices or communication networks.
[0108] like Figure 3 As shown, the terminal device may further include a communication line. The communication line may include a path to transmit information between the components.
[0109] Optional, such as Figure 3 As shown, the terminal device may further include a memory. The memory is used to store computer-executable instructions for executing the solution of the present invention, and the execution is controlled by the processor. The processor is used to execute the computer-executable instructions stored in the memory, thereby implementing the method provided by the embodiment of the present invention.
[0110] like Figure 3 As shown, the memory may be a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, a random access memory (RAM) or other types of dynamic storage devices that can store information and instructions, or an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed optical disc, laser disc, optical disc, digital versatile disc, Blu-ray disc, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory may exist independently and be connected to the processor through a communication line. The memory may also be integrated with the processor.
[0111] In a specific implementation, as an example, Figure 3 As shown, the processor may include one or more CPUs, such as Figure 3 CPU0 and CPU1 in.
[0112] In a specific implementation, as an example, Figure 3 As shown, the terminal device may include multiple processors, such as Figure 3 Each of these processors can be a single-core processor or a multi-core processor.
[0113] On the one hand, a computer-readable storage medium is provided, in which instructions are stored. When the instructions are executed, the above-mentioned hybrid block hash encryption method is implemented.
[0114] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer programs or instructions. When the computer program or instruction is loaded and executed on a computer, the process or function described in the embodiment of the present invention is executed in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, a terminal, a user device or other programmable device. The computer program or instruction can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer program or instruction can be transmitted from one website site, computer, server or data center to another website site, computer, server or data center by wired or wireless means. The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. that integrates one or more available media. The available medium can be a magnetic medium, such as a floppy disk, a hard disk, or a tape; it can also be an optical medium, such as a digital video disc (DVD); it can also be a semiconductor medium, such as a solid state drive (SSD).
[0115] Although the present invention is described herein in conjunction with various embodiments, in the process of implementing the claimed invention, those skilled in the art may understand and implement other variations of the disclosed embodiments by viewing the drawings, the disclosure, and the appended claims. In the claims, the word "comprising" does not exclude other components or steps, and "one" or "an" does not exclude multiple situations. A single processor or other unit may implement several functions listed in the claims. Certain measures are recorded in different dependent claims, but this does not mean that these measures cannot be combined to produce good results.
[0116] Although the present invention has been described in conjunction with specific features and embodiments thereof, it is apparent that various modifications and combinations may be made thereto without departing from the spirit and scope of the present invention. Accordingly, this specification and the accompanying drawings are merely exemplary illustrations of the present invention as defined by the appended claims and are deemed to cover any and all modifications, variations, combinations or equivalents within the scope of the present invention. Obviously, those skilled in the art may make various modifications and variations to the present invention without departing from the spirit and scope of the present invention. Thus, the present invention is intended to include such modifications and variations if they fall within the scope of the claims of the present invention and their equivalents.
Claims
1. A hybrid block hash encryption method, characterized in that: include: Obtain the data to be encrypted and the key; Dividing the data to be encrypted into blocks according to a preset block length to obtain at least one data block; The number of the data blocks is greater than or equal to two; Grouping the data blocks according to a preset number of bytes to obtain a plurality of byte blocks corresponding to the data blocks; When the number of bits of the byte block in the data block is an odd number, the number of bits where the odd number of the key is located is determined as the target number of bits; or, when the number of bits of the byte block in the data block is an even number, the number of bits where the even number of the key is located is determined as the target number of bits; Extract the values corresponding to the target number of bits in the byte blocks in sequence and merge them to obtain the first data; Sequentially extract the values corresponding to the bits other than the target bit in the byte block and merge them to obtain the second data; sorting the second data after the first data to obtain a sorted byte block; Encrypting the sorted byte blocks using a hash function to obtain a plurality of encrypted byte blocks; Merging multiple encrypted byte blocks in order to obtain ciphertext corresponding to the data blocks; Each of the data blocks is encrypted using the SM3 or SHA-256 hash function standard, and multiple encrypted data blocks are merged in sequence to obtain ciphertexts corresponding to the multiple data blocks.
2. The hybrid block hash encryption method according to claim 1, characterized in that: The target number of bits includes target odd bits and target even bits, the key is a binary string, the number of bits corresponding to 1 in the key is the target odd bits, and the number of bits corresponding to 0 in the key is the target even bits; the number of target odd bits and the number of target even bits of the key are the same, and the byte block obtained after arranging the second data after the first value includes: Write the values corresponding to the target number of bits in the byte block into the first Pn / 2 bits in order, and write the remaining values in the byte block into the last Pn / 2 bits in order to obtain a sorted byte block, where Pn is the number of bits in the byte block.
3. The hybrid block hash encryption method according to claim 1, characterized in that: The step of dividing the data to be encrypted into blocks according to a preset block length to obtain a plurality of data blocks comprises: Determining whether the length of the data to be encrypted is an integer multiple of the preset block length; If yes, the data to be encrypted is divided into blocks according to a preset block length; If not, the length of the data to be encrypted is padded with zeros at the end, so that the length of the data to be encrypted is an integer multiple of the preset block length, and the data to be encrypted after the zero padding is divided into blocks according to the preset block length.
4. The hybrid block hash encryption method according to claim 1, characterized in that: The data of the byte block is represented in binary form, and the number of bits of the key is the same as the number of bits of the binary code of the byte block.
5. A hybrid block hash encryption device, characterized in that: include: A module for obtaining data to be encrypted and a key, used for obtaining data to be encrypted and a key; The to-be-encrypted data block division module is used to divide the to-be-encrypted data into blocks according to a preset block length to obtain at least one data block; the number of the data blocks is greater than or equal to two; A data block grouping module, used for grouping the data blocks according to a preset number of bytes to obtain a plurality of byte blocks corresponding to the data blocks; A sorting module is used for, when the number of bits of the byte block in the data block is an odd number, determining the number of bits where the odd number of the key is located as the target number of bits; or, when the number of bits of the byte block in the data block is an even number of bits, determining the number of bits where the even number of the key is located as the target number of bits; extracting values corresponding to the target number of bits in the byte block in sequence and merging them to obtain first data; extracting values corresponding to the number of bits in the byte block except the target number of bits in sequence and merging them to obtain second data; and sorting the second data after the first data; A hash encryption module, used for encrypting the sorted byte blocks using a hash function to obtain a plurality of encrypted byte blocks; A merging module, used to merge multiple encrypted byte blocks in order to obtain ciphertext corresponding to the data block; The data block overall encryption module is used to encrypt each of the data blocks using the SM3 or SHA-256 hash function standard, and merge multiple encrypted data blocks in sequence to obtain ciphertexts corresponding to multiple data blocks.
6. A hybrid block hash encryption device, characterized in that: include: A communication unit / communication interface, used to obtain data to be encrypted and a key; A processing unit / processor, configured to divide the data to be encrypted into blocks according to a preset block length to obtain at least one data block; the number of the data blocks is greater than or equal to two; Grouping the data blocks according to a preset number of bytes to obtain a plurality of byte blocks corresponding to the data blocks; When the number of bits of the byte block in the data block is an odd number, the number of bits where the odd number of the key is located is determined as the target number of bits; or, when the number of bits of the byte block in the data block is an even number, the number of bits where the even number of the key is located is determined as the target number of bits; Extract the values corresponding to the target number of bits in the byte blocks in sequence and merge them to obtain the first data; Sequentially extract the values corresponding to the bits other than the target bit in the byte block and merge them to obtain the second data; sorting the second data after the first data to obtain a sorted byte block; Encrypting the sorted byte blocks using a hash function to obtain a plurality of encrypted byte blocks; Merging multiple encrypted byte blocks in order to obtain ciphertext corresponding to the data blocks; Each of the data blocks is encrypted using the SM3 or SHA-256 hash function standard, and multiple encrypted data blocks are merged in sequence to obtain ciphertexts corresponding to the multiple data blocks.
7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores instructions, and when the instructions are executed, the hybrid block hash encryption method described in any one of claims 1-4 is implemented.
