Short text symmetric encryption and decryption method, device, equipment and storage medium
By converting a character sequence into a digital sequence and an improved symmetric reversible hash encryption algorithm, the problem of low security and efficiency in the transmission of short text information in the existing technology is solved, efficient and safe encryption and decryption are achieved, and data consistency is ensured. .
Patent Information
- Application Number
- CN202410846202.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-27
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2044-06-27
AI Technical Summary
In the process of transmitting short text information, existing encryption technology is difficult to balance simplicity, high security and data consistency verification. In particular, symmetric encryption algorithms cannot guarantee high security, and asymmetric encryption algorithms have high computational complexity. High, low efficiency, the traditional Hash encryption algorithm is irreversible and cannot be directly used for encryption and decryption tasks of ordinary text.
Using the character sequence to digital sequence algorithm and the improved symmetric reversible hash encryption algorithm, by constructing a reversible mapping pair of text characters and digital codes, the encryption and decryption of short text is realized, and a reversible digital sequence and a fixed-length reversible hash code are generated. , and performs secondary encryption and decryption through symmetric reversible hash encryption and decryption algorithms to ensure data consistency.
It achieves efficient, safe and accurate encryption and decryption of short text information. It has the advantages of simplicity, ease of use, high security and data consistency verification, and can effectively protect short text information from unauthorized access.
Smart Images

Figure CN118400196B
Abstract
Description
Technical Field
[0001] The present application relates to the field of data encryption technology, and in particular to a short text symmetric encryption and decryption method, device, equipment and storage medium. Background Art
[0002] Encryption technology is the cornerstone of network security technology. In the era of big data and the Internet, data encryption technology, as an effective means of information protection, plays an irreplaceable role in the field of information security. Data encryption technology refers to the conversion of a message (or plaintext) through an encryption key and an encryption function into meaningless ciphertext, and the receiver restores the ciphertext to plaintext through a decryption function and a decryption key. As we all know, key information such as the entity name, content, location, date, amount, etc. for important events and activities occasionally leaks during transmission. After the information is leaked, it may cause immeasurable losses and impacts to the relevant users. Analysis shows that the above-mentioned widely used key information is basically composed of short texts. How to ensure that these short text information cannot be easily obtained and cracked by a third party during the information transmission process, and can be accurately obtained and decrypted by the designated user is an information security problem that needs to be solved urgently.
[0003] Existing encryption technologies can be divided into two major methods, symmetric encryption and asymmetric encryption, according to the type of key used. A symmetric encryption algorithm means that the same secret key is required for the encryption and decryption processes. Symmetric encryption algorithms are mainly used to encrypt text content. Although the amount of calculation is small and the encryption efficiency is high, it cannot guarantee high encryption security and cannot verify whether the file content has been tampered with. Asymmetric encryption algorithms use different keys for encryption and decryption. Although there is a certain relationship between the two, it is not easy to derive one from the other. The advantage of asymmetric encryption algorithms is strong security, but the computational complexity is high, resulting in low efficiency. In addition, the encryption process of traditional Hash encryption algorithms is generally irreversible and cannot be directly used for encryption and decryption tasks of ordinary text. Summary of the invention
[0004] Based on this, it is necessary to provide a short text symmetric encryption and decryption method, device, equipment and storage medium that can simultaneously take into account multiple dimensions such as simplicity and ease of use, high security and data consistency verification, short text symmetric encryption and decryption, etc., in order to address the above technical problems.
[0005] A short text symmetric encryption and decryption method, the method comprising:
[0006] In the encryption phase, the character sequence to digital sequence algorithm is called to perform primary encryption on the input short text sequence to be encrypted to generate a reversible digital sequence, and the improved symmetric reversible hash encryption algorithm is called to perform secondary encryption on the reversible digital sequence to generate a fixed-length reversible hash code;
[0007] In the decryption stage, the improved symmetric reversible hash decryption algorithm is called to perform secondary decryption on the fixed-length reversible hash code to obtain a reversible digital sequence, and the reversible digital sequence to character sequence algorithm is called to perform primary decryption on the reversible digital sequence to restore the decrypted short text sequence.
[0008] In one embodiment, a character sequence to digital sequence conversion algorithm is called to perform primary encryption on a pre-entered short text sequence to be encrypted to generate a reversible digital sequence, including:
[0009] Construct a reversible mapping of text characters to digital codes and initialize an empty string ; Each character in the reversible mapping pair is assigned a unique digital code corresponding to it, and all characters and digital codes are unique;
[0010] Input a short text sequence to be encrypted, and segment the short text sequence according to individual characters to obtain an ordered first list; wherein the characters in the first list are text characters, numbers, punctuation marks, and special symbols in the short text sequence;
[0011] Loop through each character in the first list, take out the digital code corresponding to the current character from the reversible mapping pair, add a specified separator after the digital code for concatenation, and add the concatenation result to S;
[0012] After traversing all the characters in the first list in sequence, remove the redundant specified separator at the last position in S to generate a reversible digital sequence; wherein, the concatenation method of encrypting and generating a reversible digital sequence is expressed as S=S+N+T; wherein N is the digital code and T is the specified separator.
[0013] In one of the embodiments, the method of constructing a reversible mapping pair of text characters and digital codes includes: secret code mapping technology, word vector conversion technology and secret table construction technology; among which, the secret table construction technology refers to collecting, organizing and removing duplicates of regular Chinese characters, numbers, letters, punctuation marks and special symbols to form a unique reversible mapping table of characters and digital codes.
[0014] In one embodiment, an improved symmetric reversible hash encryption algorithm is called to perform secondary encryption on a reversible digital sequence to generate a fixed-length reversible hash code, including:
[0015] Get the reversible digital sequence generated after the first level of encryption and initialize an empty string ;
[0016] The reversible digital sequence is segmented according to single characters to obtain an ordered second list; wherein the characters in the second list are numbers and designated separators;
[0017] Load the specified hash encryption algorithm uniformly to perform hash encryption on each number from 0 to 9 and the specified separator, and then construct the original character as the key and the hash code corresponding to the original character as the value.<K,V> The pairs (key-value pairs) are stored in the specified KV object M in sequence;
[0018] Traverse each character in the second list, take the current character as the key and take the corresponding value from the KV object M, and take the truncated code of the specified position P and fixed length K of the value as the reversible hash code of the current character, and sequentially concatenate the reversible hash codes of each character in the second list until the reversible hash code H1 of all characters is obtained; wherein the concatenation method of H1 is expressed as H1=H1+HPK; wherein HPK is the reversible hash code of a single character;
[0019] Performing overall hash encryption on the reversible digital sequence to obtain a reversible hash code H0 of the reversible digital sequence;
[0020] The tag bit is hashed and encrypted, and the truncated code of the specified position P and fixed length K is taken as the hash code H2 of the tag bit; the tag bit is a manually set or default string; the values of P and K must meet the following three conditions at the same time: P∈[0, Len (H0)-K], P+K≤ Len (H0), K is an integer not less than 2;
[0021] H0, H1 and H2 are combined and concatenated to obtain a fixed-length reversible hash code H, where the combination and concatenation of H is expressed as
[0022] ;
[0023] in, Represents a function used to intercept a string. Represents a function that calculates the length of a string.
[0024] In one embodiment, an improved symmetric reversible hash decryption algorithm is called to perform secondary decryption on a fixed-length reversible hash code to obtain a reversible digital sequence, including:
[0025] Get the fixed-length reversible hash code H generated after secondary encryption that needs to be decrypted, and initialize an empty string ;
[0026] The fixed-length reversible hash code H is split according to H2 to obtain a left fragment H0 and a right fragment H1, and H1 is grouped from left to right according to the fixed length K, and the grouped fragments are stored in the ordered third list in sequence;
[0027] Load the specified hash encryption algorithm uniformly to perform hash encryption on each number from 0 to 9 and the specified separator, and then use the original character as the key and the hash code corresponding to the original character as the value to construct<K,V> Yes, store them in the specified KV object M in sequence;
[0028] Loop through and take out each packet fragment in the third list in turn, take out the corresponding value from M with the current packet fragment as the comparison target, and take the truncated code of the specified position P with a fixed length K of the value value to perform cyclic matching with the current packet fragment until the matching is completed and stop the loop, and reversely deduce the corresponding original character key according to the current matched value, so as to obtain the real character s corresponding to the current packet fragment; wherein, the values of P and K in the secondary decryption must be completely consistent with the values of P and K adopted by the above-mentioned secondary encryption algorithm;
[0029] The real characters s corresponding to all the grouped fragments are concatenated in sequence to obtain a reversible digital sequence; wherein the concatenation method of the reversible digital sequence obtained by decryption and restoration is expressed as S=S+s.
[0030] In one embodiment, the hash encryption algorithms include SHA-512, MD5, SHA-1, SHA-128, and SHA-256.
[0031] In one embodiment, a reversible digital sequence to character sequence algorithm is called to perform primary decryption on the reversible digital sequence to restore the decrypted short text sequence, including:
[0032] Load the reversible mapping of text characters and digital codes constructed during the encryption process and initialize a string variable ;
[0033] Obtaining the reversible digital sequence obtained after the secondary decryption, and dividing the reversible digital sequence according to the specified separator to obtain an ordered fourth list;
[0034] Traverse each digital code in the fourth list, take out the text character corresponding to the current digital code from the reversible mapping pair, and splice the text characters taken out each time in turn to restore the decrypted short text sequence; wherein the splicing method of the text characters is expressed as T=T+t; wherein t represents the text character corresponding to the digital code.
[0035] A short text symmetric encryption and decryption device, the device comprising:
[0036] The encryption module is used to perform primary encryption on the input short text sequence to be encrypted by calling the character sequence to digital sequence algorithm in the encryption stage to generate a reversible digital sequence, and to perform secondary encryption on the reversible digital sequence by calling the improved symmetric reversible hash encryption algorithm to generate a fixed-length reversible hash code;
[0037] The decryption module is used to call the improved symmetric reversible hash decryption algorithm to perform secondary decryption on the fixed-length reversible hash code in the decryption stage to obtain a reversible digital sequence, and call the reversible digital sequence to character sequence algorithm to perform primary decryption on the reversible digital sequence to restore the decrypted short text sequence.
[0038] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0039] In the encryption phase, the character sequence to digital sequence algorithm is called to perform primary encryption on the input short text sequence to be encrypted to generate a reversible digital sequence, and the improved symmetric reversible hash encryption algorithm is called to perform secondary encryption on the reversible digital sequence to generate a fixed-length reversible hash code;
[0040] In the decryption stage, the improved symmetric reversible hash decryption algorithm is called to perform secondary decryption on the fixed-length reversible hash code to obtain a reversible digital sequence, and the reversible digital sequence to character sequence algorithm is called to perform primary decryption on the reversible digital sequence to restore the decrypted short text sequence.
[0041] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the following steps:
[0042] In the encryption phase, the character sequence to digital sequence algorithm is called to perform primary encryption on the input short text sequence to be encrypted to generate a reversible digital sequence, and the improved symmetric reversible hash encryption algorithm is called to perform secondary encryption on the reversible digital sequence to generate a fixed-length reversible hash code;
[0043] In the decryption stage, the improved symmetric reversible hash decryption algorithm is called to perform secondary decryption on the fixed-length reversible hash code to obtain a reversible digital sequence, and the reversible digital sequence to character sequence algorithm is called to perform primary decryption on the reversible digital sequence to restore the decrypted short text sequence.
[0044] The above-mentioned short text symmetric encryption and decryption method, device, equipment and storage medium include two stages, encryption and decryption. In the encryption stage, the character sequence to digital sequence algorithm and the improved symmetric reversible hash encryption algorithm are integrated to encrypt the short text sequence to be encrypted into a fixed-length reversible hash code; in the decryption stage, the improved symmetric reversible hash decryption algorithm and the reversible digital sequence to character sequence algorithm are integrated to decrypt the fixed-length reversible hash code and restore it to the decrypted short text sequence. Compared with the prior art, the beneficial effects of this application are:
[0045] 1. This application realizes the reversible conversion between character sequences and digital sequences during encryption and decryption by constructing and loading reversible mapping pairs of text characters and digital codes. The conversion operation is simple and the performance is efficient.
[0046] 2. This application improves the original irreversible hash encryption algorithm to obtain a symmetric reversible hash encryption and decryption algorithm, thereby forming an encryption and decryption capability for digital sequences with reversible hashing, while having the advantages of the original hash encryption algorithm, such as fast encryption speed, high security, and data consistency verification.
[0047] 3. This application can efficiently, securely and accurately encrypt and decrypt short text sequences by integrating digital coding with symmetric reversible hash encryption and decryption algorithms. As a hybrid method, it has the advantages of being simple to use, highly secure, data consistency verification, symmetric encryption and decryption, and other dimensions.
[0048] 4. The encryption result generated by the present application by integrating digital coding and an improved symmetric reversible hash encryption algorithm is completely consistent with the formation and length of the encryption result of the original irreversible hash encryption algorithm, and can realize the uniform conversion of short text sequences of different lengths into a reversible hash code of a fixed length. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] Figure 1 A schematic diagram of a flow chart of a short text symmetric encryption and decryption method in one embodiment;
[0050] Figure 2 is a schematic diagram of a process flow of an encryption phase in an embodiment;
[0051] Figure 3 A schematic diagram of a decryption process in an embodiment;
[0052] Figure 4 A schematic diagram of a flow chart of an algorithm for converting a character sequence into a digital sequence in one embodiment;
[0053] Figure 5 A schematic diagram of a flow chart of an improved symmetric reversible hash encryption algorithm in an embodiment;
[0054] Figure 6 A schematic diagram of a flow chart of an improved symmetric reversible hash decryption algorithm in an embodiment;
[0055] Figure 7 A schematic diagram of a flow chart of a reversible algorithm for converting a digital sequence into a character sequence in one embodiment;
[0056] Figure 8 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0057] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0058] In one embodiment, Figure 1 As shown, a short text symmetric encryption and decryption method is provided, comprising the following steps:
[0059] Step S1, in the encryption stage, call the character sequence to digital sequence algorithm to perform primary encryption on the input short text sequence to be encrypted, generate a reversible digital sequence, and call the improved symmetric reversible hash encryption algorithm to perform secondary encryption on the reversible digital sequence to generate a fixed-length reversible hash code.
[0060] The encryption stage uses a hybrid symmetric encryption method. The specific steps are as follows: Figure 2 shown.
[0061] Step S2, in the decryption stage, call the improved symmetric reversible hash decryption algorithm to perform secondary decryption on the fixed-length reversible hash code to obtain a reversible digital sequence, and call the reversible digital sequence to character sequence algorithm to perform primary decryption on the reversible digital sequence to restore the decrypted short text sequence.
[0062] The decryption stage uses a hybrid symmetric decryption method. The specific steps are as follows: Figure 3 shown.
[0063] In one embodiment, the character sequence to digital sequence algorithm is called to perform primary encryption on the pre-entered short text sequence to be encrypted, and the overall steps of generating a reversible digital sequence are as follows: Figure 4 As shown, including:
[0064] (1) Construct a secret table that corresponds one-to-one between text characters and digital codes, and initialize an empty string Among them, each text character in the secret table is assigned a unique digital code corresponding to it, and all text characters and digital codes are unique.
[0065] Among them, the purpose of constructing the secret table is to construct a reversible mapping pair of text characters and digital codes. In addition to the secret table construction technology, secret code mapping technology or word vector conversion technology can also be used to construct a reversible mapping pair of text characters and digital codes.
[0066] Among them, the secret table construction technology refers to the collection, sorting and deduplication of conventional Chinese characters, numbers, letters, punctuation marks and special symbols to form a unique reversible mapping table of characters and digital codes, thereby completing the reversible conversion between text characters and digital codes. Furthermore, this process can also replace conventional Chinese characters, numbers, letters, punctuation marks and special symbols with characters in other languages such as Japanese characters, Korean characters, Tibetan characters, Latin characters, etc., deduplication, and numbering to construct the corresponding reversible secret table so as to be compatible with encryption and decryption tasks in other corresponding languages.
[0067] (2) Input the short text sequence to be encrypted.
[0068] (3) Segment the short text sequence according to individual characters to obtain an ordered first list. The characters in the first list are text characters, numbers, punctuation marks, and special symbols in the short text sequence;
[0069] (4) Loop through each character in the first list.
[0070] (41) Take the digital code corresponding to the current character from the secret table, add a specified separator after the digital code, and add the concatenated result to S. Among them, symbols such as space, underscore, and @ can be used as specified separators.
[0071] (42) After traversing all the characters in the first list, remove the extra specified separator at the last position of S to generate a reversible digital sequence. The encryption method for generating a reversible digital sequence is expressed as S=S+N+T, where N is the digital code and T is the specified separator.
[0072] (5) Output the generated reversible digital sequence.
[0073] This application considers that the traditional hash encryption algorithm has the advantages of fast encryption speed, high security and fixed encryption result length. However, it has a big disadvantage of irreversibility. It can only encrypt content but cannot decrypt it. Therefore, the traditional hash encryption algorithm can generally only be used as a digital signature and content consistency verification scenario, and cannot be used for encryption and decryption services. In order to fully retain the advantages of the hash encryption algorithm and overcome its irreversibility, after a large number of comparative experimental analyses, it was found that the traditional hash encryption algorithm is not completely irreversible, and can only be reversible under certain specific types, that is, it is a restricted reversible encryption algorithm. This application is based on the transformation of the hash encryption algorithm, and proposes an improved symmetric reversible hash encryption algorithm, which is a restricted reversible hash encryption algorithm, and cannot perform reversible hash encryption and decryption on all texts, but it can achieve reversible hash encryption and decryption for pure digital sequence texts.
[0074] In one embodiment, the improved symmetric reversible hash encryption algorithm is called to perform secondary encryption on the reversible digital sequence, and the overall steps of generating a fixed-length reversible hash code are as follows: Figure 5 As shown, including:
[0075] (1) Input the reversible digital sequence generated after the first level encryption (including the specified separator) and initialize an empty string .
[0076] (2) The reversible digital sequence is segmented according to single characters to obtain an ordered second list, wherein the characters in the second list are numbers and designated separators.
[0077] (3) Load the specified hash encryption algorithm SHA-512 to perform hash encryption on each number from 0 to 9 and the specified separator, and then use the original character as the key and the hash code corresponding to the original character as the value to construct<K,V> Yes, they are stored in the specified KV object M in sequence.
[0078] Among them, in addition to SHA-512, this application can also use other hash encryption algorithms such as MD5, SHA-1, SHA-128 and SHA-256 as basic algorithms for modification to obtain an improved symmetric reversible hash encryption and decryption algorithm.
[0079] (4) Iterate over each character in the second list.
[0080] (41) Take the current character as the key and extract the corresponding value from the KV object M. Take the truncated code of the specified position P of the value with a fixed length K as the reversible hash code of the current character.
[0081] (42) The reversible hash code of each character in the second list is sequentially concatenated until the reversible hash code H1 of all characters is obtained. The concatenation of H1 is expressed as H1=H1+HPK; wherein HPK is the reversible hash code of a single character.
[0082] (5) Perform hash encryption on the reversible digital sequence as a whole to obtain the reversible hash code H0 of the reversible digital sequence, then perform hash encryption on the mark bit, and take the truncated code (sequence separator) of the specified position P (P=2) and fixed length K (K=5) of the encrypted hash code as the hash code H2 of the mark bit. The mark bit is a manually set or default string.
[0083] Among them, the values of P and K must satisfy the following three conditions at the same time: P∈[0, Len (H0)-K], P+K≤ Len (H0), K is an integer not less than 2; wherein, Indicates a function for calculating the length of a string. In order to avoid the limitation of the number of bits and combinations of the obtained truncation code, it is generally not recommended to take too large values for P and K. Specifically, in this embodiment, the hash encryption algorithm uniformly loaded is SHA-512, which is a hexadecimal string with an encryption length of 128 bits, that is, In this embodiment, the value of P is 2 and the value of K is 5.
[0084] (6) Combine H0, H1 and H2 to obtain a fixed-length reversible hash code H.
[0085] Among them, the combination of H is expressed as
[0086] ;
[0087] in, Represents a function for intercepting a string.
[0088] (7) Output a fixed-length reversible hash code H.
[0089] Specifically, through the above improved symmetric reversible hash encryption algorithm, the reversible digital sequence to be encrypted is finally converted into a 128-bit reversible hash code H.
[0090] Traditional hash encryption algorithms are irreversible, but the improved symmetric reversible hash decryption algorithm of this application is reversible for digital sequences and can decrypt the original digital sequence. However, the settings of relevant parameters in the decryption process must be consistent with the relevant parameters of the improved symmetric reversible hash encryption algorithm, such as the values of the specified position P and the fixed length K and the specified separator T in the digital sequence must be completely consistent, and must meet the basic requirements of the symmetric encryption and decryption algorithm.
[0091] In one embodiment, the improved symmetric reversible hash decryption algorithm is called to perform secondary decryption on the fixed-length reversible hash code to obtain the complete steps of the reversible digital sequence as follows: Figure 6 As shown, including:
[0092] (1) Input the fixed-length reversible hash code H (including the separator T) that needs to be decrypted after the secondary encryption, and initialize an empty string .
[0093] (2) The fixed-length reversible hash code H is split according to the specified delimiter T to obtain the left fragment H0 and the right fragment H1, and H1 is grouped from left to right according to the fixed length K, and the grouped fragments are stored in the ordered third list in sequence. The specified delimiter T here is exactly the same as H2.
[0094] (3) Load the specified hash encryption algorithm SHA-512 to perform hash encryption on each number from 0 to 9 and the specified separator, and then use the original character as the key and the hash code corresponding to the original character as the value to construct<K,V> Yes, they are stored in the specified KV object M in sequence.
[0095] (4) Loop through and take out each grouped fragment in the third list one by one.
[0096] (41) Take the current group segment as the comparison target and extract the corresponding value from M, and take the truncated code of the specified position P with a fixed length K of the value and perform a cyclic match with the current group segment until the match is completed and stop the cycle, and reversely deduce the corresponding original character key based on the current matched value, and then get the real character s corresponding to the current group segment. Among them, the values of P and K in the secondary decryption are completely consistent with the values of P and K used by the secondary encryption algorithm.
[0097] (42) The real characters s corresponding to all the grouped fragments are concatenated in sequence to obtain a reversible digital sequence. The concatenation method of the reversible digital sequence obtained by decryption and restoration is expressed as S=S+s.
[0098] (5) Output the generated reversible digital sequence.
[0099] In one embodiment, the reversible digital sequence to character sequence algorithm is called to perform primary decryption on the reversible digital sequence, and the complete steps of restoring the decrypted short text sequence are as follows: Figure 7 As shown, including:
[0100] (1) Load the secret table built during the encryption process and initialize a string variable .
[0101] Specifically, the reversible mapping pairs of text characters and digital codes constructed by the cipher code mapping technology or word vector conversion technology during the encryption process can also be loaded. It should be noted that the cipher table or reversible mapping pair loaded during the decryption process must be the same cipher table or reversible mapping pair file as the cipher table or reversible mapping pair constructed during the encryption process, and the content is completely consistent. This is also the basic requirement of the symmetric encryption and decryption algorithm.
[0102] (2) Input the reversible digital sequence obtained after secondary decryption.
[0103] (3) Split the reversible digital sequence according to the specified separator to obtain an ordered fourth list.
[0104] (4) Traverse each digital code in the fourth list.
[0105] (41) Take out the text character corresponding to the current digital code from the secret table.
[0106] (42) The text characters taken out each time are concatenated in sequence to restore the decrypted short text sequence. The concatenation method of the text characters is represented by T=T+t; where t represents the text character corresponding to the digital code.
[0107] (5) Output the restored decrypted short text sequence.
[0108] Furthermore, the short text symmetric encryption and decryption method provided in the present application has been verified through encryption and decryption experiments of real key short text data. The results show that the short text symmetric encryption and decryption method that combines digital coding and symmetric reversible hashing can encrypt and decrypt short text data efficiently, securely and accurately.
[0109] It should be understood that although Figure 1-Figure 7 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 1-Figure 7 At least part of the steps may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least part of the sub-steps or stages of other steps.
[0110] In one embodiment, a short text symmetric encryption and decryption device is provided, comprising:
[0111] The encryption module is used to perform primary encryption on the input short text sequence to be encrypted by calling the character sequence to digital sequence algorithm in the encryption stage to generate a reversible digital sequence, and to perform secondary encryption on the reversible digital sequence by calling the improved symmetric reversible hash encryption algorithm to generate a fixed-length reversible hash code;
[0112] The decryption module is used to call the improved symmetric reversible hash decryption algorithm to perform secondary decryption on the fixed-length reversible hash code in the decryption stage to obtain a reversible digital sequence, and call the reversible digital sequence to character sequence algorithm to perform primary decryption on the reversible digital sequence to restore the decrypted short text sequence.
[0113] For the specific definition of the short text symmetric encryption and decryption device, please refer to the definition of the short text symmetric encryption and decryption method above, which will not be repeated here. The various modules in the above-mentioned short text symmetric encryption and decryption device can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0114] In one embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Figure 8 As shown. The computer device includes a processor, a memory, a network interface, a display screen and an input device connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a short text symmetric encryption and decryption method is implemented. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a key, trackball or touchpad set on the computer device housing, or an external keyboard, touchpad or mouse, etc.
[0115] Those skilled in the art will understand that Figure 8 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0116] In one embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0117] In the encryption phase, the character sequence to digital sequence algorithm is called to perform primary encryption on the input short text sequence to be encrypted to generate a reversible digital sequence, and the improved symmetric reversible hash encryption algorithm is called to perform secondary encryption on the reversible digital sequence to generate a fixed-length reversible hash code;
[0118] In the decryption stage, the improved symmetric reversible hash decryption algorithm is called to perform secondary decryption on the fixed-length reversible hash code to obtain a reversible digital sequence, and the reversible digital sequence to character sequence algorithm is called to perform primary decryption on the reversible digital sequence to restore the decrypted short text sequence.
[0119] In one embodiment, a computer readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
[0120] In the encryption phase, the character sequence to digital sequence algorithm is called to perform primary encryption on the input short text sequence to be encrypted to generate a reversible digital sequence, and the improved symmetric reversible hash encryption algorithm is called to perform secondary encryption on the reversible digital sequence to generate a fixed-length reversible hash code;
[0121] In the decryption stage, the improved symmetric reversible hash decryption algorithm is called to perform secondary decryption on the fixed-length reversible hash code to obtain a reversible digital sequence, and the reversible digital sequence to character sequence algorithm is called to perform primary decryption on the reversible digital sequence to restore the decrypted short text sequence.
[0122] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0123] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0124] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A short text symmetric encryption and decryption method, characterized in that: The method comprises: In the encryption stage, the character sequence to digital sequence algorithm is called to perform primary encryption on the input short text sequence to be encrypted to generate a reversible digital sequence, and the improved symmetric reversible hash encryption algorithm is called to perform secondary encryption on the reversible digital sequence to generate a fixed-length reversible hash code; In the decryption stage, the improved symmetric reversible hash decryption algorithm is called to perform secondary decryption on the fixed-length reversible hash code to obtain a reversible digital sequence, and the reversible digital sequence to character sequence algorithm is called to perform primary decryption on the reversible digital sequence to restore the decrypted short text sequence; The improved symmetric reversible hash encryption algorithm is called to perform secondary encryption on the reversible digital sequence to generate a fixed-length reversible hash code, including: Get the reversible digital sequence generated after the first level of encryption and initialize an empty string ; The reversible digital sequence is divided according to single characters to obtain an ordered second list; wherein the characters in the second list are numbers and designated separators; Load the specified hash encryption algorithm uniformly to perform hash encryption on each number from 0 to 9 and the specified separator, and then use the original character as the key and the hash code corresponding to the original character as the value to construct<K,V> Yes, store them in the specified KV object M in sequence; Traverse each character in the second list, take the current character as the key and take the corresponding value from the KV object M, and take the truncated code of the value at the specified position P with a fixed length K as the reversible hash code of the current character, and sequentially concatenate the reversible hash codes of each character in the second list until the reversible hash code H1 of all characters is obtained; wherein the concatenation method of H1 is expressed as H1=H1+HPK; wherein HPK is the reversible hash code of a single character; Performing overall hash encryption on the reversible digital sequence to obtain a reversible hash code H0 of the reversible digital sequence; The mark bit is hashed and encrypted, and the truncated code of the specified position P and fixed length K is taken as the hash code H2 of the mark bit; wherein the mark bit is a manually set or default string; the values of P and K must simultaneously meet the following three conditions: P∈[0, Len (H0)-K], P+K≤ Len (H0), K is an integer not less than 2; H0, H1 and H2 are combined and concatenated to obtain a fixed-length reversible hash code H, where the combination and concatenation of H is expressed as ; in, Represents a function used to intercept a string. Represents a function that calculates the length of a string; The improved symmetric reversible hash decryption algorithm is called to perform secondary decryption on the fixed-length reversible hash code to obtain a reversible digital sequence, including: Get the fixed-length reversible hash code H generated after secondary encryption that needs to be decrypted, and initialize an empty string ; The fixed-length reversible hash code H is divided according to H2 to obtain a left segment H0 and a right segment H1, and H1 is grouped from left to right in sequence according to the fixed length K, and the grouped segments are stored in the ordered third list in sequence; Load the specified hash encryption algorithm uniformly to perform hash encryption on each number from 0 to 9 and the specified separator, and then use the original character as the key and the hash code corresponding to the original character as the value to construct<K,V> Yes, store them in the specified KV object M in sequence; Loop through and take out each packet segment in the third list in turn, take out the corresponding value from M with the current packet segment as the comparison target, and take the truncated code of the specified position P with a fixed length K of the value and perform cyclic matching with the current packet segment until the matching is completed and stop the loop, and reversely deduce the corresponding original character key according to the current matched value, so as to obtain the real character s corresponding to the current packet segment; wherein, the values of P and K in the secondary decryption are completely consistent with the values of P and K adopted by the secondary encryption algorithm; The real characters s corresponding to all the grouped fragments are concatenated in sequence to obtain a reversible digital sequence; wherein the concatenation method of the reversible digital sequence obtained by decryption and restoration is expressed as S=S+s.
2. The method according to claim 1, characterized in that Call the character sequence to digital sequence algorithm to perform primary encryption on the pre-entered short text sequence to be encrypted, generating a reversible digital sequence, including: Construct a reversible mapping of text characters to digital codes and initialize an empty string ; Each character in the reversible mapping pair is assigned a unique digital code corresponding to it, and all characters and digital codes are not repeated; Input a short text sequence to be encrypted, and segment the short text sequence according to individual characters to obtain an ordered first list; wherein the characters in the first list are text characters, numbers, punctuation marks, and special symbols in the short text sequence; Loop through each character in the first list, take out the digital code corresponding to the current character from the reversible mapping pair, add a specified separator after the digital code for concatenation, and add the concatenation result to S; After traversing and concatenating all the characters in the first list in sequence, remove the redundant designated separator at the last position in S to generate a reversible digital sequence; wherein, the concatenation method of encrypting and generating the reversible digital sequence is expressed as S=S+N+T; wherein N is the digital code and T is the designated separator.
3. The method according to claim 2, characterized in that The methods for constructing reversible mapping pairs of text characters and digital codes include: secret code mapping technology, word vector conversion technology and secret table construction technology; wherein, the secret table construction technology refers to collecting, organizing and removing duplicates of conventional Chinese characters, numbers, letters, punctuation marks and special symbols to form a unique reversible mapping table of characters and digital codes.
4. The method according to claim 1, characterized in that The hash encryption algorithms include SHA-512, MD5, SHA-1, SHA-128 and SHA-256.
5. The method according to claim 1, characterized in that Calling a reversible digital sequence to character sequence algorithm to perform primary decryption on the reversible digital sequence to restore the decrypted short text sequence, including: Load the reversible mapping of text characters and digital codes constructed during the encryption process and initialize a string variable ; Obtaining the reversible digital sequence obtained after the secondary decryption, and dividing the reversible digital sequence according to the specified separator to obtain an ordered fourth list; Traverse each digital code in the fourth list, take out the text character corresponding to the current digital code from the reversible mapping pair, and splice the text characters taken out each time in turn to restore the decrypted short text sequence; wherein the splicing method of the text characters is expressed as T=T+t; wherein t represents the text character corresponding to the digital code.
6. A short text symmetric encryption and decryption device, characterized in that: The device comprises: The encryption module is used to call the character sequence to digital sequence algorithm to perform primary encryption on the input short text sequence to be encrypted in the encryption stage to generate a reversible digital sequence, and call the improved symmetric reversible hash encryption algorithm to perform secondary encryption on the reversible digital sequence to generate a fixed-length reversible hash code; A decryption module is used to call an improved symmetric reversible hash decryption algorithm to perform secondary decryption on the fixed-length reversible hash code in the decryption stage to obtain a reversible digital sequence, and call a reversible digital sequence to character sequence algorithm to perform primary decryption on the reversible digital sequence to restore the decrypted short text sequence; The improved symmetric reversible hash encryption algorithm is called to perform secondary encryption on the reversible digital sequence to generate a fixed-length reversible hash code, including: Get the reversible digital sequence generated after the first level of encryption and initialize an empty string ; The reversible digital sequence is divided according to single characters to obtain an ordered second list; wherein the characters in the second list are numbers and designated separators; Load the specified hash encryption algorithm uniformly to perform hash encryption on each number from 0 to 9 and the specified separator, and then use the original character as the key and the hash code corresponding to the original character as the value to construct<K,V> Yes, store them in the specified KV object M in sequence; Traverse each character in the second list, take the current character as the key and take the corresponding value from the KV object M, and take the truncated code of the value at the specified position P with a fixed length K as the reversible hash code of the current character, and sequentially concatenate the reversible hash codes of each character in the second list until the reversible hash code H1 of all characters is obtained; wherein the concatenation method of H1 is expressed as H1=H1+HPK; wherein HPK is the reversible hash code of a single character; Performing overall hash encryption on the reversible digital sequence to obtain a reversible hash code H0 of the reversible digital sequence; The mark bit is hashed and encrypted, and the truncated code of the specified position P and fixed length K is taken as the hash code H2 of the mark bit; wherein the mark bit is a manually set or default string; the values of P and K must simultaneously meet the following three conditions: P∈[0, Len (H0)-K], P+K≤ Len (H0), K is an integer not less than 2; H0, H1 and H2 are combined and concatenated to obtain a fixed-length reversible hash code H, where the combination and concatenation of H is expressed as ; in, Represents a function used to intercept a string. Represents a function that calculates the length of a string; The improved symmetric reversible hash decryption algorithm is called to perform secondary decryption on the fixed-length reversible hash code to obtain a reversible digital sequence, including: Get the fixed-length reversible hash code H generated after secondary encryption that needs to be decrypted, and initialize an empty string ; The fixed-length reversible hash code H is divided according to H2 to obtain a left segment H0 and a right segment H1, and H1 is grouped from left to right in sequence according to the fixed length K, and the grouped segments are stored in the ordered third list in sequence; Load the specified hash encryption algorithm uniformly to perform hash encryption on each number from 0 to 9 and the specified separator, and then use the original character as the key and the hash code corresponding to the original character as the value to construct<K,V> Yes, store them in the specified KV object M in sequence; Loop through and take out each packet segment in the third list in turn, take out the corresponding value from M with the current packet segment as the comparison target, and take the truncated code of the specified position P with a fixed length K of the value and perform cyclic matching with the current packet segment until the matching is completed and stop the loop, and reversely deduce the corresponding original character key according to the current matched value, so as to obtain the real character s corresponding to the current packet segment; wherein, the values of P and K in the secondary decryption are completely consistent with the values of P and K adopted by the secondary encryption algorithm; The real characters s corresponding to all the grouped fragments are concatenated in sequence to obtain a reversible digital sequence; wherein the concatenation method of the reversible digital sequence obtained by decryption and restoration is expressed as S=S+s.
7. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 5 are implemented.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.
