Encryption and decryption method and device, equipment and storage medium

By encrypting and decrypting operations based on prime modulus and minimum common multiples, the problems of difficulty and low efficiency of key management are solved, and secure calculation and efficient processing of sensitive data in the encrypted state are realized.

CN119312373AActive Publication Date: 2025-01-14ASPIRE TECH (SHENZHEN) LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202411858461.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-17
Publication Date
2025-01-14
Estimated Expiration
2044-12-17

Smart Images

  • Figure CN119312373A_ABST
    Figure CN119312373A_ABST
Patent Text Reader

Abstract

The invention discloses an encryption and decryption method and device, equipment and a storage medium, and the method comprises the steps: determining a target modulus and a least common multiple based on a first prime number and a second prime number; determining a modular inversion correction value based on the least common multiple and the target modulus; acquiring to-be-encrypted data, wherein the to-be-encrypted data comprises first original data and second original data; based on the target modulus, encrypting the first original data and the second original data to obtain a first ciphertext and a second ciphertext; determining a ciphertext operation result based on the first ciphertext and the second ciphertext; and based on the modular inversion correction value, decrypting the ciphertext operation result to obtain a target plaintext. According to the invention, after the original data is encrypted based on the target modulus, each ciphertext is calculated, and the sensitive data of the user is calculated in the encryption state instead of being calculated after decryption in the calculation process, so that the security of the data is improved. And decrypting the ciphertext operation result to obtain a target plaintext.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to an encryption and decryption method, device, equipment and storage medium. Background Art

[0002] With the development of mobile Internet, people will encounter data privacy issues in their daily office work. For example, when a bank system calculates the total encrypted balance of an account, the usual practice is to decrypt the two amounts and then add the decrypted plaintexts to get the total balance. When the tax department conducts statistics and analysis on encrypted taxpayer data, a common method is to decrypt the taxpayer's tax amount and then summarize and add the decrypted plaintexts to get the taxpayer's statistical results. In the electronic voting and election system, when calculating the number of votes, the original historical votes need to be decrypted into plaintext, then added to the new votes, and finally the accumulated votes are encrypted and stored. To solve the above data security issues, the industry usually adopts technical routes, and the common implementation methods are as follows: 1) Symmetric encryption method: Generate symmetric keys and use AES and SM4 to encrypt and protect sensitive data. However, the encryption and decryption of symmetric encryption methods use the same key, which requires both parties to share the key securely. Key management is difficult, especially in large-scale systems.

[0003] 2) Asymmetric encryption method: Generate asymmetric keys and use RSA and SM2 to encrypt and protect sensitive data. However, the private key management of RSA and SM2 in asymmetric encryption is difficult, and asymmetric encryption and decryption are inefficient.

[0004] 3) Hybrid encryption method: Generate a pair of symmetric keys and asymmetric keys, use AES and SM4 to encrypt and protect sensitive data, and encrypt and store the content of the symmetric key using the asymmetric public key. However, hybrid encryption requires the operation of the private key of RSA and SM2, decryption to obtain the symmetric key, and then symmetrically decrypt the ciphertext. After decrypting the plaintext, it is operated in memory, and the plaintext data is easily leaked by memory snooping. Summary of the invention

[0005] Based on this, it is necessary to provide an encryption and decryption method, device, equipment and storage medium for the above technical problems to solve at least one of the above technical problems.

[0006] The present invention provides an encryption and decryption method, comprising: Based on the first prime number and the second prime number, determining a target modulus and a least common multiple; Determining a modulus inverse correction value based on the least common multiple and the target modulus; Acquire data to be encrypted, wherein the data to be encrypted includes first original data and second original data; Based on the target modulus, encrypt the first original data and the second original data respectively to obtain a first ciphertext corresponding to the first original data and a second ciphertext corresponding to the second original data; Determining a ciphertext operation result based on the first ciphertext and the second ciphertext; Based on the module inverse correction value, the ciphertext operation result is decrypted to obtain the target plaintext.

[0007] Optionally, according to an encryption and decryption method provided by the present invention, determining the modulus inverse correction value based on the least common multiple and the target modulus includes: In the forward recursion process: During the first recursion, the target modulus is assigned to the first parameter in the preset formula, the least common multiple is assigned to the second parameter in the preset formula, and the result of the first recursive calculation is determined in combination with the random number of the first recursion; In each subsequent recursive process, the value of the second parameter in the previous recursive process is assigned to the first parameter, the result of the previous recursive calculation is assigned to the second parameter, and the result of the current recursive process is determined in combination with the random number in the current recursive process, until the result of the current recursive process is 1; During the reverse recursion: Determine a calculation formula for each recursion in the forward recursive process, wherein the calculation formula includes a value of a first parameter, a value of a second parameter and a random number in the recursive process; Start reverse recursion from the last recursive calculation formula in the forward recursive process, so as to use the last recursive calculation formula as the current reverse recursive calculation formula; In the result of each recursion during the forward recursive calculation process, determine the result of the previous recursion corresponding to the current reverse recursion; Compare the value of the first parameter, the value of the second parameter and the random number in the current reverse recursive calculation formula with the result of the previous recursion; If there is a value that is the same as the result of the previous recursion, a target expansion is generated according to the calculation formula of the current reverse recursion and the calculation formula of the previous recursion, and the target expansion is used as the new calculation formula of the current reverse recursion, and the step of determining the result of the previous recursion corresponding to the current reverse recursion is returned to the result of each recursion in the forward recursive calculation process, until the reverse recursion reaches the calculation formula of the first recursion in the forward recursive process; The final target expansion is simplified to determine the modular inverse correction value according to the simplified formula.

[0008] Optionally, according to an encryption and decryption method provided by the present invention, encrypting the first original data and the second original data based on the target modulus to obtain a first ciphertext corresponding to the first original data and a second ciphertext corresponding to the second original data includes: Determine a first random factor and a second random factor; Based on the target modulus, determining an encryption base; Encrypting the first original data based on the target modulus, the encryption base, and the first random factor to obtain the first ciphertext; The second original data is encrypted based on the target modulus, the encryption base, and the second random factor to obtain the second ciphertext.

[0009] Optionally, according to an encryption and decryption method provided by the present invention, determining a ciphertext operation result based on the first ciphertext and the second ciphertext includes: Multiplying the first ciphertext and the second ciphertext to obtain a target ciphertext; Based on the target modulus and the target ciphertext operation, the ciphertext operation result is determined.

[0010] Optionally, according to an encryption and decryption method provided by the present invention, decrypting the ciphertext operation result based on the module inverse correction value to obtain the target plaintext includes: Performing a power modular operation on the ciphertext operation result to obtain a modular operation result; Multiplying the modular operation result and the modular inverse correction value to obtain a multiplication operation result; Based on the target modulus, a modulus operation is performed on the multiplication result to obtain the target plaintext.

[0011] Optionally, according to an encryption and decryption method provided by the present invention, performing a power modular operation on the ciphertext operation result to obtain a modular operation result includes: Determine a first operation result based on the ciphertext operation result, the target modulus, and the least common multiple; The modulo operation result is determined based on the first operation result and the target modulus.

[0012] Optionally, according to an encryption and decryption method provided by the present invention, determining the target modulus based on the first prime number and the second prime number includes: The product of the first prime number and the second prime number is used as the target modulus.

[0013] The present invention also provides an encryption and decryption device, comprising: A first determining module is used to determine a target modulus and a least common multiple based on a first prime number and a second prime number; A second determination module is used to determine a modulus inverse correction value based on the least common multiple and the target modulus; An acquisition module, used for acquiring data to be encrypted, wherein the data to be encrypted includes first original data and second original data; an encryption module, configured to encrypt the first original data and the second original data respectively based on the target modulus to obtain a first ciphertext corresponding to the first original data and a second ciphertext corresponding to the second original data; A calculation module, used for determining a ciphertext calculation result based on the first ciphertext and the second ciphertext; The decryption module is used to decrypt the ciphertext operation result based on the module inverse correction value to obtain the target plaintext.

[0014] The present invention also provides a computer device, comprising a memory, a processor, and computer-readable instructions stored in the memory and executable on the processor, wherein the processor implements the above encryption and decryption method when executing the computer-readable instructions.

[0015] The present invention also provides one or more readable storage media storing computer-readable instructions, and the computer-readable instructions implement the above encryption and decryption method when executed by a processor.

[0016] The above encryption and decryption method, device, equipment and storage medium include: determining a target modulus and a least common multiple based on a first prime number and a second prime number; determining a modulus inverse correction value based on the least common multiple and the target modulus; obtaining data to be encrypted, wherein the data to be encrypted includes a first original data and a second original data; encrypting the first original data and the second original data based on the target modulus, respectively, to obtain a first ciphertext corresponding to the first original data and a second ciphertext corresponding to the second original data; determining a ciphertext operation result based on the first ciphertext and the second ciphertext; decrypting the ciphertext operation result based on the modulus inverse correction value to obtain a target plaintext. The present invention determines the target modulus based on the first prime number and the second prime number, and then performs operations on each ciphertext after encrypting the original data according to the target modulus, that is, the user's sensitive data is not operated after decryption during the operation process, but is operated in an encrypted state, which effectively improves the security of the data; and then decrypts the ciphertext operation result to obtain the target plaintext, and performs encryption and decryption processing on the data by combining mathematical formulas to improve the efficiency of system operation. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.

[0018] Figure 1 is a schematic diagram of a flow chart of an encryption and decryption method in one embodiment of the present invention; Figure 2 is a schematic diagram of the structure of an encryption and decryption device in one embodiment of the present invention; Figure 3 is a schematic diagram of a computer device in one embodiment of the present invention. DETAILED DESCRIPTION

[0019] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0020] The terms used in one or more embodiments of the present invention are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of the present invention. The singular forms of "a", "said" and "the" used in one or more embodiments of the present invention are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in one or more embodiments of the present invention refers to and includes any or all possible combinations of one or more associated listed items.

[0021] In one embodiment, specifically, Figure 1 As shown, Figure 1 1 is a flow chart of an encryption and decryption method in an embodiment of the present invention. The embodiment of the present invention provides an encryption and decryption method, comprising the following steps: Step S11, based on the first prime number and the second prime number, determining the target modulus and the least common multiple; It should be noted that the first prime number and the second prime number refer to numbers that have no other positive factors except 1 and itself in a natural number greater than 1. For example, the first prime number prime_A is 7, and the second prime number prime_B is 11. The least common multiple refers to the smallest multiple shared by two or more integers.

[0022] Specifically, the product of the first prime number and the second prime number is used as the target modulus. In combination with the above example, the target modulus M=7×11=77. And according to the first prime number and the second prime number, the least common multiple is calculated. Optionally, the least common multiple is the least common multiple determined based on (prime_A-1) and (prime_B-1). Using the above example, prime_A-1=6; prime_B-1=10, the least common multiple LCF of 6 and 10 is 30.

[0023] Step S12, determining a modulus inverse correction value based on the least common multiple and the target modulus; Specifically, based on the least common multiple and the target modulus, the least common multiple is calculated in the target modulus to obtain the modulus correction value. It can be understood that: the forward and reverse recursive mathematical formulas are defined: T0=Q0-K0×P0, ..., T i =Q i -K i ×P i .

[0024] In the forward recursion process: The first recursive process: assign the target modulus to the first parameter in the preset formula, assign the least common multiple to the second parameter in the preset formula, and determine the result of the first recursive calculation in combination with the random number of the first recursion, wherein the preset formula represents the mathematical formula of the above recursion, and in the first recursion, the first parameter represents Q0, the second parameter represents P0, and K0 refers to the random number of the first recursion. That is, the calculation process of the first recursive step: 17=77-2×30. Further, in each subsequent recursive process, the value of the second parameter in the previous recursive process is assigned to the first parameter, the result of the previous recursive calculation is assigned to the second parameter, and the result of the current recursive process is determined in combination with the random number in the current recursive process, until the result of the current recursion is 1, and the forward recursive process ends. If the result of the recursion is not 1, the program will be interrupted and jumped out, and it is determined that the least common multiple and the target modulus do not meet the conditions, and the parameters need to be reselected for calculation.

[0025] When the result of the current recursion is 1, it proves that the parameter check has passed, and the reverse recursion process begins, as follows: Determine the calculation formula for each recursion in the forward recursive process, wherein the calculation formula includes the value of the first parameter, the value of the second parameter and the random number in the recursive process, for example, the calculation formula of the first recursive step: 17=77-2×30; further, reverse recursion is started from the calculation formula of the last recursion in the forward recursive process, that is, the calculation formula of the last recursion is used as the calculation formula of the current reverse recursion, and then the result of the previous recursion corresponding to the current reverse recursion is determined in the result of each recursion in the forward recursive calculation process, that is, the result of the second to last recursion in the forward recursive process; further, the value of the first parameter in the calculation formula of the current reverse recursion is used as the calculation formula of the current reverse recursion. The first value, the second parameter value and the random number are compared with the result of the previous recursion respectively; if there is a value that is the same as the result of the previous recursion, a target expansion is generated according to the calculation formula of the current reverse recursion and the calculation formula of the previous recursion, and the target expansion is used as the new calculation formula of the current reverse recursion, and the step of determining the result of the previous recursion corresponding to the current reverse recursion is returned to execute in the result of each recursion in the forward recursive calculation process, until the reverse recursion reaches the calculation formula of the first recursion in the forward recursive process, and the final target expansion is obtained; further, the final target expansion is simplified to obtain a simplified formula, and then the modular inverse correction value is determined according to the simplified formula.

[0026] Step S13, obtaining data to be encrypted, wherein the data to be encrypted includes first original data and second original data; It should be noted that the data to be encrypted is determined according to the actual data statistics application scenario, and the data to be encrypted includes the first original data and the second original data. For example, in the scenario where the banking system calculates the total encrypted balance of an account, the data to be encrypted refers to the two deposit balance data of the account; in the scenario where the taxpayer's data is counted, the data to be encrypted refers to the tax amount data of each taxpayer; in the electronic voting election system, the data to be encrypted refers to the original number of historical votes and the current number of votes, for example, the first original data Original_A is set to 4, and the second original data Original_B is set to 3. It can be understood that when an encrypted ciphertext is stored in the statistical application scenario, only the other unencrypted data is encrypted, that is, the data to be encrypted only includes one unencrypted original data.

[0027] Step S14, encrypting the first original data and the second original data based on the target modulus to obtain a first ciphertext corresponding to the first original data and a second ciphertext corresponding to the second original data; Specifically, a first random factor corresponding to the encryption of the first original data is determined, and a second random factor corresponding to the encryption of the second original data is determined, wherein the first random factor and the second random factor can be randomly generated, and the first random factor and the second random factor can be the same or different. Then, based on the target modulus and the first random factor, the first original data is encrypted to obtain a first ciphertext; in addition, based on the target modulus and the second random factor, the second original data is encrypted to obtain a second ciphertext. It should be noted that the encryption process of the original data is specifically described in the following embodiments and will not be repeated here.

[0028] Step S15, determining a ciphertext operation result based on the first ciphertext and the second ciphertext; Specifically, the first ciphertext and the second ciphertext are multiplied to obtain the target ciphertext; then, combined with the target modulus, a modulus operation is performed on the target ciphertext to obtain a ciphertext operation result, wherein the calculation formula of the ciphertext operation result is as follows: c_add_result=(Ciphertext_A×Ciphertext_B) mod M^2.

[0029] Where c_add_result is the result of the ciphertext operation, Ciphertext_A represents the first ciphertext, Ciphertext_B represents the second ciphertext, and M represents the target modulus. For example, assuming Ciphertext_A is 2621, Ciphertext_B is 5354, and M is 77, c_add_result=(2621×5354) mod 77 2 =4820.

[0030] Step S16, decrypting the ciphertext operation result based on the modulo inverse correction value to obtain the target plaintext.

[0031] Specifically, based on the target modulus and the least common multiple, the ciphertext operation result is subjected to a power modulus operation to obtain a modulus operation result; and then based on the modulus inverse correction value, the ciphertext operation result is decrypted to restore the target plaintext. The specific decryption process is specifically described in the following embodiments and will not be repeated here. It can be understood that in the scenario where the banking system calculates the total balance of two accounts, the target plaintext refers to the total deposit data of the account; in the scenario where the taxpayer's data is counted, the target plaintext refers to the total tax amount corresponding to the taxpayer; in the electronic voting election system, the target plaintext refers to the total number of votes.

[0032] The embodiment of the present invention, through the above scheme, includes: determining the target modulus and the least common multiple based on the first prime number and the second prime number; determining the modulus inverse correction value based on the least common multiple and the target modulus; obtaining the data to be encrypted, wherein the data to be encrypted includes the first original data and the second original data; encrypting the first original data and the second original data respectively based on the target modulus to obtain the first ciphertext corresponding to the first original data and the second ciphertext corresponding to the second original data; determining the ciphertext operation result based on the first ciphertext and the second ciphertext; decrypting the ciphertext operation result based on the modulus inverse correction value to obtain the target plaintext. The embodiment of the present invention determines the target modulus based on the first prime number and the second prime number, and after encrypting the original data according to the target modulus, operates on each ciphertext, that is, the user's sensitive data is not operated after decryption during the operation process, but is operated in an encrypted state, which effectively improves the security of the data; and then decrypts the ciphertext operation result to obtain the target plaintext, and encrypts and decrypts the data by combining mathematical formulas to improve the efficiency of system operation.

[0033] In one embodiment of the present invention, determining the modulus inverse correction value based on the least common multiple and the target modulus includes: In the forward recursion process: In the first recursive process, the target modulus is assigned to the first parameter in the preset formula, the lowest common multiple is assigned to the second parameter in the preset formula, and the result of the first recursive calculation is determined in combination with the random number of the first recursive process; in each subsequent recursive process, the value of the second parameter in the previous recursive process is assigned to the first parameter, the result of the previous recursive calculation is assigned to the second parameter, and the result of the current recursive process is determined in combination with the random number in the current recursive process, until the result of the current recursive process is 1; During the reverse recursion: Determine a calculation formula for each recursion in a forward recursive process, wherein the calculation formula includes the value of the first parameter, the value of the second parameter and a random number in the recursive process; start reverse recursion from the calculation formula of the last recursion in the forward recursive process, so as to use the calculation formula of the last recursion as the calculation formula of the current reverse recursion; determine the result of the previous recursion corresponding to the current reverse recursion in the result of each recursion in the forward recursive calculation process; compare the value of the first parameter, the value of the second parameter and the random number in the calculation formula of the current reverse recursion with the result of the previous recursion respectively; if there is a value that is the same as the result of the previous recursion, generate a target expansion formula according to the calculation formula of the current reverse recursion and the calculation formula of the previous recursion, and use the target expansion formula as the new calculation formula of the current reverse recursion, and return to the step of determining the result of the previous recursion corresponding to the current reverse recursion in the result of each recursion in the forward recursive calculation process, until reverse recursion reaches the calculation formula of the first recursion in the forward recursive process; simplify the final target expansion formula to determine the modular inverse correction value according to the simplified formula.

[0034] Specifically, it is necessary to check and verify the least common multiple and the target modulus, that is, in the forward recursive process: in the first recursive process, the target modulus is assigned to the first parameter in the preset formula, the least common multiple is assigned to the second parameter in the preset formula, and the result of the first recursive calculation is determined in combination with the random number of the first recursion.

[0035] For example: Example of a forward recursive constraint: T0 = Q0 - K0 × P0. In the first recursive process, Q0 = M, P0 = LCF; during the calculation process: 17 = 77 - 2 × 30.

[0036] Furthermore, in each subsequent recursive process, the value of the second parameter in the previous recursive process is assigned to the first parameter, the result of the previous recursive calculation is assigned to the second parameter, and the result of the current recursive process is determined in combination with the random number in the current recursive process, until the result of the current recursive process is 1, that is, when Ti is calculated: Make Q i =P i-1 ; Make P i =T i-1 ; When the forward recursion reaches Ti=1, the recursive operation stops.

[0037] The first recursive process: 17=77-2×30.

[0038] The second recursive process: 13=30-1×17.

[0039] The third recursive process: 4=17-1×13.

[0040] The fourth recursive process: 1=13-3×4.

[0041] The result of the fourth recursive process is 1, which proves that the parameter check is passed, and then the forward recursive operation is stopped. In addition, if the result of the recursion is not 1, the program will be interrupted and it will be determined that the least common multiple and the target modulus do not meet the conditions, and the first prime number and the second prime number need to be re-selected for calculation.

[0042] In the reverse recursive process (modulo the reverse correction process): Determine a calculation formula for each recursion in the forward recursive process, wherein the calculation formula includes the value of the first parameter, the value of the second parameter and a random number in the recursive process; start reverse recursion from the calculation formula of the last recursion in the forward recursive process, so as to use the calculation formula of the last recursion as the calculation formula of the current reverse recursion. For example, using the above example, start reverse recursion from the fourth recursive process in the forward recursive process: 1=13-3×4.

[0043] Furthermore, in the result of each recursion in the forward recursive calculation process, determine the result of the previous recursion corresponding to the current reverse recursion; for example, reverse recursion starts from the fourth recursive process in the forward recursive process, and the query obtains the result of the previous forward recursion, which is 4 (the result of the third recursive process). Then, the value of the first parameter, the value of the second parameter and the random number in the current reverse recursive calculation formula are compared with the result of the previous recursion respectively. If the calculation formula of the previous reverse recursion has the same value as the result of the previous recursion, the calculation formula of the previous recursion is merged into the calculation formula of the current reverse recursion to generate the target expansion formula.

[0044] Understandably, when calculating Ti in reverse recursion: If Q i ==T i-1 , then T i-1 Assign the formula to Q i . If K i ==T i-1 , then T i-1 Assign the formula to K i .

[0045] If P i ==T i-1 , then T i-1 Assign the formula to P i .

[0046] Continuing with the above example, the current reverse recursive calculation formula is: 1=13-3×4, the result of the third forward recursive process is 4, and the calculation formula of the third forward recursive process is: 4=17-1×13; the calculation formula of the previous recursion is integrated into the current reverse recursive calculation formula: 1=13-3×(17-1×13).

[0047] Furthermore, the target expansion is used as the new calculation formula of the current reverse recursion, and the step of determining the result of the previous recursion corresponding to the current reverse recursion is returned to the result of each recursion in the forward recursion calculation process, until the reverse recursion reaches the calculation formula of the first recursion in the forward recursion process. Using the above example, the complete calculation process of the reverse recursion is as follows: Step 4: 1=13-3×4.

[0048] Step 3: 1=13-3×(17-1×13).

[0049] Step 2: 1=(30-1×17)-3×(17-1×(30-1×17)).

[0050] Step 1: 1=(30-1×(77-2×30))-3×((77-2×30)-1×(30-1×(77-2×30))).

[0051] After the reverse recursive calculation is completed, the final target expansion is obtained. Further, the final target expansion is simplified. Optionally, in this embodiment, the target simplified formula is set to 1 = LCF * UM * K, where U is the desired modular inverse correction value and K is a random parameter. That is, 1 = (30-1 × (77-2 × 30))-3 × ((77-2 × 30)-1 × (30-1 × (77-2 × 30))) is simplified to 1 = LCF × UM × K to obtain the following simplified formula: 1 = 30 × 18-7 × 77, and the modular inverse correction value U can be determined to be 18.

[0052] The embodiment of the present invention adopts the above scheme, combines the least common multiple and the target modulus, calculates the modular inverse correction process of the least common multiple in the target modulus, and obtains the modular inverse correction value. In the recursive process, it has the functions of qualitative inspection, reverse deduction and self-verification, and has higher data accuracy.

[0053] In one embodiment of the present invention, first original data and second original data are encrypted based on a target modulus to obtain a first ciphertext corresponding to the first original data and a second ciphertext corresponding to the second original data, including: Determine a first random factor and a second random factor; determine an encryption base based on a target modulus; encrypt the first original data based on the target modulus, the encryption base and the first random factor to obtain a first ciphertext; encrypt the second original data based on the target modulus, the encryption base and the second random factor to obtain a second ciphertext.

[0054] Specifically, determine the first random factor and the second random factor, for example, the first random factor R_A is 5, and the second random factor R_B is 6; in addition, based on the target modulus, calculate the encryption base, for example, the encryption base G = target modulus M + 1 = 77 + 1. Further, based on the target modulus, the encryption base and the first random factor, encrypt the first original data to obtain the first ciphertext; and based on the target modulus, the encryption base and the second random factor, encrypt the second original data to obtain the second ciphertext. The encryption formula is as follows: the first ciphertext Ciphertext_A=(G^Original_A×R_A^M) modM^2, for example, the first original data Original_A is 4, and the second original data Original_B is 3; Ciphertext_A=(78 4 ×5 77 )mod 77 2 =2621. The second ciphertext Ciphertext_B=(G^Original_B×R_B^M) mod M^2, for example, Ciphertext_B=(78 3 ×6 77 )mod 77 2 =5354.

[0055] The embodiment of the present invention adopts the above scheme, combines the target modulus and the random factor, and uses a mathematical formula to encrypt the original data, thereby improving the security of the data and the operating efficiency of the system.

[0056] In one embodiment of the present invention, the ciphertext operation result is decrypted based on the modulo inverse correction value to obtain the target plaintext, including: Perform a power modulo operation on the ciphertext operation result to obtain a modulo operation result; multiply the modulo operation result and the modulo inverse correction value to obtain a multiplication operation result; based on the target modulus, perform a modulo operation on the multiplication operation result to obtain the target plaintext.

[0057] Specifically, based on the ciphertext operation result, the target modulus and the least common multiple, the first operation result is determined, and the calculation formula is as follows: First operation result Powermod = (c_add_result^LCF) mod M^2, using the above example, assuming c_add_result = 4820, Powermod = 4820 30 mod77 2 =4313. Further, based on the first operation result and the target modulus, a modulus operation result is determined. The modulus operation result Powermod'=(Powermod-1) / M, for example, Powermod'=(4313-1) / 77=56.

[0058] Furthermore, the result of the modulus operation and the modulus inverse correction value are multiplied to obtain the multiplication result, and then based on the target modulus, the multiplication result is modulo-operated to obtain the target plaintext. The calculation formula of the target plaintext is as follows: (Powermod'×U)mod M, where U represents the modulus inverse correction value. For example, using the above example, the modulus inverse correction value U is 18, and the target plaintext = (56×18)mod77=7. The original text after decryption can be tested and verified. The first original data Original_A is 4, and the second original data Original_B is 3. The sum of the two is equal to 7, which proves that the encryption and decryption results used in this embodiment are correct.

[0059] In the embodiment of the present invention, the sensitive data of the user is not calculated after decryption during the calculation process, but is calculated in an encrypted state, thereby improving the security of the data. The ciphertext calculation result is then decrypted according to a mathematical formula, thereby improving the operating efficiency of the system.

[0060] It should be understood that the order of execution of the steps in the above embodiment does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention.

[0061] In one embodiment, an encryption and decryption device is provided, and the encryption and decryption device corresponds one-to-one to the encryption and decryption method in the above embodiment. Figure 2 As shown, Figure 2 : is a schematic diagram of a structure of an encryption and decryption device in an embodiment of the present invention, the encryption and decryption device comprises: A first determining module 21 is used to determine a target modulus and a least common multiple based on a first prime number and a second prime number; A second determination module 22, for determining a modulus inverse correction value based on the least common multiple and the target modulus; An acquisition module 23, used for acquiring data to be encrypted, wherein the data to be encrypted includes first original data and second original data; An encryption module 24 is used to encrypt the first original data and the second original data based on the target modulus to obtain a first ciphertext corresponding to the first original data and a second ciphertext corresponding to the second original data; A calculation module 25, configured to determine a ciphertext calculation result based on the first ciphertext and the second ciphertext; The decryption module 26 is used to decrypt the ciphertext operation result based on the modulo inverse correction value to obtain the target plaintext.

[0062] The second determining module 22 is further used for: In the forward recursion process: In the first recursive process, the target modulus is assigned to the first parameter in the preset formula, the lowest common multiple is assigned to the second parameter in the preset formula, and the result of the first recursive calculation is determined in combination with the random number of the first recursion; In each subsequent recursive process, the value of the second parameter in the previous recursive process is assigned to the first parameter, the result of the previous recursive calculation is assigned to the second parameter, and the result of the current recursive process is determined in combination with the random number in the current recursive process, until the result of the current recursive process is 1; During the reverse recursion: Determine a calculation formula for each recursion in the forward recursive process, wherein the calculation formula includes a value of a first parameter, a value of a second parameter, and a random number in the recursive process; Start reverse recursion from the last recursive calculation formula in the forward recursive process, so as to use the last recursive calculation formula as the current reverse recursive calculation formula; In the result of each recursion during the forward recursive calculation process, determine the result of the previous recursion corresponding to the current reverse recursion; Compare the value of the first parameter, the value of the second parameter and the random number in the current reverse recursive calculation formula with the result of the previous recursion; If there is a value that is the same as the result of the previous recursion, then generate the target expansion according to the calculation formula of the current reverse recursion and the calculation formula of the previous recursion, and use the target expansion as the new calculation formula of the current reverse recursion, and return to the step of determining the result of the previous recursion corresponding to the current reverse recursion in the result of each recursion in the forward recursive calculation process, until the reverse recursion reaches the calculation formula of the first recursion in the forward recursive process; The final target expansion is simplified to determine the modular inverse correction value based on the simplified formula.

[0063] The encryption module 24 is also used for: Determine a first random factor and a second random factor; Based on the target modulus, determine the encryption base; Encrypting the first original data based on the target modulus, the encryption base, and the first random factor to obtain a first ciphertext; The second original data is encrypted based on the target modulus, the encryption base, and the second random factor to obtain a second ciphertext.

[0064] The computing module 25 is also used for: Multiply the first ciphertext and the second ciphertext to obtain the target ciphertext; Based on the target modulus and the target ciphertext operation, the ciphertext operation result is determined.

[0065] The decryption module 26 is also used to: Perform a power modular operation on the ciphertext operation result to obtain a modular operation result; Multiply the modular operation result and the modular inverse correction value to obtain a multiplication operation result; Based on the target modulus, a modulus operation is performed on the multiplication result to obtain the target plaintext.

[0066] The decryption module 26 is also used to: Determine a first operation result based on the ciphertext operation result, the target modulus, and the least common multiple; Based on the first operation result and the target modulus, a modulus operation result is determined.

[0067] The first determining module 21 is further used for: The product of the first prime number and the second prime number is taken as the target modulus.

[0068] For the specific definition of the encryption and decryption device, please refer to the definition of the encryption and decryption method above, which will not be repeated here. Each module in the above encryption and decryption device can be implemented in whole or in part by software, hardware and a combination thereof. Each of the above modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.

[0069] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 3 As shown, Figure 3 : is a schematic diagram of a computer device in one embodiment of the present invention. The computer device includes a processor, a memory, a network interface and a database connected by a device bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a readable storage medium and an internal memory. The readable storage medium stores an operating device, a computer-readable instruction and a database. The internal memory provides an environment for the operation of the operating device and the computer-readable instructions in the readable storage medium. The database of the computer device is used to store data involved in the encryption and decryption method. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer-readable instruction is executed by the processor, an encryption and decryption method is implemented. The readable storage medium provided in this embodiment includes a non-volatile readable storage medium and a volatile readable storage medium.

[0070] In one embodiment, a computer device is provided. The computer device may be a terminal device, and its internal structure diagram may be as follows: Figure 3As shown. The computer device includes a processor, a memory, and a network interface connected through a device bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a readable storage medium. The readable storage medium stores computer-readable instructions. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer-readable instructions are executed by the processor, an encryption and decryption method is implemented. The readable storage medium provided in this embodiment includes a non-volatile readable storage medium and a volatile readable storage medium.

[0071] In one embodiment, a computer device is provided, including a memory, a processor, and computer-readable instructions stored in the memory and executable on the processor, and the processor implements the steps of the above encryption and decryption method when executing the computer-readable instructions.

[0072] In one embodiment, a readable storage medium is provided, and the readable storage medium stores computer-readable instructions, and the computer-readable instructions are executed by the processor to implement the above-mentioned encryption and decryption method steps. A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through computer-readable instructions, and the computer-readable instructions can be stored in a non-volatile readable storage medium or a volatile readable storage medium. When the computer-readable instructions are executed, they may include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0073] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.

[0074] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the protection scope of the present invention.

Claims

1. An encryption and decryption method, characterized in that: include: Based on the first prime number and the second prime number, determining a target modulus and a least common multiple; Determining a modulus inverse correction value based on the least common multiple and the target modulus; Acquire data to be encrypted, wherein the data to be encrypted includes first original data and second original data; Based on the target modulus, encrypt the first original data and the second original data respectively to obtain a first ciphertext corresponding to the first original data and a second ciphertext corresponding to the second original data; Determining a ciphertext operation result based on the first ciphertext and the second ciphertext; Based on the module inverse correction value, the ciphertext operation result is decrypted to obtain the target plaintext.

2. The encryption and decryption method according to claim 1, characterized in that: The step of determining a modulus inverse correction value based on the least common multiple and the target modulus includes: In the forward recursion process: During the first recursion, the target modulus is assigned to the first parameter in the preset formula, the least common multiple is assigned to the second parameter in the preset formula, and the result of the first recursive calculation is determined in combination with the random number of the first recursion; In each subsequent recursive process, the value of the second parameter in the previous recursive process is assigned to the first parameter, the result of the previous recursive calculation is assigned to the second parameter, and the result of the current recursive process is determined in combination with the random number in the current recursive process, until the result of the current recursive process is 1; During the reverse recursion: Determine a calculation formula for each recursion in the forward recursive process, wherein the calculation formula includes a value of a first parameter, a value of a second parameter and a random number in the recursive process; Start reverse recursion from the last recursive calculation formula in the forward recursive process, so as to use the last recursive calculation formula as the current reverse recursive calculation formula; In the result of each recursion during the forward recursive calculation process, determine the result of the previous recursion corresponding to the current reverse recursion; Compare the value of the first parameter, the value of the second parameter and the random number in the current reverse recursive calculation formula with the result of the previous recursion; If there is a value that is the same as the result of the previous recursion, a target expansion is generated according to the calculation formula of the current reverse recursion and the calculation formula of the previous recursion, and the target expansion is used as the new calculation formula of the current reverse recursion, and the step of determining the result of the previous recursion corresponding to the current reverse recursion is returned to the result of each recursion in the forward recursive calculation process, until the reverse recursion reaches the calculation formula of the first recursion in the forward recursive process; The final target expansion is simplified to determine the modular inverse correction value according to the simplified formula.

3. The encryption and decryption method according to claim 1, characterized in that: The encrypting the first original data and the second original data based on the target modulus to obtain a first ciphertext corresponding to the first original data and a second ciphertext corresponding to the second original data includes: Determine a first random factor and a second random factor; Based on the target modulus, determining an encryption base; Encrypting the first original data based on the target modulus, the encryption base, and the first random factor to obtain the first ciphertext; The second original data is encrypted based on the target modulus, the encryption base, and the second random factor to obtain the second ciphertext.

4. The encryption and decryption method according to claim 1, characterized in that: The determining a ciphertext operation result based on the first ciphertext and the second ciphertext includes: Multiplying the first ciphertext and the second ciphertext to obtain a target ciphertext; Based on the target modulus and the target ciphertext operation, the ciphertext operation result is determined.

5. The encryption and decryption method according to claim 1, characterized in that: The decrypting the ciphertext operation result based on the module inverse correction value to obtain the target plaintext includes: Performing a power modular operation on the ciphertext operation result to obtain a modular operation result; Multiplying the modular operation result and the modular inverse correction value to obtain a multiplication operation result; Based on the target modulus, a modulus operation is performed on the multiplication result to obtain the target plaintext.

6. The encryption and decryption method according to claim 5, characterized in that: The performing a power modular operation on the ciphertext operation result to obtain a modular operation result includes: Determine a first operation result based on the ciphertext operation result, the target modulus, and the least common multiple; The modulo operation result is determined based on the first operation result and the target modulus.

7. The encryption and decryption method according to claim 1, characterized in that: The method of determining a target modulus based on the first prime number and the second prime number comprises: The product of the first prime number and the second prime number is used as the target modulus.

8. An encryption and decryption device, characterized in that: include: A first determining module is used to determine a target modulus and a least common multiple based on a first prime number and a second prime number; A second determination module is used to determine a modulus inverse correction value based on the least common multiple and the target modulus; An acquisition module, used for acquiring data to be encrypted, wherein the data to be encrypted includes first original data and second original data; an encryption module, configured to encrypt the first original data and the second original data respectively based on the target modulus to obtain a first ciphertext corresponding to the first original data and a second ciphertext corresponding to the second original data; A calculation module, used for determining a ciphertext calculation result based on the first ciphertext and the second ciphertext; The decryption module is used to decrypt the ciphertext operation result based on the module inverse correction value to obtain the target plaintext.

9. A computer device comprising a memory, a processor, and computer-readable instructions stored in the memory and executed on the processor, characterized in that: When the processor executes the computer-readable instructions, the encryption and decryption method according to any one of claims 1 to 7 is implemented.

10. A readable storage medium having computer readable instructions stored thereon, characterized in that: When the computer-readable instructions are executed by a processor, the encryption and decryption method according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Data processing method, device and system

    CN110493201A

  • Power system laboratory data sharing method and device based on privacy computing and medium

    CN118862162A

  • Generation of cryptographic keys

    US20160072627A1

  • Format-Preserving Cipher

    US20160218860A1