Encryption method, decryption method, device, electronic device and storage medium
By generating dynamic encryption keys and encrypting encrypted texts in packets, the shortcomings of existing encryption algorithms in terms of encryption efficiency and security are solved, and efficient and secure encryption processing is achieved.
Patent Information
- Application Number
- CN202211181965.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-27
- Publication Date
- 2024-11-29
- Estimated Expiration
- 2042-09-27
AI Technical Summary
Existing encryption algorithms have shortcomings in terms of encryption efficiency and security, especially the problems of inefficient serial encryption and the susceptibility of fixed keys to be attacked.
By obtaining two target prime numbers that are prime numbers and generating a target random number, a dynamic encryption key is generated based on these prime numbers and random numbers, and the encrypted text is encrypted in packets, supporting parallel encryption processing.
It improves encryption efficiency and security, and the keys are different every time they are encrypted, avoiding the security risks of fixed keys, and solving the problem of inefficient serial encryption.
Smart Images

Figure CN115632765B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of encryption technology, and in particular to an encryption method, a decryption method, a device, an electronic device and a storage medium. Background Art
[0002] Encryption is the process of changing the original information data with a special algorithm so that even if unauthorized users obtain the encrypted information, they still cannot understand the content of the information because they do not know the decryption method, thereby improving the security of the information data.
[0003] At present, commonly used encryption algorithms include DES (Data Encryption Standard), AES (Advanced Encryption Standard), 3DES (Triple DES) and other encryption algorithms. However, these encryption algorithms are usually serial encryption methods with low encryption efficiency. At the same time, commonly used encryption algorithms use fixed keys, which are extremely easy to be attacked, resulting in low security of the encryption algorithms. Summary of the invention
[0004] The technical problem to be solved by the embodiments of the present application is to provide an encryption method, a decryption method, a device, an electronic device and a storage medium to solve the problem of low efficiency of serial encryption, which can improve the security of the encryption algorithm while improving the encryption efficiency.
[0005] In a first aspect, an embodiment of the present application provides an encryption method, the method comprising:
[0006] Obtain two target prime numbers that are prime to each other, and generate a target random number, wherein both of the target prime numbers are greater than a set value;
[0007] Generate a dynamic encryption key based on the two target prime numbers and the target random number;
[0008] Performing group processing on the text to be encrypted to obtain multiple groups of subtexts to be encrypted of the text to be encrypted;
[0009] Based on the dynamic encryption key, the multiple groups of sub-texts to be encrypted are encrypted to obtain the encrypted texts of the sub-texts to be encrypted.
[0010] Optionally, the target random number is a random number of N bytes, where N is an even number.
[0011] The generating a dynamic encryption key based on the two target prime numbers and the target random number comprises:
[0012] Generate an initial key pair according to the two target prime numbers;
[0013] Perform byte splitting and byte conversion processing on the target random number to generate two random parameters of the same bytes corresponding to the target random number;
[0014] The dynamic encryption key is generated according to the initial key pair and the key special solution corresponding to the two random parameters.
[0015] Optionally, generating the dynamic encryption key according to the initial key pair and a key-specific solution corresponding to the two random parameters includes:
[0016] Solving the initial key pair and the two random parameters based on the remainder theorem to obtain a solution result;
[0017] Obtaining a minimum result among the solution results, and using the minimum result as the key-specific solution;
[0018] The dynamic encryption key is determined according to the first target bit number and the key special solution.
[0019] Optionally, determining the dynamic encryption key according to the first target bit number and the key special solution includes:
[0020] When the number of bits of the key special solution is less than the first target number of bits, padding the key special solution to generate a padding special solution of the first target number of bits, and using the padding special solution as the dynamic encryption key;
[0021] When the number of bits of the key-specific solution is equal to the first target number of bits, using the key-specific solution as the dynamic encryption key;
[0022] When the number of bits of the key-specific solution is greater than the first target number of bits, the last first target number of bits of the key-specific solution is intercepted as the dynamic encryption key.
[0023] Optionally, the encrypting the plurality of groups of subtexts to be encrypted based on the dynamic encryption key to obtain encrypted texts of the subtexts to be encrypted includes:
[0024] Performing XOR processing on the multiple groups of subtexts to be encrypted to obtain multiple groups of plaintexts to be encrypted;
[0025] Performing parallel encryption processing on the multiple groups of plaintexts to be encrypted based on the dynamic encryption key to obtain multiple groups of ciphertexts;
[0026] Concatenate the target random number and the multiple groups of ciphertexts to generate a ciphertext byte stream;
[0027] The ciphertext byte stream is encoded to obtain the encrypted text of the text to be encrypted.
[0028] Optionally, encoding the ciphertext byte stream to obtain an encrypted text of the text to be encrypted includes:
[0029] Perform Base64 encoding on the ciphertext byte stream to obtain an encrypted text of the text to be encrypted; or
[0030] The ciphertext byte stream is subjected to hexadecimal encoding to obtain the encrypted text of the text to be encrypted.
[0031] In a second aspect, an embodiment of the present application provides a decryption method, the method comprising:
[0032] Obtain two target prime numbers that are prime to each other, wherein both of the target prime numbers are greater than a set value;
[0033] Obtain the target random number based on the obtained encrypted text;
[0034] Based on the target prime number and the target random number, generate a dynamic decryption key for the encrypted text;
[0035] The encrypted text is processed in groups to obtain multiple groups of sub-texts to be decrypted corresponding to the encrypted text;
[0036] Based on the dynamic decryption key, the multiple groups of sub-texts to be decrypted are decrypted to obtain decrypted texts.
[0037] Optionally, obtaining a target random number according to the obtained encrypted text includes:
[0038] Decoding the encrypted text to obtain a ciphertext byte stream of the encrypted text;
[0039] The first N bytes of the ciphertext byte stream in the ciphertext byte stream are obtained as the target random number, where N is an even number.
[0040] Optionally, generating a dynamic decryption key for the encrypted text based on the target prime number and the target random number includes:
[0041] Generate an initial key pair according to the two target prime numbers;
[0042] Perform byte splitting and byte conversion processing on the target random number to generate two random parameters of the same bytes corresponding to the target random number;
[0043] The dynamic decryption key is generated according to the initial key pair and the key special solution corresponding to the two random parameters.
[0044] Optionally, generating the dynamic decryption key according to the initial key pair and a key-specific solution corresponding to the two random parameters includes:
[0045] Solving the initial key pair and the two random parameters based on the remainder theorem to obtain a solution result;
[0046] Obtaining a minimum result among the solution results, and using the minimum result as the key-specific solution;
[0047] The dynamic decryption key is determined according to the first target bit number and the key special solution.
[0048] Optionally, determining the dynamic decryption key according to the first target bit number and the key special solution includes:
[0049] When the number of bits of the key special solution is less than the first target number of bits, padding the key special solution to generate a padding special solution of the first target number of bits, and using the padding special solution as the dynamic decryption key;
[0050] When the number of bits of the key-specific solution is equal to the first target number of bits, using the key-specific solution as the dynamic decryption key;
[0051] When the number of bits of the key special solution is greater than the first target number of bits, a special solution of the key special solution after the first target number of bits is obtained as the dynamic decryption key.
[0052] In a third aspect, an embodiment of the present application provides an encryption device, the device comprising:
[0053] A target random number acquisition module is used to acquire two target prime numbers that are prime to each other and generate a target random number, wherein both of the two target prime numbers are greater than a set value;
[0054] A dynamic encryption key generation module, used for generating a dynamic encryption key based on the two target prime numbers and the target random number;
[0055] A module for obtaining subtexts to be encrypted, used for grouping the texts to be encrypted to obtain multiple groups of subtexts to be encrypted;
[0056] The encrypted text acquisition module is used to encrypt the multiple groups of sub-texts to be encrypted based on the dynamic encryption key to obtain the encrypted text of the sub-text to be encrypted.
[0057] Optionally, the target random number is a random number of N bytes, where N is an even number.
[0058] The dynamic encryption key generation includes:
[0059] A first key pair generating unit, used for generating an initial key pair according to the two target prime numbers;
[0060] A first random parameter generating unit, configured to perform byte splitting and byte conversion processing on the target random number to generate two random parameters of the same bytes corresponding to the target random number;
[0061] The dynamic encryption key generation unit is used to generate the dynamic encryption key according to the initial key pair and the key special solution corresponding to the two random parameters.
[0062] Optionally, the dynamic encryption key generation unit includes:
[0063] A first solution result acquisition subunit is used to solve the initial key pair and the two random parameters based on the remainder theorem to obtain a solution result;
[0064] A first key-specific solution obtaining subunit is used to obtain a minimum result among the solution results, and use the minimum result as the key-specific solution;
[0065] The dynamic encryption key determination subunit is used to determine the dynamic encryption key according to the first target bit number and the key special solution.
[0066] Optionally, the dynamic encryption key determination subunit includes:
[0067] A first encryption key acquisition subunit is used to, when the number of bits of the key special solution is less than the first target number of bits, pad the key special solution to generate a padding special solution of the first target number of bits, and use the padding special solution as the dynamic encryption key;
[0068] A second encryption key acquisition subunit is used to use the key-specific solution as the dynamic encryption key when the number of bits of the key-specific solution is equal to the first target number of bits;
[0069] The third encryption key acquisition subunit is used to intercept the last first target number of bits of the key-specific solution as the dynamic encryption key when the number of bits of the key-specific solution is greater than the first target number of bits.
[0070] Optionally, the encrypted text acquisition module includes:
[0071] A plaintext acquisition unit to be encrypted, used for performing XOR processing on the multiple groups of subtexts to be encrypted to obtain multiple groups of plaintexts to be encrypted;
[0072] A plurality of ciphertext acquisition units, configured to perform parallel encryption processing on the plurality of plaintexts to be encrypted based on the dynamic encryption key to obtain a plurality of ciphertexts;
[0073] A ciphertext byte stream generating unit, used for performing concatenation processing on the target random number and the multiple groups of ciphertexts to generate a ciphertext byte stream;
[0074] The encrypted text acquisition unit is used to encode the ciphertext byte stream to obtain the encrypted text of the text to be encrypted.
[0075] Optionally, the encrypted text acquisition unit includes:
[0076] A first encrypted text acquisition subunit is used to perform Base64 encoding on the ciphertext byte stream to obtain an encrypted text of the text to be encrypted;
[0077] The second encrypted text acquisition subunit is used to perform hexadecimal encoding on the ciphertext byte stream to obtain the encrypted text of the text to be encrypted.
[0078] In a fourth aspect, an embodiment of the present application provides a decryption device, the device comprising:
[0079] A target prime number acquisition module is used to acquire two target prime numbers that are prime to each other, wherein both of the two target prime numbers are greater than a set value;
[0080] A random number acquisition module is used to obtain a target random number based on the obtained encrypted text;
[0081] A dynamic decryption key generation module, used to generate a dynamic decryption key for the encrypted text based on the target prime number and the target random number;
[0082] A subtext acquisition module to be decrypted is used to group the encrypted text to obtain multiple groups of subtexts to be decrypted corresponding to the encrypted text;
[0083] The decrypted text acquisition module is used to decrypt the multiple groups of sub-texts to be decrypted based on the dynamic decryption key to obtain the decrypted text.
[0084] Optionally, the random number acquisition module includes:
[0085] A ciphertext byte stream acquisition unit, used for decoding the encrypted text to obtain a ciphertext byte stream of the encrypted text;
[0086] The target random number acquisition unit is used to acquire the first N bytes of the ciphertext byte stream in the ciphertext byte stream as the target random number, where N is an even number.
[0087] Optionally, the dynamic decryption key generation module includes:
[0088] A second key pair generating unit, used for generating an initial key pair according to the two target prime numbers;
[0089] A second random parameter generating unit is used to perform byte splitting and byte conversion processing on the target random number to generate two random parameters of the same bytes corresponding to the target random number;
[0090] The dynamic decryption key generation unit is used to generate the dynamic decryption key according to the initial key pair and the key special solution corresponding to the two random parameters.
[0091] Optionally, the dynamic decryption key generation unit includes:
[0092] A second solution result acquisition subunit is used to solve the initial key pair and the two random parameters based on the remainder theorem to obtain a solution result;
[0093] A second key-specific solution obtaining subunit is used to obtain a minimum result among the solution results, and use the minimum result as the key-specific solution;
[0094] The dynamic decryption key determination subunit is used to determine the dynamic decryption key according to the first target bit number and the key special solution.
[0095] Optionally, the dynamic decryption key determination subunit includes:
[0096] A first decryption key acquisition subunit is used to fill in the key special solution when the number of bits of the key special solution is less than the first target number of bits, generate a fill-in special solution of the first target number of bits, and use the fill-in special solution as the dynamic decryption key;
[0097] A second decryption key acquisition subunit is used to use the key-specific solution as the dynamic decryption key when the number of bits of the key-specific solution is equal to the first target number of bits;
[0098] The third decryption key acquisition subunit is used to obtain a special solution of the key special solution having a number of bits after the first target number of bits as the dynamic decryption key when the number of bits of the key special solution is greater than the first target number of bits.
[0099] In a fifth aspect, an embodiment of the present application provides an electronic device, including:
[0100] A processor, a memory, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the encryption method described in any one of the above items or the decryption method described in any one of the above items is implemented.
[0101] In a sixth aspect, an embodiment of the present application provides a computer-readable storage medium. When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device can execute any of the encryption methods described above, or any of the decryption methods described above.
[0102] Compared with the prior art, the embodiments of the present application have the following advantages:
[0103] In an embodiment of the present application, two target prime numbers that are prime to each other are obtained, and a target random number is generated, wherein both target prime numbers are greater than a set value, a dynamic encryption key is generated based on the two target prime numbers and the target random number, the text to be encrypted is grouped, and multiple groups of subtexts to be encrypted are obtained, and multiple groups of subtexts to be encrypted are encrypted based on the dynamic encryption key to obtain the encrypted text of the text to be encrypted. The embodiment of the present application generates a dynamic key by combining a random number, so the key is different each time the encryption is performed, which can improve the security of data encryption. At the same time, by grouping the text to be encrypted into multiple groups of subtexts to be encrypted, it is possible to support the dynamic key to encrypt multiple groups of subtexts to be encrypted in parallel, thereby solving the problem of low efficiency of serial encryption and improving encryption efficiency.
[0104] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0105] Figure 1 A flowchart of an encryption method provided in an embodiment of the present application;
[0106] Figure 2 A flowchart of a method for generating a dynamic encryption key provided in an embodiment of the present application;
[0107] Figure 3 A flowchart of a method for determining a dynamic encryption key provided in an embodiment of the present application;
[0108] Figure 4 A flowchart of a method for obtaining a dynamic encryption key provided in an embodiment of the present application;
[0109] Figure 5 A flowchart of a method for obtaining encrypted text provided in an embodiment of the present application;
[0110] Figure 6 A flowchart of another method for obtaining encrypted text provided in an embodiment of the present application;
[0111] Figure 7 A schematic diagram of an AES packet encryption process based on a dynamic key provided in an embodiment of the present application;
[0112] Figure 8 A flowchart of a decryption method provided in an embodiment of the present application;
[0113] Fig. 9 A flowchart of a random number acquisition method provided in an embodiment of the present application;
[0114] Fig.10A flowchart of a method for generating a dynamic decryption key provided in an embodiment of the present application;
[0115] Fig.11 A flowchart of a method for determining a dynamic decryption key provided in an embodiment of the present application;
[0116] Fig.12 A flowchart of a method for obtaining a dynamic decryption key provided in an embodiment of the present application;
[0117] Fig.13 A schematic diagram of an AES packet decryption process based on a dynamic key provided in an embodiment of the present application;
[0118] Fig.14 A schematic diagram of the structure of an encryption device provided in an embodiment of the present application;
[0119] Fig.15 A schematic diagram of the structure of a decryption device provided in an embodiment of the present application;
[0120] Fig.16 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0121] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, the present application is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0122] The terms used in the embodiments of the present application are only for the purpose of describing specific embodiments, and are not intended to limit the present application. The singular forms "a", "said" and "the" used in the embodiments of the present application and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings.
[0123] The widely used CBC (Cipher Block Chaining) mode has the problem of serial encryption and low efficiency, which is particularly prominent when encrypting longer information. The most popular counter mode supports parallel computing and is more efficient. Since the secret key is fixed during encryption and decryption, and the random number is transmitted in plain text, the encryptor must ensure that the random number encrypted each time must be unique, otherwise there is a risk of replay attack. The existing AES encryption is all static key mode, that is, the same secret key will encrypt the same plain text multiple times to obtain the same ciphertext. This will result in low encryption efficiency and low security of the encryption algorithm.
[0124] In order to solve the above problems, the invention idea of the embodiment of the present application is: a dynamic encryption key is generated by a random number and two prime numbers, and the encryption key is different each time, which can improve the security of the encryption algorithm. At the same time, by grouping the encrypted text, parallel encryption can be supported when encrypting with a dynamic encryption key, which can effectively improve the encryption efficiency.
[0125] Next, the technical solution of the present application is described in detail in conjunction with the following embodiments.
[0126] Reference Figure 1 , shows a flowchart of the steps of an encryption method provided by an embodiment of the present application, such as Figure 1 As shown, the encryption method may include: step 101, step 102, step 103 and step 104.
[0127] Step 101: Obtain two target prime numbers that are prime to each other, and generate a target random number, wherein both of the two target prime numbers are greater than a set value.
[0128] In this embodiment, the target prime number refers to a prime number greater than a set value, wherein the set value is a pre-set value for screening prime numbers, and the size of the set value can be determined according to business requirements, and this embodiment does not impose any restrictions on this.
[0129] The target random number is a randomly generated value. The number of bytes of the target random number is an even number.
[0130] When encrypting the text to be encrypted, two target prime numbers (such as 251, 163, etc.) that are prime to each other and both greater than a set value can be obtained.
[0131] At the same time, a target random number can be randomly generated. For example, a 32-bit hexadecimal random number is generated as the target random number. Assuming that the target random number is: 16fd27068baf433b82eb8c7fada847da, which corresponds to 16 bytes, the corresponding byte stream is: x16\xfd'\x06\x8b\xafC;\x82\xeb\x8c\x7f\xad\xa8G\xda, etc.
[0132] After obtaining two mutually prime target prime numbers and generating a target random number, step 102 is executed.
[0133] Step 102: Generate a dynamic encryption key based on the two target prime numbers and the target random number.
[0134] A dynamic encryption key is a key used to encrypt text to be encrypted. Since the random number is different each time it is encrypted, the key for each encryption is a dynamic key.
[0135] After obtaining two mutually prime target prime numbers and generating a target random number, a dynamic encryption key can be generated based on the two target prime numbers and the target random number. Specifically, a key pair can be generated based on the two target prime numbers, and a special solution can be obtained based on the two random parameters corresponding to the target random number and the target prime number to generate a dynamic encryption key. Figure 2 This is described in detail as follows.
[0136] Reference Figure 2 , shows a flowchart of a method for generating a dynamic encryption key provided by an embodiment of the present application, such as Figure 2 As shown, the dynamic encryption key generation method may include: step 201, step 202 and step 203.
[0137] Step 201: Generate an initial key pair according to the two target prime numbers.
[0138] In this embodiment, after two target prime numbers are obtained, an initial key pair can be generated according to the two target prime numbers.
[0139] After the initial key pair is generated according to the two target prime numbers, step 203 is executed.
[0140] Step 202: Perform byte splitting and byte conversion processing on the target random number to generate two random parameters of the same bytes corresponding to the target random number.
[0141] After the target random number is generated, the target random number can be byte-split and byte-converted to generate two random parameters of the same bytes corresponding to the target random number. Specifically, the target random number is a random number of N bytes, where N is an even number. After the target random number is generated, the target random number can be byte-split to obtain two split random numbers with the same bytes. Then the split random number is byte-converted to obtain two random parameters of the same bytes corresponding to the target random number. For example, the target random number is a 32-bit hexadecimal random number, assuming: 16fd27068baf433b82eb8c7fada847da, which corresponds to 16 bytes, and the corresponding byte stream is: x16\xfd'\x06\x8b\xafC;\x82\xeb\x8c\x7f\xad\xa8G\xda. The first and last 8 bytes are each converted into a decimal number and separated into 2 random parameters, respectively:
[0142] Random parameter 1: 65414632567958551445968527399106851682;
[0143] Random Parameters 2: 74698438912063031305537089530964173921.
[0144] It can be understood that the above examples are merely examples listed to better illustrate the technical solutions of the embodiments of the present application, and are not intended to be the sole limitations of the embodiments.
[0145] After performing byte splitting and byte conversion processing on the target random number to generate two random parameters of the same bytes corresponding to the target random number, step 203 is executed.
[0146] Step 203: Generate the dynamic encryption key according to the initial key pair and the key solution corresponding to the two random parameters.
[0147] After the target random number is byte-splitting and byte-converting processed to generate two random parameters of the same bytes corresponding to the target random number, a dynamic encryption key can be generated according to the initial key pair and the key special solution corresponding to the two random parameters.
[0148] In a specific implementation, after obtaining two random parameters, the minimum special solution of the sum of the two random parameters (i.e., the key special solution in this example) can be obtained, and then the dynamic encryption key can be determined based on the target number of bits and the key special solution. Figure 3 This is described in detail as follows.
[0149] Reference Figure 3 , shows a flowchart of the steps of a method for determining a dynamic encryption key provided by an embodiment of the present application, such as Figure 3 As shown, the dynamic encryption key determination method may include: step 301, step 302 and step 303.
[0150] Step 301: Solve the initial key pair and the two random parameters based on the remainder theorem to obtain a solution result.
[0151] In this embodiment, after obtaining the initial key pair and the two random parameters, the initial key pair and the two random parameters can be solved based on the remainder theorem to obtain a solution result. Specifically, the remainder theorem can be used to solve the general solution of the initial key pair and the two random parameters, and the solved general solution is used as the solution result.
[0152] After the initial key pair and the two random parameter pairs are solved based on the remainder theorem to obtain a solution result, step 302 is executed.
[0153] Step 302: Obtain the minimum result among the solution results, and use the minimum result as the key-specific solution.
[0154] After solving the initial key pair and two random parameter pairs based on the remainder theorem to obtain the solution results, the minimum result in the solution results can be obtained and the minimum result can be used as the key special solution. For example, the initial key pair is: 251, 163, the two random parameters are 65414632567958551445968527399106851682 and 74698438912063031305537089530964173921, after substituting the initial key pair and the two random parameters into the formula of the remainder theorem, the minimum special solution calculated is 26085, and the result: 26085 can be used as the key special solution, etc.
[0155] It can be understood that the above examples are merely examples listed for a better understanding of the technical solutions of the embodiments of the present application, and are not intended to be the sole limitation to the embodiments.
[0156] After obtaining the minimum result among the solution results and using the minimum result as the key-specific solution, step 303 is executed.
[0157] Step 303: Determine the dynamic encryption key according to the first target bit number and the key special solution.
[0158] The first target bit number refers to the pre-set number of bits used to determine the dynamic encryption key. In this example, the first target bit number can be 128 bits, 256 bits, etc. Specifically, the specific value of the first target bit number can be determined according to business requirements, and this embodiment does not impose any restrictions on this.
[0159] After obtaining the minimum result in the solution and using the minimum result as the key special solution, the dynamic encryption key can be determined according to the first target number of digits and the key special solution. Specifically, when the number of digits of the key special solution is less than the first target number of digits, padding is performed. When the number of digits of the key special solution is greater than or equal to the first target number of digits, the last special solution of the first target number of digits is intercepted as the dynamic encryption key. This implementation process can be combined with Figure 4 This is described in detail as follows.
[0160] Reference Figure 4 , shows a flowchart of a method for obtaining a dynamic encryption key provided by an embodiment of the present application, such as Figure 4 As shown, the dynamic encryption key acquisition method may include: step 401, step 402 and step 403.
[0161] Step 401: When the number of bits of the key-specific solution is less than the first target number of bits, the key-specific solution is padded to generate a padded special solution of the first target number of bits, and the padded special solution is used as the dynamic encryption key.
[0162] Step 402: When the number of bits of the key-specific solution is equal to the first target number of bits, the key-specific solution is used as the dynamic encryption key.
[0163] Step 403: When the number of bits of the key-specific solution is greater than the first target number of bits, intercept the last first target number of bits of the key-specific solution as the dynamic encryption key.
[0164] In this embodiment, after obtaining the special key solution, the number of bits of the special key solution may be compared with the first target number of bits.
[0165] When the number of bits of the key special solution is less than the first target number of bits, the key special solution can be padded to generate the padded feature of the first target number of bits, and the padded feature can be used as the dynamic encryption key. For example, the calculated key special solution is 26085, and the first target number of bits is 16 bits. At this time, the key special solution can be padded to obtain the padded special solution: 2608526085260852. At this time, the padded special solution: 2608526085260852 can be used as the dynamic encryption key.
[0166] When the number of bits of the key-specific solution is equal to the first target number of bits, the key-specific solution can be used as a dynamic encryption key.
[0167] When the number of bits of the key feature is greater than the first target number of bits, the special solution of the key after the first target number of bits can be obtained as a dynamic encryption key. For example, when the calculated special solution of the key is: 2608526082608526085260852608, the special solution of the last 16 bits: 8526085260852608 can be used as a dynamic encryption key, etc.
[0168] In this example, the first target number of bits can be determined according to the length range defined by the AES algorithm, and is not a unique fixed value. In the specific implementation, the length range defined by the AES algorithm is D = {128, 196, 256}, and the calculated key solution is: T, if len(T) <128, then 128 bits are added, if len(T) > = 128 and len(T) <196, then the next 128 bits are taken as the dynamic key. If len(T) > = 196 and len(T) < 256, then the next 196 bits can be taken as the dynamic key. If len(T) > 256, then 256 bits can be taken as the dynamic key, etc. Among them, len(T) represents the number of bits of the length of T calculated.
[0169] It can be understood that the above examples are merely examples listed for a better understanding of the technical solutions of the embodiments of the present application, and are not intended to be the sole limitation to the embodiments.
[0170] After the dynamic encryption key is generated based on the two target prime numbers and the target random number, step 104 is performed.
[0171] Step 103: Group the text to be encrypted to obtain multiple groups of sub-texts to be encrypted.
[0172] The text to be encrypted refers to the text that needs to be encrypted.
[0173] After obtaining the text to be encrypted, the text to be encrypted can be grouped to obtain multiple groups of subtexts to be encrypted. In a specific implementation, the text to be encrypted can be grouped according to a specific length. If the last group of the text to be encrypted is less than the specific length, padding can be performed. For example, the plaintext to be encrypted (i.e., the text to be encrypted in this example) 0123456789abcdef0 has 17 bits in total. After padding, the plaintext to be encrypted after padding is obtained, 0123456789abcdef0\x0f\x0f\x0f\x0f\x 0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f, the first group is 16 bits: 0123456789abcdef, the second group is 16: 0\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f, among which there are 15 null values f, etc.
[0174] It can be understood that the above examples are merely examples listed for a better understanding of the technical solutions of the embodiments of the present application, and are not intended to be the sole limitation to the embodiments.
[0175] After the text to be encrypted is grouped to obtain multiple groups of sub-texts to be encrypted, step 104 is executed.
[0176] Step 104: Based on the dynamic encryption key, the multiple groups of sub-texts to be encrypted are encrypted to obtain encrypted texts of the sub-texts to be encrypted.
[0177] After obtaining the dynamic encryption key and multiple groups of subtexts to be encrypted, the multiple groups of subtexts to be encrypted can be encrypted based on the dynamic encryption key to obtain encrypted texts of the texts to be encrypted. Specifically, after obtaining the multiple groups of subtexts to be encrypted, the multiple groups of subtexts to be encrypted can be XORed to obtain multiple groups of plaintexts to be encrypted, and then the multiple groups of plaintexts to be encrypted can be encrypted in parallel using the dynamic encryption key to obtain encrypted texts. Figure 5 This is described in detail as follows.
[0178] Reference Figure 5, shows a flowchart of the steps of a method for obtaining encrypted text provided by an embodiment of the present application, such as Figure 5 As shown, the encrypted text acquisition method may include: step 501, step 502, step 503 and step 504.
[0179] Step 501: Perform XOR processing on the multiple groups of subtexts to be encrypted to obtain multiple groups of plaintexts to be encrypted.
[0180] In this embodiment, Exclusive OR (XOR) is a mathematical operator that can be applied to logical operations. The mathematical symbol of XOR is “⊕” and the computer symbol is “eor”. Its operation rules are: If the values of a and b are different, the XOR result is 1. If the values of a and b are the same, the XOR result is 0.
[0181] After obtaining multiple groups of subtexts to be encrypted, the multiple groups of subtexts to be encrypted can be XORed to obtain multiple groups of plaintexts to be encrypted. Specifically, multiple groups of subtexts to be encrypted can be XORed by accumulating counters to obtain the plaintexts to be encrypted of each group of subtexts to be encrypted. For example, after performing counter accumulation XOR on the plaintext groups to be encrypted after padding in the above step 103, 0123456789abcdef⊕0b0≤0123456789abcdef can be obtained. 0 / x0f / x0f / x0f / x0f / x0f / x0f / x0f / x0f / x0f / x0f / x0f / x0f / x0f / x0f / x0f⊕0b 1≤0 / x0f / x0f / x0f / x0f / x0f / x0f / x0f / x0f / x0f / x0f / x0f / x0f / x0f / x0f / x0e.
[0182] It can be understood that the above examples are merely examples listed for a better understanding of the technical solutions of the embodiments of the present application, and are not intended to be the sole limitation to the embodiments.
[0183] After performing XOR processing on multiple groups of subtexts to be encrypted to obtain multiple groups of plaintexts to be encrypted, step 502 is executed.
[0184] Step 502: Performing parallel encryption processing on the multiple groups of plaintexts to be encrypted based on the dynamic encryption key to obtain multiple groups of ciphertexts.
[0185] After performing XOR processing on multiple groups of subtexts to be encrypted to obtain multiple groups of plaintexts to be encrypted, multiple groups of plaintexts to be encrypted can be encrypted in parallel based on the dynamic encryption key to obtain multiple groups of ciphertexts. Specifically, the dynamic encryption key can be used to perform byte replacement, row shift, column confusion and round key addition on multiple groups of plaintexts to be encrypted, and each group of ciphertexts can be obtained after multiple rounds of transformation.
[0186] After multiple groups of plaintexts to be encrypted are encrypted in parallel based on the dynamic encryption key to obtain multiple groups of ciphertexts, step 503 is executed.
[0187] Step 503: concatenate the target random number and the multiple groups of ciphertexts to generate a ciphertext byte stream.
[0188] After multiple groups of plaintexts to be encrypted are encrypted in parallel based on the dynamic encryption key to obtain multiple groups of ciphertexts, the target random number and the multiple groups of ciphertexts can be spliced together to generate a ciphertext byte stream. That is, the target random number and all groups of ciphertexts are spliced together to obtain the ciphertext byte stream. Specifically, the target random number can be placed before the multiple groups of ciphertexts, and spliced together to obtain the ciphertext byte stream.
[0189] After the target random number and the multiple groups of ciphertexts are concatenated to generate a ciphertext byte stream, step 504 is executed.
[0190] Step 504: Encode the ciphertext byte stream to obtain the encrypted text of the text to be encrypted.
[0191] After the target random number and multiple groups of ciphertext are concatenated to generate a ciphertext byte stream, the ciphertext byte stream can be encoded to obtain the encrypted text of the text to be encrypted. Specifically, the ciphertext byte stream can be encoded in Base64 or hexadecimal to obtain the encrypted text. Figure 6 This is described in detail as follows.
[0192] Reference Figure 6 , shows a flowchart of another method for obtaining encrypted text provided by an embodiment of the present application, such as Figure 6 As shown, the encrypted text acquisition method may include: step 601 and step 602.
[0193] Step 601: Perform Base64 encoding on the ciphertext byte stream to obtain the encrypted text of the text to be encrypted.
[0194] In this embodiment, Base64 is an encoding method for transmitting 8-bit byte codes.
[0195] After obtaining the ciphertext byte stream, the ciphertext byte stream can be Base64 encoded to obtain the encrypted text of the to-be-encrypted text. For example, the obtained ciphertext byte stream is: \x16\xfd'\x06\x8b\xafC;\x82\xeb\x8c\x7f\xad\xa8G\xdar\xc6\xb2\xf0C\xd12\t\xb8]ve?N\x86\xa6F\xac\x8dJ\xd4\nF\xb6^\xc1\xbc\x84\xdc\x18\xd0E. The ciphertext byte stream is Base64 encoded to obtain the encrypted text: Fv0nBouvQzuC64x / rahH2nLGsvBD0TIJuF12ZT9OhqZGrI1K1ApGtl7BvITcGNBF.
[0196] It can be understood that the above examples are merely examples listed for a better understanding of the technical solutions of the embodiments of the present application, and are not intended to be the sole limitation to the embodiments.
[0197] Step 602: Perform hexadecimal encoding on the ciphertext byte stream to obtain the encrypted text of the text to be encrypted.
[0198] After obtaining the ciphertext byte stream, the ciphertext byte stream can be subjected to hexadecimal encoding processing, thereby obtaining the encrypted text of the text to be encrypted.
[0199] The embodiment of the present application generates a 16-byte random number, converts the front and rear 8 bytes to hexadecimal and then to decimal, obtains two random parameters, and then combines the key pair, substitutes into the remainder theorem, and calculates its smallest special solution as a dynamic key. Therefore, the key is different each time encryption is performed, and the same plaintext will be encrypted twice to obtain different ciphertexts, thereby ensuring the security of the data encryption process. At the same time, the key pair and random parameter encryption are used to obtain a dynamic key during encryption, and then the plaintext is grouped, and then XORed with the accumulated value of the counter, and then encrypted in parallel to obtain each group of ciphertexts, and finally assembled into the overall ciphertext. It can be seen that the present embodiment supports parallel computing during encryption, solves the problem of low efficiency of serial encryption, and improves encryption efficiency.
[0200] The encryption process for dynamic encryption keys can be as follows Figure 7 shown.
[0201] like Figure 7 As shown, a random number can be obtained, and a general solution can be obtained based on the random number and two relatively large prime numbers, and a dynamic key can be determined based on the smallest special solution in the general solution. At the same time, the text to be encrypted can be grouped, and the grouped plaintext can be XORed through a counter to obtain the plaintext to be encrypted, such as Figure 7The plaintext P1 and plaintext P2 are shown. Then, the dynamic key can be used to perform parallel encryption processing on the plaintexts P1 and P2 to obtain the corresponding ciphertexts C1 and C2. Finally, the obtained ciphertexts C1 and C2 can be encoded to obtain the final encrypted text.
[0202] The encryption method provided by the embodiment of the present application obtains two target prime numbers that are prime to each other and generates a target random number, wherein both target prime numbers are greater than a set value, generates a dynamic encryption key based on the two target prime numbers and the target random number, performs group processing on the encrypted text, obtains multiple groups of encrypted subtexts of the encrypted text, encrypts the multiple groups of encrypted subtexts based on the dynamic encryption key, and obtains the encrypted text of the encrypted text. The embodiment of the present application generates a dynamic key by combining a random number, so the key is different each time the encryption is performed, which can improve the security of data encryption. At the same time, by grouping the encrypted text into multiple groups of encrypted subtexts, it can support the dynamic key to encrypt multiple groups of encrypted subtexts in parallel, solves the problem of low efficiency of serial encryption, and can improve encryption efficiency.
[0203] Reference Figure 8 , shows a flowchart of the steps of a decryption method provided by an embodiment of the present application, such as Figure 8 As shown, the decryption method may include: step 801, step 802, step 803, step 804 and step 805.
[0204] Step 801: Obtain two target prime numbers that are prime to each other, wherein both of the target prime numbers are greater than a set value.
[0205] In this embodiment, the target prime number refers to a prime number greater than a set value, wherein the set value is a pre-set value for screening prime numbers, and the size of the set value can be determined according to business requirements, and this embodiment does not impose any restrictions on this.
[0206] When decrypting the encrypted ciphertext, two target prime numbers that are prime to each other can be obtained.
[0207] Step 802: Obtain a target random number based on the obtained encrypted text.
[0208] The encrypted text refers to the text obtained after the encryption process in the encryption embodiment.
[0209] After obtaining the encrypted text, the target random number can be obtained according to the encrypted text. Specifically, the encrypted text can be decoded to obtain a ciphertext byte stream, and then the target random number can be determined according to the ciphertext byte stream. Fig. 9 This is described in detail as follows.
[0210] Reference Fig. 9, shows a flow chart of the steps of a method for obtaining a target random number provided by an embodiment of the present application, such as Fig. 9 As shown, the target random number acquisition method may include: step 901 and step 902.
[0211] Step 901: Decode the encrypted text to obtain a ciphertext byte stream of the encrypted text.
[0212] In this embodiment, after obtaining the encrypted text, the encrypted text can be decoded to obtain the ciphertext byte stream of the encrypted text. Specifically, when the encoding method used in encryption is the Base64 encoding method, Base64 decoding can be used when decoding the encrypted text, and when the encoding method used in encryption is the hexadecimal encoding method, the hexadecimal decoding method can be used, etc.
[0213] It can be understood that the above examples are merely examples listed for a better understanding of the technical solutions of the embodiments of the present application, and are not intended to be the sole limitation to the embodiments.
[0214] After the encrypted text is decoded to obtain the ciphertext byte stream of the encrypted text, step 902 is executed.
[0215] Step 902: Obtain the first N bytes of the ciphertext byte stream as the target random number, where N is an even number.
[0216] After the encrypted text is decoded to obtain the ciphertext byte stream of the encrypted text, the ciphertext byte stream of the first N bytes in the ciphertext byte stream can be obtained as the target random number, where N is an even number and N is the number of bytes of the target random number in the above encryption embodiment.
[0217] After the target random number is obtained according to the obtained encrypted text, step 803 is executed.
[0218] Step 803: Generate a dynamic decryption key for the encrypted text based on the target prime number and the target random number.
[0219] After obtaining the target random number according to the encrypted text, a dynamic decryption key of the encrypted text can be generated based on the target prime number and the target random number. Specifically, an initial key pair can be generated according to the two target prime numbers, and the target random number can be byte-split and byte-converted to generate two random parameters, and a dynamic decryption key can be generated according to the initial key pair and the two random parameters. Fig.10 This is described in detail as follows.
[0220] Reference Fig.10 , shows a flowchart of a method for generating a dynamic decryption key provided by an embodiment of the present application, such as Fig.10 As shown, the dynamic decryption key generation method may include: step 1001, step 1002 and step 1003.
[0221] Step 1001: Generate an initial key pair according to the two target prime numbers.
[0222] In this embodiment, after two target prime numbers are obtained, an initial key pair can be generated according to the two target prime numbers.
[0223] After the initial key pair is generated according to the two target prime numbers, step 1003 is executed.
[0224] Step 1002: Perform byte splitting and byte conversion processing on the target random number to generate two random parameters of the same bytes corresponding to the target random number.
[0225] After the target random number is generated, the target random number can be byte-split and byte-converted to generate two random parameters of the same bytes corresponding to the target random number. Specifically, the target random number is a random number of N bytes, where N is an even number. After the target random number is generated, the target random number can be byte-split to obtain two split random numbers with the same bytes. Then the split random number is byte-converted to obtain two random parameters of the same bytes corresponding to the target random number. For example, the target random number is a 32-bit hexadecimal random number, assuming: 16fd27068baf433b82eb8c7fada847da, which corresponds to 16 bytes, and the corresponding byte stream is: x16\xfd'\x06\x8b\xafC;\x82\xeb\x8c\x7f\xad\xa8G\xda. The first and last 8 bytes are each converted into a decimal number and separated into 2 random parameters, respectively:
[0226] Random parameter 1: 65414632567958551445968527399106851682;
[0227] Random Parameters 2: 74698438912063031305537089530964173921.
[0228] It can be understood that the above examples are merely examples listed to better illustrate the technical solutions of the embodiments of the present application, and are not intended to be the sole limitations of the embodiments.
[0229] After performing byte splitting and byte conversion processing on the target random number to generate two random parameters of the same bytes corresponding to the target random number, step 1003 is executed.
[0230] Step 1003: Generate the dynamic decryption key according to the initial key pair and the key special solution corresponding to the two random parameters.
[0231] After the target random number is byte-splitting and byte-converting processed to generate two random parameters of the same bytes corresponding to the target random number, a dynamic decryption key can be generated according to the initial key pair and the key special solution corresponding to the two random parameters.
[0232] In a specific implementation, after obtaining two random parameters, the minimum special solution of the sum of the two random parameters (i.e., the key special solution in this example) can be obtained, and then the dynamic decryption key can be determined based on the target number of bits and the key special solution. Fig.11 This is described in detail as follows.
[0233] Reference Fig.11 , shows a flowchart of the steps of a method for determining a dynamic decryption key provided by an embodiment of the present application, such as Fig.11 As shown, the dynamic decryption key determination method may include: step 1101, step 1102 and step 1103.
[0234] Step 1101: Solve the initial key pair and the two random parameters based on the remainder theorem to obtain a solution result.
[0235] In this embodiment, after obtaining the initial key pair and the two random parameters, the initial key pair and the two random parameters can be solved based on the remainder theorem to obtain a solution result. Specifically, the remainder theorem can be used to solve the general solution of the initial key pair and the two random parameters, and the solved general solution is used as the solution result.
[0236] After solving the initial key pair and the two random parameter pairs based on the remainder theorem to obtain a solution result, step 1102 is executed.
[0237] Step 1102: Obtain the minimum result among the solution results, and use the minimum result as the key-specific solution.
[0238] After solving the initial key pair and two random parameter pairs based on the remainder theorem to obtain the solution results, the minimum result in the solution results can be obtained and the minimum result can be used as the key special solution. For example, the initial key pair is: 251, 163, the two random parameters are 65414632567958551445968527399106851682 and 74698438912063031305537089530964173921, after substituting the initial key pair and the two random parameters into the formula of the remainder theorem, the minimum special solution calculated is 26085, and the result: 26085 can be used as the key special solution, etc.
[0239] It can be understood that the above examples are merely examples listed for a better understanding of the technical solutions of the embodiments of the present application, and are not intended to be the sole limitation to the embodiments.
[0240] After obtaining the minimum result among the solution results and using the minimum result as the key-specific solution, execute step 1103.
[0241] Step 1103: Determine the dynamic decryption key according to the first target bit number and the key special solution.
[0242] The first target bit number refers to the pre-set number of bits used to determine the dynamic encryption key. In this example, the first target bit number can be 128 bits, 256 bits, etc. Specifically, the specific value of the first target bit number can be determined according to business requirements, and this embodiment does not impose any restrictions on this.
[0243] After obtaining the minimum result in the solution and using the minimum result as the key-specific solution, the dynamic decryption key can be determined based on the first target number of digits and the key-specific solution. Specifically, when the number of digits of the key-specific solution is less than the first target number of digits, padding is performed. When the number of digits of the key-specific solution is greater than or equal to the first target number of digits, the last first target number of digits of the special solution is intercepted as the dynamic decryption key. This implementation process can be combined with Fig.12 This is described in detail as follows.
[0244] Reference Fig.12 , shows a flowchart of a method for obtaining a dynamic decryption key provided by an embodiment of the present application, such as Fig.12 As shown, the dynamic decryption key acquisition method may include: step 1201, step 1202 and step 1203.
[0245] Step 1201: When the number of bits of the key-specific solution is less than the first target number of bits, the key-specific solution is padded to generate a padded special solution of the first target number of bits, and the padded special solution is used as the dynamic decryption key.
[0246] Step 1202: When the number of bits of the key-specific solution is equal to the first target number of bits, the key-specific solution is used as the dynamic decryption key.
[0247] Step 1203: When the number of bits of the special solution of the key is greater than the first target number of bits, obtain the special solution of the key after the first target number of bits as the dynamic decryption key.
[0248] In this embodiment, after obtaining the special key solution, the number of bits of the special key solution may be compared with the first target number of bits.
[0249] When the number of bits of the key special solution is less than the first target number of bits, the key special solution can be padded to generate the padded feature of the first target number of bits, and the padded feature can be used as the dynamic decryption key. For example, the calculated key special solution is 26085, and the first target number of bits is 16 bits. At this time, the key special solution can be padded to obtain the padded special solution: 2608526085260852. At this time, the padded special solution: 2608526085260852 can be used as the dynamic decryption key.
[0250] When the number of bits of the key-specific solution is equal to the first target number of bits, the key-specific solution can be used as a dynamic decryption key.
[0251] When the number of bits of the key feature is greater than the first target number of bits, the special solution of the key after the first target number of bits can be obtained as the dynamic decryption key. For example, when the calculated special solution of the key is: 2608526082608526085260852608, the special solution of the last 16 bits: 8526085260852608 can be used as the dynamic decryption key, etc.
[0252] In this example, the first target number of bits can be determined according to the length range defined by the AES algorithm, and is not a unique fixed value. In the specific implementation, the length range defined by the AES algorithm is D = {128, 196, 256}, and the calculated key solution is: T, if len(T) < 128, then 128 bits are added, if len(T) > = 128 and len(T) < 196, then the next 128 bits are taken as the dynamic key. If len(T) > = 196 and len(T) < 256, then the next 196 bits can be taken as the dynamic key. If len(T) > 256, then 256 bits can be taken as the dynamic key, etc.
[0253] It can be understood that the above examples are merely examples listed for a better understanding of the technical solutions of the embodiments of the present application, and are not intended to be the sole limitation to the embodiments.
[0254] Step 804: grouping the encrypted text to obtain multiple groups of sub-texts to be decrypted corresponding to the encrypted text.
[0255] After obtaining the encrypted text, the encrypted text can be grouped to obtain multiple groups of subtexts to be decrypted corresponding to the encrypted text. It can be understood that in this example, the length of the encrypted text grouping is the same as the length of the encrypted text grouping in the above encryption embodiment. For example, when the encrypted text is grouped according to the length of 16 bytes, when the encrypted text corresponding to the encrypted text is grouped, it can also be grouped according to the length of 16 bytes.
[0256] After the encrypted text is grouped to obtain multiple groups of sub-texts to be decrypted corresponding to the encrypted text, step 805 is executed.
[0257] Step 805: Based on the dynamic decryption key, the multiple groups of sub-texts to be decrypted are decrypted to obtain decrypted texts.
[0258] After the encrypted text is processed in groups to obtain multiple groups of sub-texts to be decrypted corresponding to the encrypted text, the multiple groups of sub-texts to be decrypted can be decrypted based on the dynamic decryption key to obtain the decrypted text. Specifically, the dynamic decryption key can be used to perform round key addition, column confusion, row shift, and byte replacement, and the ciphertext after decryption of each group can be obtained after multiple rounds of transformation. Then, the ciphertext after decryption of each group is accumulated through the cumulative counter to obtain the plaintext of each group. Finally, the plaintext of each group is spliced together to obtain the decrypted text corresponding to the encrypted text.
[0259] In this embodiment, decryption is similar to encryption. First, the ciphertext is grouped according to the length of each group, and the first group is decomposed into random parameters. Then, the dynamic key is obtained by performing a calculation with the key pair. Then, the remaining ciphertext is decrypted in parallel, and then XORed with the accumulated value of the counter to obtain each group of plaintext. Therefore, the time complexity of the encryption and decryption process is 1.1, and it can be seen that this embodiment supports parallel computing during encryption and decryption, which solves the problem of low efficiency of serial decryption and improves the decryption efficiency.
[0260] For the decryption process, you can combine Fig.13 This is described in detail as follows.
[0261] like Fig.13 As shown, an initial key pair can be generated based on two mutually prime target prime numbers, and a general solution can be obtained based on the random number obtained from the encrypted text and the initial key, and a dynamic key (i.e., a dynamic decryption key) can be determined based on the minimum special solution in the general solution. Then, the encrypted text can be grouped to obtain multiple groups of subtexts to be decrypted, and then the dynamic key can be used to perform parallel decryption processing on the multiple groups of subtexts to be decrypted (i.e., group decryption as shown in the figure). Finally, the ciphertext after decryption of each group can be accumulated through an accumulation counter to obtain the plaintext of each group, and the plaintext of all groups can be spliced together to obtain the final plaintext, i.e., the decrypted text.
[0262] The decryption method provided in the embodiment of the present application obtains two target prime numbers that are prime to each other, wherein both of the target prime numbers are greater than a set value, obtains a target random number based on the obtained encrypted text, generates a dynamic decryption key for the encrypted text based on the target prime number and the target random number, performs group processing on the encrypted text, obtains multiple groups of subtexts to be decrypted corresponding to the encrypted text, and performs decryption processing on the multiple groups of subtexts to be decrypted based on the dynamic decryption key to obtain a decrypted text. The embodiment of the present application generates a dynamic key by combining a random number, so the key is different each time encryption is performed, which can improve the security of data encryption. At the same time, by grouping the encrypted text into multiple groups of subtexts to be decrypted, it can support the dynamic key to perform parallel decryption on multiple groups of subtexts to be decrypted, solves the problem of low efficiency of serial decryption, and can improve decryption efficiency.
[0263] Reference Fig.14 , shows a schematic diagram of the structure of an encryption device provided in an embodiment of the present application, such as Fig.14 As shown, the encryption device 1400 may include the following modules:
[0264] The target random number acquisition module 1410 is used to acquire two target prime numbers that are prime to each other and generate a target random number, wherein both of the two target prime numbers are greater than a set value;
[0265] A dynamic encryption key generation module 1420, configured to generate a dynamic encryption key based on the two target prime numbers and the target random number;
[0266] The to-be-encrypted subtext acquisition module 1430 is used to group the to-be-encrypted text to obtain multiple groups of to-be-encrypted subtexts of the to-be-encrypted text;
[0267] The encrypted text acquisition module 1440 is used to encrypt the multiple groups of sub-texts to be encrypted based on the dynamic encryption key to obtain the encrypted text of the sub-text to be encrypted.
[0268] Optionally, the target random number is a random number of N bytes, where N is an even number.
[0269] The dynamic encryption key generation includes:
[0270] A first key pair generating unit, used for generating an initial key pair according to the two target prime numbers;
[0271] A first random parameter generating unit, configured to perform byte splitting and byte conversion processing on the target random number to generate two random parameters of the same bytes corresponding to the target random number;
[0272] The dynamic encryption key generation unit is used to generate the dynamic encryption key according to the initial key pair and the key special solution corresponding to the two random parameters.
[0273] Optionally, the dynamic encryption key generation unit includes:
[0274] A first solution result acquisition subunit is used to solve the initial key pair and the two random parameters based on the remainder theorem to obtain a solution result;
[0275] A first key-specific solution obtaining subunit is used to obtain a minimum result among the solution results, and use the minimum result as the key-specific solution;
[0276] The dynamic encryption key determination subunit is used to determine the dynamic encryption key according to the first target bit number and the key special solution.
[0277] Optionally, the dynamic encryption key determination subunit includes:
[0278] A first encryption key acquisition subunit is used to, when the number of bits of the key special solution is less than the first target number of bits, pad the key special solution to generate a padding special solution of the first target number of bits, and use the padding special solution as the dynamic encryption key;
[0279] A second encryption key acquisition subunit is used to use the key-specific solution as the dynamic encryption key when the number of bits of the key-specific solution is equal to the first target number of bits;
[0280] The third encryption key acquisition subunit is used to intercept the last first target number of bits of the key-specific solution as the dynamic encryption key when the number of bits of the key-specific solution is greater than the first target number of bits.
[0281] Optionally, the encrypted text acquisition module includes:
[0282] A plaintext acquisition unit to be encrypted, used for performing XOR processing on the multiple groups of subtexts to be encrypted to obtain multiple groups of plaintexts to be encrypted;
[0283] A plurality of ciphertext acquisition units, configured to perform parallel encryption processing on the plurality of plaintexts to be encrypted based on the dynamic encryption key to obtain a plurality of ciphertexts;
[0284] A ciphertext byte stream generating unit, used for performing concatenation processing on the target random number and the multiple groups of ciphertexts to generate a ciphertext byte stream;
[0285] The encrypted text acquisition unit is used to encode the ciphertext byte stream to obtain the encrypted text of the text to be encrypted.
[0286] Optionally, the encrypted text acquisition unit includes:
[0287] A first encrypted text acquisition subunit is used to perform Base64 encoding on the ciphertext byte stream to obtain an encrypted text of the text to be encrypted;
[0288] The second encrypted text acquisition subunit is used to perform hexadecimal encoding on the ciphertext byte stream to obtain the encrypted text of the text to be encrypted.
[0289] The encryption device provided in the embodiment of the present application obtains two target prime numbers that are prime to each other and generates a target random number, wherein both target prime numbers are greater than a set value, generates a dynamic encryption key based on the two target prime numbers and the target random number, performs group processing on the encrypted text, obtains multiple groups of encrypted subtexts of the encrypted text, encrypts the multiple groups of encrypted subtexts based on the dynamic encryption key, and obtains the encrypted text of the encrypted text. The embodiment of the present application generates a dynamic key by combining a random number, so the key is different each time the encryption is performed, which can improve the security of data encryption. At the same time, by grouping the encrypted text into multiple groups of encrypted subtexts, it can support the dynamic key to encrypt multiple groups of encrypted subtexts in parallel, solves the problem of low efficiency of serial encryption, and can improve encryption efficiency.
[0290] Reference Fig.15 , shows a schematic diagram of the structure of a decryption device provided in an embodiment of the present application, such as Fig.15 As shown, the decryption device 1500 may include the following modules:
[0291] A target prime number acquisition module 1510 is used to acquire two target prime numbers that are prime to each other, wherein both of the two target prime numbers are greater than a set value;
[0292] A random number acquisition module 1520 is used to acquire a target random number according to the acquired encrypted text;
[0293] A dynamic decryption key generation module 1530, used to generate a dynamic decryption key for the encrypted text based on the target prime number and the target random number;
[0294] The subtext to be decrypted acquisition module 1540 is used to group the encrypted text to obtain multiple groups of subtext to be decrypted corresponding to the encrypted text;
[0295] The decrypted text acquisition module 1550 is used to decrypt the multiple groups of sub-texts to be decrypted based on the dynamic decryption key to obtain decrypted texts.
[0296] Optionally, the random number acquisition module includes:
[0297] A ciphertext byte stream acquisition unit, used for decoding the encrypted text to obtain a ciphertext byte stream of the encrypted text;
[0298] The target random number acquisition unit is used to acquire the first N bytes of the ciphertext byte stream in the ciphertext byte stream as the target random number, where N is an even number.
[0299] Optionally, the dynamic decryption key generation module includes:
[0300] A second key pair generating unit, used for generating an initial key pair according to the two target prime numbers;
[0301] A second random parameter generating unit is used to perform byte splitting and byte conversion processing on the target random number to generate two random parameters of the same bytes corresponding to the target random number;
[0302] The dynamic decryption key generation unit is used to generate the dynamic decryption key according to the initial key pair and the key special solution corresponding to the two random parameters.
[0303] Optionally, the dynamic decryption key generation unit includes:
[0304] A second solution result acquisition subunit is used to solve the initial key pair and the two random parameters based on the remainder theorem to obtain a solution result;
[0305] A second key-specific solution obtaining subunit is used to obtain a minimum result among the solution results, and use the minimum result as the key-specific solution;
[0306] The dynamic decryption key determination subunit is used to determine the dynamic decryption key according to the first target bit number and the key special solution.
[0307] Optionally, the dynamic decryption key determination subunit includes:
[0308] A first decryption key acquisition subunit is used to fill in the key special solution when the number of bits of the key special solution is less than the first target number of bits, generate a fill-in special solution of the first target number of bits, and use the fill-in special solution as the dynamic decryption key;
[0309] A second decryption key acquisition subunit is used to use the key-specific solution as the dynamic decryption key when the number of bits of the key-specific solution is equal to the first target number of bits;
[0310] The third decryption key acquisition subunit is used to obtain a special solution of the key special solution having a number of bits after the first target number of bits as the dynamic decryption key when the number of bits of the key special solution is greater than the first target number of bits.
[0311] The decryption device provided in the embodiment of the present application obtains two target prime numbers that are prime to each other, wherein both of the target prime numbers are greater than a set value, obtains a target random number based on the obtained encrypted text, generates a dynamic decryption key for the encrypted text based on the target prime number and the target random number, performs group processing on the encrypted text, obtains multiple groups of subtexts to be decrypted corresponding to the encrypted text, and performs decryption processing on the multiple groups of subtexts to be decrypted based on the dynamic decryption key to obtain decrypted text. The embodiment of the present application generates a dynamic key by combining a random number, so the key is different each time encryption is performed, which can improve the security of data encryption. At the same time, by grouping the encrypted text into multiple groups of subtexts to be decrypted, it can support the dynamic key to perform parallel decryption on multiple groups of subtexts to be decrypted, solves the problem of low efficiency of serial decryption, and can improve decryption efficiency.
[0312] An embodiment of the present application also provides an electronic device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program implements the above-mentioned encryption method or the above-mentioned decryption method when executed by the processor.
[0313] Fig.16 FIG. 1 is a schematic diagram showing the structure of an electronic device 1600 according to an embodiment of the present invention. Fig.16 As shown, the electronic device 1600 includes a central processing unit (CPU) 1601, which can perform various appropriate actions and processes according to computer program instructions stored in a read-only memory (ROM) 1602 or computer program instructions loaded from a storage unit 1608 to a random access memory (RAM) 1603. In RAM 1603, various programs and data required for the operation of the electronic device 1600 can also be stored. CPU 1601, ROM 1602 and RAM 1603 are connected to each other via a bus 1604. An input / output (I / O) interface 1605 is also connected to the bus 1604.
[0314] Multiple components in the electronic device 1600 are connected to the I / O interface 1605, including: an input unit 1606, such as a keyboard, a mouse, a microphone, etc.; an output unit 1607, such as various types of displays, speakers, etc.; a storage unit 1608, such as a disk, an optical disk, etc.; and a communication unit 1609, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 1609 allows the electronic device 1600 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0315] The various processes and processing described above may be performed by the processing unit 1601. For example, the method of any of the above embodiments may be implemented as a computer software program, which is tangibly contained in a computer-readable medium, such as the storage unit 1608. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 1600 via the ROM 1602 and / or the communication unit 1609. When the computer program is loaded into the RAM 1603 and executed by the CPU 1601, one or more actions in the method described above may be performed.
[0316] In addition, an embodiment of the present application further provides a computer-readable storage medium on which a computer program is stored, and when the program is executed by a processor, the above-mentioned encryption method or the above-mentioned decryption method is implemented.
[0317] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0318] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, devices, or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0319] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, terminals (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0320] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0321] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal so that a series of operating steps are executed on the computer or other programmable terminal to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable terminal. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0322] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present application.
[0323] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal. In the absence of further restrictions, the elements defined by the statement "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or terminal including the elements.
[0324] The above is a detailed introduction to an encryption method, decryption method, device, electronic device and storage medium provided by the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for general technical personnel in this field, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. An encryption method, characterized in that: The method comprises: Obtain two target prime numbers that are prime to each other, and generate a target random number, wherein both of the target prime numbers are greater than a set value; Generate a dynamic encryption key based on the two target prime numbers and the target random number; Performing group processing on the text to be encrypted to obtain multiple groups of subtexts to be encrypted of the text to be encrypted; Based on the dynamic encryption key, encrypt the multiple groups of subtexts to be encrypted to obtain encrypted texts of the subtexts to be encrypted; The target random number is a random number of N bytes, where N is an even number. The generating a dynamic encryption key based on the two target prime numbers and the target random number comprises: Generate an initial key pair according to the two target prime numbers; Perform byte splitting and byte conversion processing on the target random number to generate two random parameters of the same bytes corresponding to the target random number; Generate the dynamic encryption key according to the initial key pair and the key special solution corresponding to the two random parameters; The generating the dynamic encryption key according to the initial key pair and the key special solution corresponding to the two random parameters comprises: Solving the initial key pair and the two random parameters based on the remainder theorem to obtain a solution result; Obtaining a minimum result among the solution results, and using the minimum result as the key-specific solution; Determine the dynamic encryption key according to the first target number of bits and the key special solution; The step of encrypting the plurality of groups of subtexts to be encrypted based on the dynamic encryption key to obtain encrypted texts of the subtexts to be encrypted comprises: Performing XOR processing on the multiple groups of subtexts to be encrypted to obtain multiple groups of plaintexts to be encrypted; Performing parallel encryption processing on the multiple groups of plaintexts to be encrypted based on the dynamic encryption key to obtain multiple groups of ciphertexts; Concatenate the target random number and the multiple groups of ciphertexts to generate a ciphertext byte stream; The ciphertext byte stream is encoded to obtain the encrypted text of the text to be encrypted.
2. The method according to claim 1, characterized in that The determining the dynamic encryption key according to the first target number of bits and the key special solution includes: When the number of bits of the key special solution is less than the first target number of bits, padding the key special solution to generate a padding special solution of the first target number of bits, and using the padding special solution as the dynamic encryption key; When the number of bits of the key-specific solution is equal to the first target number of bits, using the key-specific solution as the dynamic encryption key; When the number of bits of the key-specific solution is greater than the first target number of bits, the last first target number of bits of the key-specific solution is intercepted as the dynamic encryption key.
3. The method according to claim 1, characterized in that The encoding process of the ciphertext byte stream to obtain the encrypted text of the text to be encrypted includes: Perform Base64 encoding on the ciphertext byte stream to obtain an encrypted text of the text to be encrypted; or The ciphertext byte stream is subjected to hexadecimal encoding to obtain the encrypted text of the text to be encrypted.
4. A decryption method, characterized in that: The method comprises: Obtain two target prime numbers that are prime to each other, wherein both of the target prime numbers are greater than a set value; Obtain the target random number based on the obtained encrypted text; Based on the target prime number and the target random number, generate a dynamic decryption key for the encrypted text; The encrypted text is processed in groups to obtain multiple groups of sub-texts to be decrypted corresponding to the encrypted text; Based on the dynamic decryption key, the multiple groups of subtexts to be decrypted are decrypted to obtain decrypted texts, including: using the dynamic key to perform parallel decryption on the multiple groups of subtexts to be decrypted, and accumulating the decrypted ciphertexts of each group through an accumulation counter to obtain the plaintexts of each group, and splicing the plaintexts of all groups together to obtain the decrypted texts; The step of obtaining a target random number according to the obtained encrypted text includes: Decoding the encrypted text to obtain a ciphertext byte stream of the encrypted text; Obtaining the first N bytes of the ciphertext byte stream as the target random number, where N is an even number; The step of generating a dynamic decryption key for the encrypted text based on the target prime number and the target random number comprises: Generate an initial key pair according to the two target prime numbers; Perform byte splitting and byte conversion processing on the target random number to generate two random parameters of the same bytes corresponding to the target random number; Generate the dynamic decryption key according to the initial key pair and the key special solution corresponding to the two random parameters; The step of generating the dynamic decryption key according to the initial key pair and the key special solution corresponding to the two random parameters comprises: Solving the initial key pair and the two random parameters based on the remainder theorem to obtain a solution result; Obtaining a minimum result among the solution results, and using the minimum result as the key-specific solution; Determine the dynamic decryption key according to the first target number of bits and the key special solution; Determining the dynamic decryption key according to the first target number of bits and the key special solution includes: When the number of bits of the key special solution is less than the first target number of bits, padding the key special solution to generate a padding special solution of the first target number of bits, and using the padding special solution as the dynamic decryption key; When the number of bits of the key-specific solution is equal to the first target number of bits, using the key-specific solution as the dynamic decryption key; When the number of bits of the key-specific solution is greater than the first target number of bits, the last first target number of bits of the key-specific solution is intercepted as the dynamic decryption key.
5. An encryption device, characterized in that: The device comprises: A target random number acquisition module is used to acquire two target prime numbers that are prime to each other and generate a target random number, wherein both of the two target prime numbers are greater than a set value; A dynamic encryption key generation module, used for generating a dynamic encryption key based on the two target prime numbers and the target random number; A module for obtaining subtexts to be encrypted, used for grouping the texts to be encrypted to obtain multiple groups of subtexts to be encrypted; An encrypted text acquisition module, used for encrypting the plurality of groups of subtexts to be encrypted based on the dynamic encryption key to obtain an encrypted text of the subtext to be encrypted; The target random number is a random number of N bytes, where N is an even number. The dynamic encryption key generation includes: A first key pair generating unit, used for generating an initial key pair according to the two target prime numbers; A first random parameter generating unit, configured to perform byte splitting and byte conversion processing on the target random number to generate two random parameters of the same bytes corresponding to the target random number; A dynamic encryption key generation unit, configured to generate the dynamic encryption key according to the initial key pair and a key solution corresponding to the two random parameters; The dynamic encryption key generation unit comprises: A first solution result acquisition subunit is used to solve the initial key pair and the two random parameters based on the remainder theorem to obtain a solution result; A first key-specific solution obtaining subunit is used to obtain a minimum result among the solution results, and use the minimum result as the key-specific solution; A dynamic encryption key determination subunit, used to determine the dynamic encryption key according to a first target number of bits and the key special solution; The encrypted text acquisition module comprises: A plaintext acquisition unit to be encrypted, used for performing XOR processing on the multiple groups of subtexts to be encrypted to obtain multiple groups of plaintexts to be encrypted; A plurality of ciphertext acquisition units, configured to perform parallel encryption processing on the plurality of plaintexts to be encrypted based on the dynamic encryption key to obtain a plurality of ciphertexts; A ciphertext byte stream generating unit, used for performing concatenation processing on the target random number and the multiple groups of ciphertexts to generate a ciphertext byte stream; The encrypted text acquisition unit is used to encode the ciphertext byte stream to obtain the encrypted text of the text to be encrypted.
6. A decryption device, characterized in that: The device comprises: A target prime number acquisition module is used to acquire two target prime numbers that are prime to each other, wherein both of the two target prime numbers are greater than a set value; A random number acquisition module is used to obtain a target random number based on the obtained encrypted text; A dynamic decryption key generation module, used to generate a dynamic decryption key for the encrypted text based on the target prime number and the target random number; A subtext acquisition module to be decrypted is used to group the encrypted text to obtain multiple groups of subtexts to be decrypted corresponding to the encrypted text; A decrypted text acquisition module is used to decrypt the multiple groups of subtexts to be decrypted based on the dynamic decryption key to obtain decrypted texts; the decrypted text acquisition module is specifically used to use the dynamic key to perform parallel decryption processing on the multiple groups of subtexts to be decrypted, and accumulate the decrypted ciphertexts of each group through an accumulation counter to obtain the plaintexts of each group, and splice the plaintexts of all groups together to obtain the decrypted text; The random number acquisition module comprises: A ciphertext byte stream acquisition unit, used for decoding the encrypted text to obtain a ciphertext byte stream of the encrypted text; A target random number acquisition unit, used to acquire the first N bytes of the ciphertext byte stream in the ciphertext byte stream as the target random number, where N is an even number; The dynamic decryption key generation module comprises: A second key pair generating unit, used for generating an initial key pair according to the two target prime numbers; A second random parameter generating unit is used to perform byte splitting and byte conversion processing on the target random number to generate two random parameters of the same bytes corresponding to the target random number; A dynamic decryption key generation unit, used to generate the dynamic decryption key according to the initial key pair and a key special solution corresponding to the two random parameters; The dynamic decryption key generation unit comprises: A second solution result acquisition subunit is used to solve the initial key pair and the two random parameters based on the remainder theorem to obtain a solution result; A second key-specific solution obtaining subunit is used to obtain a minimum result among the solution results, and use the minimum result as the key-specific solution; The dynamic decryption key determination subunit is used to determine the dynamic decryption key according to the first target bit number and the key special solution.
7. An electronic device, characterized in that: include: A processor, a memory, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the encryption method according to any one of claims 1 to 3 or the decryption method according to any one of claim 4 is implemented.
8. A computer-readable storage medium, characterized in that: When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the encryption method described in any one of claims 1 to 3, or the decryption method described in any one of claim 4.
Citation Information
Patent Citations
Data encryption method and device, data decryption method and device and storage medium
CN110401527A
Symmetrical fully homomorphic encryption method and device and storage medium
CN114491603A
Efficient outsourcing aggregation and specified acquisition method for multi-source data
CN114499822A
Encrypting device, decrypting device, cryptosystem including the same devices, encrypting method, and decrypting method
US20040208317A1
