Encryption method based on RSA algorithm

By introducing hybrid encryption and multiple obfuscation processing into the RSA algorithm, the session key is generated and encrypted, the security problem of the RSA algorithm in the face of ciphertext attacks and incorrect key management is solved, and the encryption security is achieved. .

CN119449308AActive Publication Date: 2025-02-14青岛青软晶尊微电子科技有限公司

Patent Information

Application Number
CN202411792973.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-08
Publication Date
2025-02-14
Estimated Expiration
2044-12-08

AI Technical Summary

Technical Problem

In the prior art, RSA algorithms are difficult to effectively resist security threats when facing ciphertext attacks and key management, resulting in low security of encrypted data.

Method used

By combining RSA algorithm with hybrid encryption and multiple obfuscation processing, the session key is generated and encrypted. Specific steps include data collection, session key generation, session key encryption, data encryption, data obfuscation, etc.

Benefits of technology

Improves the security of RSA algorithm encryption and enhances the protection of encrypted data, making it difficult for attackers to crack or restore encrypted data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119449308A_ABST
    Figure CN119449308A_ABST
Patent Text Reader

Abstract

The invention discloses an encryption method based on an RSA algorithm, and relates to the technical field of data encryption, and the method comprises the steps: collecting to-be-encrypted data; generating a session key of the to-be-encrypted data by adopting a symmetric block encryption algorithm RC5; encrypting the generated session key by adopting an RSA public key; encrypting the to-be-encrypted data by adopting a symmetric block encryption algorithm RC5 and the encrypted session key to generate encrypted data, dividing the to-be-encrypted data into N1 groups, and encrypting the grouped to-be-encrypted data by calling the RC5 algorithm in parallel through multiple threads; and performing confusion processing of sequentially and circularly exchanging adjacent data positions on the encrypted data to obtain the encrypted data. Aiming at the low encryption security based on an RSA algorithm in the prior art, the method comprises the following steps: collecting to-be-encrypted data, and generating a session key based on data content by using an RC5 algorithm; encrypting the session key by adopting an RSA algorithm; an RC5 algorithm is called in parallel for encryption; and block position confusion processing is carried out on the encrypted data, so that the encryption security of the RSA algorithm is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of data encryption, and in particular to an encryption method based on RSA algorithm. Background Art

[0002] With the rapid development of information technology and the increasing popularity of network applications, data security issues have become the focus of attention in various fields. In industries involving important privacy data such as government, finance, and medical care, higher and higher requirements are placed on the confidentiality and integrity of data. However, the existing data encryption technology still has some shortcomings, which makes the encrypted data easy to crack and the security of data difficult to be effectively guaranteed. Among many encryption algorithms, the RSA algorithm is widely used in fields such as data encryption and digital signatures because of its difficulty in solving the problem of large number factorization. The RSA algorithm uses a pair of public and private keys to encrypt and decrypt data. The public key is used for encryption and the private key is used for decryption. If an attacker does not know the private key, even if he obtains the public key and ciphertext, it is difficult to crack the plaintext within a computationally feasible time, thereby ensuring the confidentiality of the data.

[0003] However, with the continuous improvement of computer hardware performance and the increasing maturity of cryptanalysis technology, the traditional RSA algorithm also faces some security challenges. Attackers can use known plaintext attacks, chosen ciphertext attacks and other methods to infer the private key or restore the plaintext through a large amount of data analysis and calculation attempts. In addition, the security of the RSA algorithm also depends on the choice of key length. Insufficient key length or improper key management may lead to the leakage of encrypted data.

[0004] In the related art, for example, Chinese patent document CN116506230B provides a data collection method, system, electronic device and computer storage medium based on RSA asymmetric encryption, and the collection method includes: obtaining data from the original data source, analyzing the data from the original data source to find out the problem data in the original data source; establishing strategies and rules for data cleaning and processing models, importing the problem data in the original data source into the data cleaning and processing model to obtain clean target data; format conversion of the target data, converting the key value format of the target data into a set data format for output; and forwarding the target data to the cloud server after RSA data encryption. This application can reduce the workload of cleaning and processing, and improve the speed and efficiency of cleaning and processing; the target data is forwarded to the cloud server after RSA encryption, which can reduce the bandwidth between edge computing and the cloud server; at the same time, the data is output after RSA encryption, and the data transmission process is saved from being leaked and tampered with. However, asymmetric encryption relying solely on the RSA single algorithm cannot effectively resist security threats such as ciphertext attacks, and the security is not high. Summary of the invention

[0005] In view of the problem that encrypted data in the prior art is easily cracked, the present application provides an encryption method based on the RSA algorithm, which improves the security of RSA algorithm encryption through hybrid encryption and multiple obfuscation processing.

[0006] The purpose of this application is achieved through the following technical solutions.

[0007] The present application provides an encryption method based on the RSA algorithm, including: in a data collection stage, collecting structured data to be encrypted, such as database records, XML files, etc., and converting them into a unified structured format, such as JSON or binary format. Collecting unstructured data to be encrypted, such as text, images, audio and video, etc., and converting them into a unified unstructured format, such as Base64 encoding. The converted structured data and unstructured data are spliced ​​according to predefined rules to form complete data to be encrypted.

[0008] During the session key generation phase, a secure hash algorithm (such as SHA-256) is used to perform a hash operation on the encrypted data to obtain a hash value of fixed length. Using the hash value as a seed, a pseudo-random number generator (such as PRNG) is used to generate a random number sequence. According to the preset key length (such as 128 bits, 192 bits, or 256 bits) and the number of encryption rounds (such as 12 rounds, 16 rounds, or 20 rounds), the random number sequence is divided into the required subkeys. Using the RC5 symmetric block encryption algorithm, the subkey is used as the round key to encrypt the fixed initial vector (such as a string of all 0 bits) to generate the session key.

[0009] During the session key encryption phase, select the preset RSA public key, including the public key modulus and public key exponent. Convert the session key into a large integer and encrypt it using the RSA encryption algorithm. The encrypted session key is used as ciphertext and transmitted or stored together with the data to be encrypted.

[0010] In the data encryption phase, the data to be encrypted is divided into fixed-size data packets, such as 64 bits or 128 bits. The RC5 symmetric block encryption algorithm is used to encrypt each data packet with the session key as the round key. The Cipher Block Chaining (CBC) mode is used to perform an XOR operation on the ciphertext of the previous data packet and the current data packet, and then perform RC5 encryption. All encrypted data packets are spliced ​​together to form preliminary encrypted data.

[0011] In the data obfuscation stage, the preliminary encrypted data is divided into several data blocks of fixed size. Each data block is subjected to M rounds of obfuscation processing, where M is a preset positive integer. Each round of obfuscation processing includes: dividing the data block into several sub-blocks. Performing byte-level replacement operations on each sub-block, such as exchanging the i-th byte with the (i+1) mod n-th byte, where n is the number of bytes in the sub-block. Performing byte-level replacement operations on the replaced sub-blocks, such as swapping the upper 4 bits and the lower 4 bits of each byte. Reassemble the processed sub-blocks into a complete data block. All obfuscated data blocks are spliced ​​together to obtain the final encrypted data.

[0012] Further, generating a session key includes: performing SHA256 hash calculation on the structured data to be encrypted, serializing the structured data to be encrypted according to a predefined data format and field order to obtain a byte sequence. Using the SHA256 cryptographic hash algorithm to hash the byte sequence to obtain a 256-bit (32-byte) structured data hash value. Performing MD5 hash calculation on the unstructured data to be encrypted, encoding the unstructured data to be encrypted according to a predefined encoding format (such as Base64) to obtain a byte sequence. Using the MD5 cryptographic hash algorithm to hash the byte sequence to obtain a 128-bit (16-byte) unstructured data hash value. Generating an initial vector, splicing the obtained structured data hash value and the obtained unstructured data hash value in a preset order, first the structured hash value and then the unstructured hash value, to obtain a 384-bit (48-byte) spliced ​​hash value. Using the spliced ​​hash value as the initial vector of the RC5 encryption algorithm. Set the RC5 algorithm parameters, set the key length of the RC5 algorithm to L bits, such as 128 bits, 192 bits, or 256 bits. Set the number of encryption rounds of the RC5 algorithm to T, such as 12 rounds, 16 rounds, or 20 rounds. Perform SHA3-384 hash calculation on the initial vector, and use the SHA3-384 cryptographic hash algorithm to hash the obtained initial vector to obtain a 384-bit (48-byte) SHA3 hash value.

[0013] Preferably, the PBKDF2 algorithm is used to further process the SHA3 hash value to obtain a session key of the required length. The SHA3 hash value is used as the password; the randomly generated salt value has a length of not less than 128 bits; the preset number of iterations is not less than 1000 times; and the length of the output key is equal to the key length L.

[0014] Further, generating a session key also includes: generating a sub-vector, dividing the obtained SHA3 hash value into S sub-vectors of length L bits, denoted as V1 to VS, where S=384 / L, preferably, using the RC5 algorithm with a preset initial key of L bits and a set number of encryption rounds T to generate T sub-keys of length L bits, denoted as K1 to KT; preferably, performing an XOR operation on the initial key and the SHA3 hash value to obtain the XOR result as a seed key of the RC5 key expansion algorithm; using the RC5 key expansion algorithm, taking the seed key as input, to generate 2T sub-keys; the RC5 key expansion algorithm ensures the randomness and unpredictability of the sub-keys; dividing the generated 2T sub-keys into two groups, the front T sub-keys K1 to KT are used for encryption of odd sub-vectors, and the rear T sub-keys K(T+1) to K2T are used for decryption of even sub-vectors;

[0015] Generate subkeys, select a preset L-bit (such as 128-bit) initial key as the key input of the RC5 algorithm. Use the RC5 key expansion algorithm, take the initial key and the set encryption round number T as input, and generate T subkeys with a length of L bits, denoted as K1 to KT. Preferably, use Ki to perform RC5 encryption E(Vi) on the odd-numbered plaintext subvector Vi, and the encryption result E(Vi) is used as the left half of Ci; use K(i+T) to perform RC5 decryption D(Vi) on the even-numbered plaintext subvector Vi, and the decryption result D(Vi) is used as the right half of Ci; by encrypting the odd subvectors, decrypting the even subvectors, and then splicing Ci, the asymmetry of alternating encryption and decryption is introduced, which increases the difficulty of cracking the session key; encrypt the subvector, for the i-th subvector Vi among the obtained S subvectors, use the generated i-th subkey Ki as the key, use the RC5 encryption algorithm to encrypt Vi, and obtain an encrypted subvector Ci with a length of L bits, where i is an integer from 1 to S.

[0016] Furthermore, in the CBC mode encryption phase of session key generation, an initial vector IV is introduced, and a predefined L-bit initial vector IV is set for initialization of the CBC mode. CBC mode encryption is performed, and the first sub-vector V1 obtained is subjected to a bitwise XOR operation with the initial vector IV, and the XOR result is obtained as the initial value of the feedback encryption sub-vector C'0. For each integer i from 1 to S, the following steps are performed: the obtained i-th encryption sub-vector Ci is subjected to a bitwise XOR operation with the feedback encryption sub-vector C'i-1 obtained in the previous iteration, and an XOR result Ri with a length of L bits is obtained. The generated i-th sub-key Ki is used as the key, and an RC5 encryption operation is performed on Ri to obtain an encryption result Ei with a length of L bits. The encryption result Ei is subjected to a bitwise XOR operation with the obtained i-th sub-vector Vi to obtain a feedback encryption sub-vector C'i with a length of L bits. The above iterative process is repeated until S feedback encryption sub-vectors C'1 to C'S are obtained. Generate a final session key, and concatenate the obtained S feedback encryption sub-vectors C'1 to C'S in order to obtain a final session key with a length of 384 bits (48 bytes).

[0017] Preferably, the bits of the SHA3 hash value are rearranged according to a preset permutation table, and the input and output lengths of the permutation table are the same as the length of the SHA3 hash value; the permutation table is generated based on the key used in the session key derivation process, and the permutation table is obtained by expanding and transforming the key, thereby ensuring the unpredictability of the permutation operation; the bit sequence obtained after the permutation operation is grouped from left to right, each group of L bits, and a total of S sub-vectors V1 to VS with a length of L are obtained; the RC5 algorithm is used with a preset initial key of L bits and a set number of encryption rounds T to generate T sub-keys with a length of L bits, which are recorded as K1 to KT; the generation of the sub-key includes: performing a bitwise XOR operation on the initial key and the SHA3 hash value, and obtaining the XOR result as the seed key of the RC5 key expansion algorithm; the RC5 key expansion algorithm is used with the seed key The subkey is input, and T subkeys K1 to KT of length L are generated through operations such as cyclic shift and XOR. The RC5 key expansion algorithm ensures the randomness and unpredictability of the subkey. (3) The S subvectors Vi and T subkeys Ki are interleaved to obtain S interleaved subvectors Wi and T interleaved subkeys Ji: the subvectors V1, V3, ... at odd positions are sequentially XORed with the subkeys K1, K3, ... at odd positions to obtain the interleaved subvectors W1, W3, ... and interleaved subkeys J1, J3, ... at odd positions; the subvectors V2, V4, ... at even positions are sequentially XORed with the subkeys K2, K4, ... at even positions to obtain the interleaved subvectors W2, W4, ... and interleaved subkeys J2, J4, ... at even positions.; The interleaving process introduces the correlation between the sub-vectors and the sub-keys through the XOR operation, disrupting the statistical characteristics of the original data and increasing the difficulty of cracking; (4) Using the CBC mode, taking S interleaved sub-vectors Wi as input, T interleaved sub-keys Ji as keys, introducing the initial vector IV of length L, and performing iterative calculation to obtain S feedback encryption sub-vectors C'i of length L; the iterative calculation includes: performing bitwise XOR on the first interleaved sub-vector W1 and the initial vector IV to obtain the XOR result X1 as the input of the first round of CBC encryption; performing RC5 encryption on the input Xi of the i-th round using the i-th interleaved sub-key Ji to obtain the encryption result Ei of length L; and combining the encryption result Ei with the i+1-th interleaved sub-vector W( i+1) is bitwise XORed to obtain the XOR result X(i+1) of length L as the input of the next round of CBC encryption; the above process is repeated until the last round, and the encryption result ES is XORed with WS to obtain C'S of length L; by replacing the original sub-vector with the interleaved sub-vector and inputting it into the CBC iteration, a feedback mechanism is introduced to increase the diffusion and obfuscation of the ciphertext, thereby further enhancing the strength of the feedback encryption; (5) S feedback encryption sub-vectors C'1 to C'S of length L are permuted, and then sequentially concatenated to obtain a session key of length S*L; the permutation operation uses a permutation table different from that in step (1), further increasing the difficulty of cracking; the permutation table is also generated based on the key, thereby ensuring the unpredictability of the permutation operation. In the process of converting SHA3 hash value to session key, multiple rounds of randomization measures are introduced, including: permutation operation based on key to disrupt the bits of hash value and hide the statistical characteristics of original data; dynamically generate subkeys related to hash value for interleaving and RC5 encryption to provide randomness of key; interleave subvectors and subkeys to introduce correlation and increase the difficulty of cracking; iteratively encrypt the interleaved result in CBC mode, introduce initial vector to increase the diffusion and confusion of ciphertext; finally, permute the feedback encryption result again to further disrupt the data order and bit distribution. Multiple randomization steps are combined in series to finally obtain a session key with high randomness, unpredictability and anti-attack. This method makes full use of the bit-level confusion of hash value, innovatively combines permutation, interleaving, feedback encryption and other technical measures to form a comprehensive and effective session key generation scheme, which can significantly improve the security strength of session key. .

[0018] Furthermore, generating encrypted data includes: using a symmetric block encryption algorithm RC5 to encrypt the data to be encrypted. The RC5 algorithm is a block cipher algorithm that divides plaintext data into data blocks of a fixed size and encrypts each data block using a key. In the present application, the generated session key is used as the encryption key of the RC5 algorithm to encrypt the data to be encrypted to obtain the encrypted data. Next, the encrypted data is divided into N blocks, where N is an integer greater than 1. A suitable N value can be selected according to the size of the data and the requirements for block division. For example, the data can be divided into blocks of fixed size, such as 128 bytes, 256 bytes, etc.; different block division methods can also be used according to the characteristics of the data, such as file format, data type, etc.

[0019] The encrypted data after block division is stored in a cache area, which can be a memory, a disk or other storage medium. Each data block occupies a continuous storage space in the cache area, and the data blocks are numbered from 1 to N. The Mersenne Twister algorithm is used to generate a pseudo-random exchange sequence containing N exchange indexes. The Mersenne Twister algorithm is an efficient pseudo-random number generation algorithm, which can generate a pseudo-random number sequence with uniform distribution, long cycle and good statistical characteristics. According to the generated pseudo-random exchange sequence, the data blocks in the cache area are exchanged to change the order of the data blocks to achieve data confusion and disturbance. The first exchange index is obtained from the pseudo-random exchange sequence, and two data blocks at corresponding positions are read from the cache area according to the index, and are marked as data block blockA and data block blockB respectively. The storage positions of data block blockA and data block blockB in the cache area are exchanged. Specifically, data block blockA is copied to a temporary buffer, and then data block blockB is copied to the original position of data block blockA, and finally data block blockA in the temporary buffer is copied to the original position of data block blockB. In this way, the exchange operation of the two data blocks is completed. Continue to obtain the next exchange index from the pseudo-random exchange sequence and repeat the data block exchange steps until all N data blocks are exchanged. After the data block exchange is completed, read N data blocks from the buffer in the order after the exchange and splice them into complete encrypted data. This encrypted data is the final output result and can be stored, transmitted or otherwise processed.

[0020] Furthermore, the Mersenne Twister algorithm is used to generate a pseudo-random exchange sequence, including: the internal state of the Mersenne Twister algorithm includes two parts: a seed value and a state vector. The seed value is used to determine the starting point of the pseudo-random number sequence, and the state vector is used to save the intermediate result of generating the pseudo-random number. In order to enhance the security of the pseudo-random exchange sequence, the present application adopts a key derivation function based on a hash function, and uses the generated session key as input to derive a seed value. Specifically, the session key is used as the input of the hash function, the hash value is calculated, and a part of the hash value is used as the seed value. In this way, it can be ensured that there is a cryptographic association between the seed value and the session key, and the randomness and unpredictability of the seed value are increased.

[0021] Preferably, HKDF (HMAC-based Key Derivation Function) is used to receive a session key, a random salt value, a timestamp and a counter as input data, wherein the session key is a shared key obtained by negotiation between the communicating parties, the random salt value is a randomly generated fixed-length value, the timestamp represents the current time, and the counter is an increasing integer value; the session key, the random salt value, the timestamp and the counter are concatenated into an input string as the input of the improved HKDF; a double hash chain operation is performed on the input string, two different hash functions and initialization vectors are used to generate the outputs of two hash chains respectively, and the double hash chain operation enhances the security of the key derivation process; the outputs of the two hash chains are combined by an XOR operation to generate a derived key, and the XOR operation mixes the outputs of the two hash chains to improve the randomness of the derived key; the derived key is divided into multiple subkeys, the length of each subkey is adjusted according to the demand, and then the subkeys are mixed by a key mixing algorithm to generate a final seed key, and the key division and key mixing increase the unpredictability of the derived key; it is determined whether the length of the seed key is consistent with the Mersenne The Twister algorithm requires the same seed value length. If they are different, the seed key is truncated or extended to obtain a processed seed key with the same length as the seed value; the processed seed key is used as the seed value and set as the initial seed value of the Mersenne Twister algorithm to initialize the internal state of the Mersenne Twister algorithm. In the double hash chain operation, one hash chain uses the SHA-256 hash function and the other hash chain uses the SHA-512 hash function. The two hash functions have different security strengths and output lengths. The key mixing algorithm is selected from the XOR operation, HMAC operation or other secure key mixing algorithm to mix the subkeys and generate the final seed key.

[0022] The derived seed value is set as the initial seed value of the Mersenne Twister algorithm to initialize the internal state of the algorithm. At the same time, the state vector is initialized to a preset constant, such as an all-0 or all-1 vector, to prepare for subsequent state updates. According to the internal state of the Mersenne Twister algorithm, a linear feedback shift register (LFSR) and bit operations are used to generate a new state vector. First, the LFSR is used to shift the current state vector. The LFSR forms a new state vector by cyclically shifting the bits of the state vector according to a predetermined shift method, shifting the highest bit out and placing it in the lowest bit. The number of bits shifted can be set according to the parameters of the algorithm, such as 32 bits or 64 bits. Then, the shifted state vector is XORed with the preset feedback polynomial to update the content of the state vector. The feedback polynomial is a fixed binary polynomial whose coefficients determine the feedback position of the LFSR. By XORing specific bits of the state vector with the feedback polynomial, new randomness can be introduced to prevent the state vector from entering a short cycle loop.

[0023] Preferably, a quaternary twist function is used to generate a new state vector, and the current internal state vector of the Mersenne Twister algorithm is received as input, where the internal state vector consists of multiple binary bits; a linear feedback shift register is applied to the internal state vector, a shift operation is performed on the current state vector, and an XOR operation is performed with a preset feedback polynomial to generate an updated state vector, where the preset feedback polynomial is a fixed binary polynomial; a bit operation is applied to the updated state vector, and the bits of the state vector are mixed to generate a mixed state vector, where the bit operation includes an XOR operation, an AND operation, an OR operation or a combination thereof; the mixed state vector is divided into multiple quaternaries, each quaternary group contains four binary bits as input of the quaternary twist function; a quaternary twist function is applied to each quaternary group, and a binary bit is calculated as output according to the value of the quaternary group, where the quaternary twist function is a Boolean function, which maps four binary bits of input to one binary bit of output; the binary bits of all quaternaries calculated by the quaternary twist function are concatenated to form a new state vector as a new state for generating a pseudo-random number sequence. The quaternion warp function satisfies the following conditions: for any two different quaternion inputs, the output binary bits are different, that is, it has perfect nonlinear characteristics; the algebraic degree of the quaternion warp function is 3, that is, the degree of the highest order term in the function expression is 3; the nonlinear order of the quaternion warp function is 4, that is, the nonlinearity of the function reaches the maximum value. Before dividing the mixed state vector into quaternions, the mixed state vector is permuted to rearrange the bits of the state vector, disrupt the original positional relationship, and increase the diffusion effect of the state transfer. After applying the quaternion warp function to the quaternion to calculate the binary bits, the calculated binary bits are permuted to rearrange the output binary bits, further increasing the chaos and diffusion of the state transfer.

[0024] Perform bitwise operations on the updated state vector to further mix the bits of the state vector. Bitwise operations may include bitwise AND, bitwise OR, bitwise XOR, etc., which increase the complexity and unpredictability of the state vector by combining and transforming the bits of the state vector. After LFSR shifting, feedback XOR, and bitwise operations, a new state vector is obtained as the current internal state of the Mersenne Twister algorithm. Perform modulo N operations on the generated new state vector to obtain a random integer ranging from 1 to N as a candidate exchange index in the pseudo-random exchange sequence. Modulo N operations can be obtained by taking the low-order bits of the state vector and taking modulo N. The candidate exchange index represents the position of the data block in the cache area and is used for subsequent data block exchange operations. Since the exchange index needs to be between 1 and N and not repeated, the candidate exchange index needs to be further processed and judged. A hash table is used to determine whether the generated candidate exchange index is repeated with the previously generated exchange index. The candidate exchange index is used as a key to perform a hash operation to obtain a hash value. Check whether there is a corresponding key-value pair in the hash table, that is, whether there is an identical exchange index.

[0025] If the same exchange index is found in the hash table, it means that the current candidate exchange index is repeated and needs to be regenerated. Regenerate a new state vector based on the current internal state, and continue to execute subsequent steps until a non-repeating candidate exchange index is generated. If the same exchange index is not found in the hash table, it means that the current candidate exchange index is valid and can be used as the final exchange index. Add the obtained valid exchange index to the pseudo-random exchange sequence as an element of the sequence. At the same time, insert the valid exchange index as a key into the hash table, and update the content of the hash table for subsequent repeatability judgment. In order to further enhance the security and unpredictability of the pseudo-random exchange sequence, obtain the current timestamp, perform an XOR operation with the generated new state vector, and obtain the final state vector. The timestamp can be obtained by obtaining the system time or network time. It introduces the time factor and increases the dynamics and randomness of the state vector.

[0026] The final state vector after XOR is used as the new internal state of the Mersenne Twister algorithm for the next generation of candidate exchange indexes. This ensures that each generated exchange index is related to the previous internal state, which increases the complexity and unpredictability of the pseudo-random exchange sequence. Determine whether the number of exchange indexes in the current pseudo-random exchange sequence has reached the preset N value. If the number of exchange indexes reaches N, it means that a sufficient number of exchange indexes have been generated and a complete pseudo-random exchange sequence can be output. The pseudo-random exchange sequence containing N exchange indexes is used as the final output result for subsequent data block exchange operations. If the number of exchange indexes has not reached N, it is necessary to continue to generate more valid exchange indexes. Return to repeat the steps of generating candidate exchange indexes, judging repeatability, updating exchange sequences and internal states according to the current internal state until N valid exchange indexes are generated. Among them, the feedback polynomial of the linear feedback shift register (LFSR) can be expressed as: f(x) = x^n+c_{n-1}x^{n-1}+c_{n-2}x^{n-2}+...+c_1x+c_0, where: n represents the level of LFSR, that is, the bit length of the state vector; c_i∈{0,1}, i=0,1,...,n-1, represents the coefficient of the feedback polynomial, which determines the position of the feedback bit; x^i represents the i-th bit in the state vector, and x^n represents the highest bit.

[0027] Furthermore, the hash table is constructed and updated using the following steps: Initialize a hash table of size N, the hash function is modulo N, and the method for resolving hash conflicts is the chain address method. The specific implementation is as follows: Define the data structure of the hash table, including: a bucket array of size N, each bucket is a pointer to the head node of the linked list; the structure of the linked list node contains an integer key and a pointer to the next node. Implement the hash function to map the exchange index to the corresponding bucket index: define the hash function as hash(key)=key%N, where key is the exchange index and N is the size of the hash table; the hash function takes the exchange index modulo the size of the hash table to obtain a bucket index ranging from 0 to N-1. Insert key-value pairs into the hash table: use the generated valid exchange index as the key (key), calculate its hash value hash(key), and get the corresponding bucket index; insert a new node at the head of the linked list corresponding to the bucket index, the key of the node is the exchange index, and the head insertion method is used to insert the new node into the head of the linked list; the head insertion method can maintain the insertion order of the key-value pairs, and the newly inserted key-value pairs are always at the head of the linked list.

[0028] Determine whether the candidate exchange index is repeated: take the candidate exchange index as the key, calculate its hash value hash(key), and get the corresponding bucket index; traverse the linked list corresponding to the bucket index, and compare whether the key of each node in the linked list is equal to the candidate exchange index; if an equal key is found, it means that the candidate exchange index already exists in the hash table, that is, a duplicate occurs; if no equal key is found after traversing the entire linked list, it means that the candidate exchange index does not exist in the hash table, that is, it is not repeated. This implementation method based on hash tables and chain address methods can efficiently insert and search key-value pairs, with an average time complexity of O(1). At the same time, the use of the head insertion method can maintain the insertion order of key-value pairs, which is convenient for subsequent processing and access. By using hash table duplication detection, repeated exchange indexes in pseudo-random exchange sequences can be effectively avoided, ensuring the validity and randomness of the sequence.

[0029] Further, the encrypted data is subjected to M rounds of obfuscation processing to obtain the final encrypted data, including: an array of fixed size, the elements in the array are integers between 0 and the size of the substitution box - 1, and each integer represents the new position to which the bit at the corresponding position will be replaced; the substitution box is also an array of fixed size, the elements in the array are integers between 0 and the size of the substitution box - 1, and each integer represents the new value to which the bit at the corresponding position will be replaced; the substitution box and the replacement box can be generated randomly or based on a key, ensuring the security and unpredictability of the obfuscation operation; the generated substitution box and the replacement box are used as parameters for obfuscation processing in each round of obfuscation operation. Data is divided into sub-blocks: the encrypted data is regarded as consisting of N fixed-size data blocks, and the size of the data block can be determined according to the packet size of the encryption algorithm; each data block is further divided into multiple sub-blocks, and the size of the sub-block is the same as the size of the substitution box; the number of sub-blocks is equal to the size of the data block divided by the size of the substitution box, ensuring that each sub-block can correspond to the substitution box one by one.

[0030] Sub-block permutation operation: For each sub-block, rearrange the bits in the sub-block according to the preset position in the permutation box; the permutation operation exchanges the bits in the sub-block according to the position specified in the permutation box, and the new position of the bit is determined by the value of the corresponding position in the permutation box; the permutation operation is a bit-level rearrangement, which increases the degree of data obfuscation by disrupting the order of the bits. Sub-block replacement operation: For each permuted sub-block, nonlinearly replace the bits in the sub-block according to the preset value in the replacement box; the replacement operation replaces each bit in the sub-block with the value of the corresponding position in the replacement box, and the replaced bit is determined by the value of the replacement box; the replacement operation is a nonlinear transformation, which replaces the bit value by looking up the table, introduces nonlinear characteristics, and enhances the data obfuscation effect. Sub-block combination: The sub-blocks after permutation and replacement operations are recombined into a complete data block in the order before permutation; the combination operation splices all sub-blocks together in the original order to obtain the encrypted data after permutation and replacement; the combination operation ensures that the obfuscated data has the same structure and length as the original encrypted data. Iterative obfuscation: Repeat the M-round obfuscation process on the encrypted data; each round of obfuscation uses the same permutation box and replacement box, but the division and combination order of the sub-blocks can change in each round; multiple rounds of obfuscation further enhance the obfuscation of the data, making it more difficult to crack or restore the data. Output the final encrypted data: After M rounds of obfuscation, the final encrypted data is obtained; the final encrypted data has the same data format and length as the original encrypted data, but has been obfuscated by permutation and replacement operations; the obfuscated data has higher randomness and unpredictability, which enhances the security of encryption.

[0031] Further, the encrypted data is subjected to M rounds of obfuscation processing to obtain the final encrypted data, wherein the replacement operation includes: dividing the replaced encrypted data: re-dividing the encrypted data after the replacement operation into multiple sub-blocks; the size of the sub-block is the same as the input size of the replacement box, usually 1 byte (8 bits); the number of sub-blocks is equal to the length of the replaced encrypted data divided by the input size of the replacement box. Constructing a byte replacement table: creating an array of size 256 bytes as a byte replacement table; the index range of the byte replacement table is 0 to 255, corresponding to all possible values ​​of a byte; each element in the byte replacement table is also a byte, used to store the replaced byte value; the byte replacement table can be generated based on a key or randomly, ensuring the security and unpredictability of the replacement operation. Replacement of bytes in a sub-block: For each sub-block obtained by division, each byte in the sub-block is used as an index of the byte replacement table; according to the value of each byte in the sub-block, the element at the corresponding index position is searched in the byte replacement table; each byte in the sub-block is replaced with the corresponding replacement byte found in the byte replacement table; the replacement operation is implemented by table lookup, mapping the original byte value to the byte value after replacement.

[0032] Sub-block splicing: All the sub-blocks after the replacement operation are spliced ​​together in the order before the division; the splicing operation reassembles all the replaced sub-blocks into complete encrypted data; the spliced ​​encrypted data has the same data length and format as the replaced encrypted data. Iterative obfuscation processing: Repeat the M rounds of obfuscation processing on the encrypted data; each round of obfuscation processing uses the same byte substitution table to ensure the consistency of the replacement operation; multiple rounds of obfuscation processing further enhances the degree of obfuscation of the data, making the data more difficult to crack or restore. Output the final encrypted data: After M rounds of obfuscation processing, the final encrypted data is obtained; the final encrypted data has been double-obfuscated by the permutation operation and the replacement operation; the obfuscated data has higher randomness and unpredictability, which enhances the security of encryption. Through the above steps, the replacement operation is introduced after the replacement operation, and the byte replacement table is used to perform nonlinear replacement of the bytes in the sub-block. The replacement operation maps the original bytes to the replaced bytes by table lookup, introducing additional nonlinear transformations, which further enhances the obfuscation effect of the data. The construction of the byte replacement table can be based on a key or randomly generated, ensuring the security and unpredictability of the replacement operation. By dividing the replaced encrypted data into sub-blocks of the same size as the replacement box input, each byte can be easily replaced independently. The replaced sub-blocks are spliced ​​together in the original order to obtain the replaced encrypted data. Multiple rounds of iterative obfuscation further improve the randomness and unpredictability of the data, enhancing the overall security of the encryption.

[0033] Preferably, a 256-byte byte substitution table and a substitution box are generated according to the key, the byte substitution table is used as a storage structure of the substitution box, and the substitution box is used to substitute the byte position in the sub-block; the index range of the byte substitution table is 0 to 255, each element in the table is a byte, which is used to store the byte value after substitution; the size of the substitution box is the same as the size of the sub-block, and is used to store the substitution mode of the byte position; the byte substitution table and the substitution box are dynamically generated according to the key, which ensures that the substitution box and the substitution box used for each encryption are different, thereby enhancing the nonlinearity and unpredictability of the encryption; the encrypted data is stored in the encrypted form according to the key. Divide the input size of the byte substitution table into N sub-blocks, add necessary padding bytes at the end of the data to ensure that the data length is an integer multiple of the input size; for each sub-block, use a substitution box to permute the byte position: generate a pseudo-random number according to the content of the sub-block, and use the pseudo-random number as the index of the substitution box; select the corresponding substitution method from the substitution box according to the index to permute the byte position in the sub-block; the permuted sub-block has higher randomness and uniform distribution characteristics; perform M rounds of substitution processing on the permuted encrypted data, and each round of substitution processing includes: dividing the encrypted data into N sub-blocks, each sub-block The size of the block is the same as the input size of the byte substitution table; for each sub-block, use the byte substitution table corresponding to the current round and the nonlinear transformation function to perform multiple substitutions: use each byte in the sub-block as an index of the byte substitution table, and search the corresponding position of the replacement byte from the byte substitution table according to the index; use the replaced byte as the input of the nonlinear transformation function, and obtain the transformed byte value through the nonlinear transformation function; the nonlinear transformation function can be an S-box, an XOR operation, a modular addition, etc.; replace each byte in the sub-block with the transformed byte value to obtain the replaced sub-block; repeat the substitution operation K times, K is the pre- Assume the number of replacements; multiple replacements combined with nonlinear transformation further enhance the obfuscation and nonlinearity of the data; the replaced sub-blocks are spliced ​​in the original order to obtain the encrypted data after the replacement process of this round; according to the encrypted data after the replacement process of this round, the byte substitution table and the substitution box are updated: the updated encrypted data are XOR-operated with the original byte substitution table and the substitution box to obtain the updated byte substitution table and the substitution box; the updated byte substitution table and the substitution box are related to the encrypted data of this round, which further enhances the dynamic and unpredictable nature of the encryption; after M rounds of replacement processing, the final encrypted data is obtained.

[0034] Furthermore, the encrypted data is subjected to M rounds of obfuscation processing to obtain the final encrypted data. The key scheduling scheme is as follows: the generated session key is used as input, and M round keys are derived using the key scheduling scheme; the number of round keys is the same as the number of rounds of obfuscation processing M, and each round key corresponds to one round of obfuscation processing; the length of each round key is the same as the length of the replaced encrypted data, ensuring the feasibility of the bitwise XOR operation of the round key and the encrypted data; the key scheduling scheme can be implemented based on a cryptographically secure pseudo-random function (such as HMAC or KDF), ensuring the security and independence of the round keys.

[0035] XOR operation of round keys: For the i-th round of obfuscation (i is an integer from 1 to M), the replaced encrypted data is subjected to a bitwise XOR operation with the i-th round key; XOR operation is a simple and effective cryptographic operation, which performs bitwise XOR operation on two bit strings of equal length to obtain the XOR result; XOR operation has the following properties: for any bits a and b, (a XOR b)XOR b=a, that is, the result of the XOR operation can be restored to the original value by performing an XOR operation with the same value; by performing an XOR operation on the encrypted data and the round key, the data can be further obfuscated, increasing the difficulty of cracking.

[0036] Iterative obfuscation processing: The encrypted data after XOR is used as the input of the next round of obfuscation processing, and M rounds of obfuscation processing are repeated; in each round of obfuscation processing, the corresponding round key is used to perform an XOR operation with the encrypted data of the current round to obtain the XORed encrypted data; the XORed encrypted data is used as the input of the next round of obfuscation processing, ensuring the dependency and continuity between each round of obfuscation processing; through multiple rounds of iterative obfuscation processing, the encrypted data can be continuously obfuscated and diffused, enhancing the overall security of encryption.

[0037] Final encrypted data: After M rounds of obfuscation, the final encrypted data is obtained; the final encrypted data has been subjected to multiple obfuscations such as permutation operation, replacement operation, and XOR operation with round keys; the obfuscated data is highly random and unpredictable, and even if part of the encrypted data is obtained, it is difficult to infer the original data or other parts of the encrypted data; the combination of multiple obfuscations has comprehensively enhanced the security of the encrypted data and greatly increased the difficulty of cracking. Through the above steps, on the basis of permutation and replacement operations, the XOR operation of the round key and the encrypted data is introduced to further enhance the obfuscation effect of the data.

[0038] The key scheduling scheme derives round keys with the same number of obfuscation rounds based on the session key, ensuring that each round of obfuscation uses an independent key, increasing the difficulty of cracking. The length of the round key is the same as the length of the encrypted data after replacement, which facilitates the implementation of bitwise XOR operations. In each round of obfuscation, the encrypted data of the current round is bitwise XORed with the corresponding round key to obtain the XORed encrypted data. XOR operations have good cryptographic properties, can effectively obfuscate data, and are reversible. The original data can be restored by XORing the same round key again. Multiple rounds of iterative obfuscation processing continuously confuses and diffuses the encrypted data, making the randomness and unpredictability of the data continuously enhanced. The output of each round of obfuscation processing serves as the input of the next round, ensuring the accumulation and transmission of the obfuscation effect.

[0039] Preferably, the generated session key is used as input, a key arrangement scheme is adopted, and M round keys and an initial vector (IV) are derived through a secure key derivation function; a key obfuscation mechanism is introduced during the iteration and obfuscation operation: in each iteration, the output of the previous round is obfuscated with the subkey of the current round, such as an exclusive OR (XOR) operation; the obfuscated result is used as the input of the pseudo-random function of the current round to generate the round key of the current round; by introducing the key obfuscation mechanism, the key dependency between different rounds is enhanced, making it difficult for an attacker to infer the value of other round keys through a known round key, thereby improving the security. The security of the encryption scheme; Introduce a counter mechanism in each iteration process: XOR the current round number with the session key as an additional input to the pseudo-random function; By introducing the counter mechanism, the independence and unpredictability of the round keys are enhanced; The M round keys derived by the key scheduling scheme, the length of each round key is the same as the length of the encrypted data after replacement, ensuring the one-to-one correspondence between the round key and the encrypted data; Use a cryptographically secure random number generator, such as a hardware-based true random number generator or a securely certified pseudo-random number generator; Generate a length that is the same as the length of the encrypted data packet The same random bit sequence is used as the initial vector (IV); by using a secure random number generator, the generated initial vector is ensured to be sufficiently random and unpredictable, thereby enhancing the security of the encryption scheme; for each data packet, an initial vector (IV) is used for initialization as the starting input of the encryption process; the data packet is divided into several sub-blocks, and the size of each sub-block is the same as the input size of the byte substitution table; multiple rounds of obfuscation processing are performed on each sub-block, and each round of obfuscation processing includes: dynamically generating a byte substitution table and a substitution box, generating a round key according to the current round; using the byte substitution table to replace the sub-block, and replacing the sub-block with the sub-block. Each byte is replaced with the corresponding replacement byte; a substitution box is used to permute the replaced sub-block to change the position of the bytes in the sub-block; a nonlinear transformation is performed on the replaced sub-block to introduce nonlinear characteristics; an XOR operation is performed on the transformed sub-block and the round key of the current round to obtain an encrypted sub-block; all encrypted sub-blocks are concatenated to obtain the encryption result of the current data group; the encryption result of the current data group is used as the initial vector (IV) of the next data group for encryption processing of the next data group; all encrypted data groups are concatenated to obtain the final encrypted data; the encrypted data is output to complete the encryption process.

[0040] Compared with the prior art, the advantages of this application are:

[0041] This solution uses a combination of symmetric encryption algorithm RC5 and asymmetric encryption algorithm RSA to generate session keys to encrypt data. The generation process of session keys introduces multiple hash algorithms such as SHA256, MD5 and SHA3-384, and introduces a feedback mechanism through CBC mode to enhance the randomness and unpredictability of the key. Even if an attacker obtains part of the encrypted data, it is difficult to infer the complete session key, thereby improving the security of data encryption.

[0042] After data encryption, this scheme uses the Mersenne Twister algorithm to generate a pseudo-random exchange sequence, performs a permutation operation on the encrypted data block, disrupts the order of the data, and increases the obfuscation of the data. At the same time, the permutation box and the replacement box are introduced to permute and nonlinearly replace the bits of the data block, and the round key is used to perform an XOR operation with the data, further enhancing the diffusion and anti-differential properties of the data. This multiple obfuscation process increases the difficulty for attackers to analyze and crack encrypted data, and improves the anti-attack ability of encrypted data.

[0043] This solution takes into account the characteristics of structured data and unstructured data, using the SHA256 algorithm to perform hash calculations on structured data and the MD5 algorithm to perform hash calculations on unstructured data to generate initial vectors. This differentiated processing for different data types can better meet the encryption needs of structured and unstructured data and provide comprehensive data protection.

[0044] This solution uses the efficient symmetric encryption algorithm RC5 and the classic asymmetric encryption algorithm RSA. While ensuring data security, it also takes into account the performance of encryption and decryption. The session key is used to encrypt the data, avoiding the overhead of frequently using public and private keys to encrypt and decrypt large amounts of data. At the same time, through the optimized obfuscation process and the support of parallel computing, the efficiency of data processing is improved, which is suitable for application scenarios that require encryption performance. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] The present application will be further described in the form of exemplary embodiments, which will be described in detail by the accompanying drawings. These embodiments are not restrictive, and in these embodiments, the same number represents the same structure, wherein:

[0046] Figure 1 is an exemplary flow chart of an encryption method based on the RSA algorithm according to some embodiments of the present application;

[0047] Figure 2 is an exemplary flow chart of generating a session key according to some embodiments of the present application;

[0048] Figure 3is an exemplary flow chart of generating encrypted data according to some embodiments of the present application;

[0049] Figure 4 is an exemplary flow chart of generating a pseudo-random exchange sequence according to some embodiments of the present application;

[0050] Figure 5 This is an exemplary flowchart of generating final encrypted data according to some embodiments of the present application. DETAILED DESCRIPTION

[0051] The method and system provided in the embodiments of the present application are described in detail below with reference to the accompanying drawings.

[0052] Example 1

[0053] Figure 1 This is an exemplary flow chart of an encryption method based on the RSA algorithm according to some embodiments of the present application, including: collecting data to be encrypted; wherein the data to be encrypted includes structured data and unstructured data. Using the symmetric block encryption algorithm RC5, with a preset key length and number of encryption rounds, a session key for the data to be encrypted is generated; using a preset RSA public key to encrypt the generated session key; using the symmetric block encryption algorithm RC5 and the encrypted session key to encrypt the data to be encrypted to generate encrypted data; performing M rounds of obfuscation processing on the encrypted data to obtain the final encrypted data.

[0054] In the encryption method based on the RSA algorithm provided in the present application, it is first necessary to collect the data to be encrypted. The data to be encrypted includes structured data and unstructured data. The structured data is usually organized in a specific format and structure, such as a database table, a CSV file, data in JSON format, etc. For the collection of structured data, the following methods can be used: Query and obtain data from a relational database: query the required data from a relational database such as MySQL, Oracle, PostgreSQL, etc. through SQL statements, and return the query results in a structured form. Read structured files: read data from structured files such as CSV files, JSON files, XML files, and parse the data content according to predefined formats and fields. Receive structured data streams: receive structured data streams transmitted by external systems through network interfaces, message queues, etc., such as JSON format data returned by a RESTAPI interface.

[0055] Unstructured data refers to data without a predefined format and structure, such as text files, pictures, audio, video, etc. For the collection of unstructured data, the following methods can be used: Read unstructured files: Read raw binary data or text content from unstructured files such as text files, picture files, audio files, and video files. Receive unstructured data streams: Receive unstructured data transmitted by external systems through network interfaces, file uploads, etc., such as uploaded picture files, audio files, etc. Collect real-time unstructured data: Collect unstructured data such as images and audio in real time through devices such as cameras and microphones, and convert them into digital signals for processing. Store the collected structured and unstructured data in appropriate data structures for subsequent encryption processing. You can use data structures such as arrays, lists, and dictionaries to store structured data, and use data structures such as byte arrays and strings to store unstructured data.

[0056] Figure 2 This is an exemplary flow chart of generating a session key according to some embodiments of the present application. The generation of a session key is a key step. The session key is used to encrypt the data to be encrypted using the symmetric encryption algorithm RC5. Hash calculation is performed on structured data and unstructured data: For structured data to be encrypted, the SHA256 algorithm is used for hash calculation. SHA256 is a secure one-way hash function that can map data of any length to a 256-bit hash value. By performing SHA256 hash calculation on structured data, a 256-bit structured data hash value is obtained.

[0057] For unstructured data to be encrypted, the MD5 algorithm is used for hash calculation. MD5 is another commonly used hash function that can map data of any length to a 128-bit hash value. By performing MD5 hash calculation on unstructured data, a 128-bit unstructured data hash value is obtained.

[0058] Concatenate hash values ​​to generate initial vector: Concatenate the structured data hash value and the unstructured data hash value in a preset order to form a 384-bit concatenated hash value. The preset order can be to put the structured data hash value first and the unstructured data hash value last, or to concatenate in another agreed order. The concatenated 384-bit hash value is used as the initial vector for subsequent encryption operations.

[0059] Set the parameters of the RC5 algorithm: Set the key length of the RC5 algorithm to L bits, where L is a positive integer. The key length determines the security strength of the RC5 algorithm. Usually, you can choose a length of 128 bits, 192 bits, or 256 bits. Set the number of encryption rounds of the RC5 algorithm to T, where T is a positive integer. The number of encryption rounds represents the number of iterations in the RC5 algorithm. Increasing the number of encryption rounds can improve the security of encryption, but it will also increase the computational overhead. Perform SHA3-384 hash calculation on the initial vector: Use the SHA3-384 algorithm to perform hash calculation on the generated initial vector. SHA3-384 is a hash function in the SHA-3 family that can map data of any length to a 384-bit hash value. By performing SHA3-384 hash calculation on the initial vector, a 384-bit SHA3 hash value is obtained. Split the SHA3 hash value into subvectors: Split the obtained 384-bit SHA3 hash value into S subvectors, recorded as V1 to VS. The division method may be to divide the SHA3 hash value into S equal parts, each of which has a length of 384 / S bits. For example, if S=12, the SHA3 hash value is divided into 12 sub-vectors of 32 bits in length.

[0060] Generate subkeys for the RC5 algorithm: Use the RC5 algorithm, with a preset initial key of L bits and the number of encryption rounds T as parameters, to generate T subkeys of L bits in length, denoted as K1 to KT. The key expansion process of the RC5 algorithm generates a series of subkeys based on the initial key and the number of encryption rounds, which are used for each round of encryption operations.

[0061] Use the subkey to RC5 encrypt the subvector: For the i-th subvector Vi among the S subvectors obtained, use the generated i-th subkey Ki to perform RC5 encryption. The RC5 encryption algorithm will perform a series of bit operations and circular shift operations on the subvector Vi and the subkey Ki to obtain an encrypted subvector Ci with a length of L bits. Repeat this process, and use the corresponding subkey Ki to perform RC5 encryption on each subvector Vi to obtain S encrypted subvectors C1 to CS.

[0062] Iterative calculation using CBC mode: Cipher Block Chaining (CBC) mode is used to perform iterative calculation using the S encrypted subvectors C1 to CS as input. In CBC mode, each encrypted subvector is XORed with the result of the previous encrypted subvector before the next round of encryption operation is performed. Through iterative calculation, S feedback encrypted subvectors C'1 to C'S with a length of L bits are obtained.

[0063] Concatenate feedback encryption sub-vectors to generate session keys: Concatenate the S feedback encryption sub-vectors C'1 to C'S in order to obtain a session key with a length of 384 bits. The concatenation order is the same as the generation order of the feedback encryption sub-vectors to ensure the correctness of the session key. By performing RSA encryption on the session key, the confidentiality and integrity of the session key can be ensured. Preset RSA public key and private key pair: Before the encryption process begins, a pair of RSA public key and private key are pre-generated. The RSA public key is used to encrypt the session key, and the corresponding RSA private key is used to decrypt the encrypted session key.

[0064] The generation of RSA public and private keys can be achieved through the following steps: Select two large prime numbers p and q, and calculate their product n = p*q, where n is called the RSA modulus. Calculate the Euler function value of n φ(n) = (p-1)*(q-1). Select an integer e that is relatively prime to φ(n) as the public key exponent, usually 65537. Calculate the modular inverse element d of e with respect to φ(n), so that (e*d)modφ(n) = 1, and d is used as the private key exponent. The RSA public key is (n, e), and the RSA private key is (n, d).

[0065] Encrypt the session key using the RSA public key: Use the generated 384-bit session key as the plaintext data to be encrypted. Use the preset RSA public key (n, e) to encrypt the session key to obtain the encrypted session key. The specific process of RSA encryption is as follows: Represent the session key as an integer m that is less than the RSA modulus n. Calculate the encrypted session key c using the formula: c = m^emodn, where ^ represents modular exponentiation. The obtained c is the encrypted session key, which is an integer with the same length as the RSA modulus n. Encode and format the encrypted session key: Since the encrypted session key is a large integer, it needs to be encoded and formatted for easy transmission and storage. Common encoding methods include Base64 encoding, hexadecimal encoding, etc., which can convert the encrypted session key into a readable string format. The encoded encrypted session key can be stored or transmitted as a string for subsequent decryption and use.

[0066] Figure 3It is an exemplary flow chart for generating encrypted data according to some embodiments of the present application, and securely transmits the encrypted session key: the encrypted session key needs to be transmitted to the recipient through a secure communication channel so that the recipient can use the corresponding RSA private key for decryption. A secure communication protocol such as SSL / TLS can be used to perform secondary encryption on the encrypted session key during the transmission process to ensure that it is not obtained by unauthorized third parties. Measures should also be taken during the transmission process to prevent tampering and replay attacks to ensure the integrity and authenticity of the encrypted session key. The symmetric block encryption algorithm RC5 and the encrypted session key are used to encrypt the encrypted data to generate encrypted data: Data block storage: The data to be encrypted is divided into N blocks, where N is an integer greater than 1, indicating the number of data blocks. The divided data is stored in a cache area, which can be a continuous space in the memory or other data structure suitable for storing data blocks. The size of each data block can be set according to actual needs and the requirements of the encryption algorithm, and a block size that matches the packet size of the encryption algorithm is usually selected.

[0067] Figure 4 This is an exemplary flow chart for generating a pseudo-random exchange sequence according to some embodiments of the present application. The Mersenne Twister algorithm is used to generate a pseudo-random exchange sequence, and the internal state of the Mersenne Twister algorithm is initialized: the internal state includes two parts: a seed value and a state vector. The seed value is used to initialize the state vector, and the current timestamp, random number or other entropy source can be used as the seed value. The state vector is an integer array with a length of 624, which is used to generate a pseudo-random number sequence. The seed value is passed to the Mersenne Twister algorithm, and the value of the state vector is initialized according to the seed value. A key derivation function based on a hash function is used to generate a seed value: the generated session key is used as input, and a hash value is calculated by a hash function (such as SHA-256). The calculated hash value is used as the initial seed value of the Mersenne Twister algorithm. The use of a key derivation function can enhance the randomness and security of the seed value and prevent the seed value from being predicted or guessed.

[0068] Generate a new state vector based on the internal state: Use a linear feedback shift register (LFSR) to shift the current state vector. The LFSR generates a new state vector by performing an XOR operation on certain bits of the state vector. The Mersenne Twister algorithm uses a specific LFSR structure called the Mersenne Prime LFSR (Mersenne Prime LFSR). The feedback polynomial of the LFSR uses the characteristics of Mersenne primes to generate a pseudo-random sequence with a long period. Perform bit operations such as shifts and XOR on the generated new state vector to further mix the bits of the state vector.

[0069] Generate candidate exchange indexes: Perform a modulo N operation on the generated new state vector to obtain a random integer in the range of 1 to N. The modulo N operation ensures that the generated random integer falls within the legal exchange index range. Use the generated random integer as the candidate exchange index for subsequent repeatability checks. Determine whether the candidate exchange index is repeated: Use a hash table to determine whether the candidate exchange index is repeated with the previously generated exchange index. Use the candidate exchange index as the key to search in the hash table. If the same key exists in the hash table, it means that the candidate exchange index is repeated and the candidate exchange index needs to be regenerated. If the same key does not exist in the hash table, it means that the candidate exchange index is valid and can be used as the final exchange index.

[0070] Update the pseudo-random exchange sequence and hash table: Add the valid exchange index to the pseudo-random exchange sequence as part of the sequence. At the same time, insert the valid exchange index into the hash table as a key for subsequent duplication checks. The hash table is updated using the head insertion method, inserting the new key into the head of the linked list to improve search efficiency.

[0071] Update the internal state of the Mersenne Twister algorithm: Get the current timestamp as an additional entropy source. XOR the current timestamp with the generated new state vector to obtain the final state vector. Use the final state vector as the new internal state of the Mersenne Twister algorithm for the next pseudo-random number generation. By introducing the timestamp, the unpredictability and randomness of the pseudo-random number sequence can be increased. Repeat until N valid exchange indexes are generated. Each time a new candidate exchange index is generated, a repeatability check is performed to ensure that the generated exchange index is not repeated. When the number of generated valid exchange indexes reaches N, the generation process is stopped to obtain a complete pseudo-random exchange sequence. The Mersenne Twister algorithm is used to generate a pseudo-random exchange sequence containing N exchange indexes. The Mersenne Twister algorithm has good statistical properties and long periodicity, and can generate high-quality pseudo-random number sequences. By introducing the session key as the seed value and combining the hash function for key derivation, the randomness and security of the seed value are enhanced. At the same time, a hash table is used for repeatability checks to ensure that the generated exchange index is not repeated, which ensures the validity of the pseudo-random exchange sequence. Finally, by introducing a timestamp to update the internal state, the unpredictability of the pseudo-random number sequence is further increased.

[0072] The exchange of data blocks is guided by a pseudo-random exchange sequence, thereby realizing the position obfuscation and rearrangement of the encrypted data. The first exchange index is obtained from the generated pseudo-random exchange sequence, and the index indicates the position of the first pair of data blocks to be exchanged. According to the exchange index, two data blocks at corresponding positions are obtained from the cache storing the encrypted data blocks, and are marked as data block blockA and data block blockB respectively. The cache can be a continuous space in the memory, and the data blocks are stored in the cache in a continuous manner. The exchange index is used as the offset of the data block in the cache, and the corresponding data block can be quickly located and accessed through the offset. The obtained data block blockA and data block blockB are saved in temporary variables for subsequent exchange operations. The storage positions of data block blockA and data block blockB in the cache are exchanged to realize the position exchange of data blocks.

[0073] The exchange operation can be implemented in the following two ways: Pointer exchange: If the data block is accessed by a pointer or reference, the pointer to the data block can be simply exchanged without moving the actual data. Data exchange: If the data block is directly stored in the cache, the position exchange needs to be achieved by exchanging the content of the data block. A temporary variable can be used to store the content of one of the data blocks, and then the content of the other data block is copied to the location, and finally the content in the temporary variable is copied to the location of the other data block. After the exchange operation is completed, the positions of data block blockA and data block blockB in the cache are exchanged, and the position confusion is achieved. Get the next exchange index in the pseudo-random exchange sequence and repeat the operation of exchanging storage positions. According to the index order in the pseudo-random exchange sequence, the data blocks at the corresponding positions are exchanged in sequence until all data blocks are exchanged. The specific steps are as follows: Initialize a loop variable i to represent the index position of the current exchange, with an initial value of 0. Get the next exchange index index from the pseudo-random exchange sequence. According to the exchange index index, get the two data blocks blockA and blockB at the corresponding positions from the cache. To exchange the storage positions of blockA and blockB in the cache, pointer exchange or data exchange can be used. Increment the loop variable i to indicate moving to the next exchange index position. Repeat until the loop variable i reaches the length N of the pseudo-random exchange sequence, that is, the exchange of all data blocks is completed. By repeating the exchange process, the encrypted data blocks are confused and rearranged in the order of the pseudo-random exchange sequence, increasing the randomness and unpredictability of the data. After the exchange of all data blocks is completed, output N blocks of encrypted data from the buffer in the order after the exchange as the generated encrypted data.

[0074] Figure 5This is an exemplary flow chart for generating the final encrypted data according to some embodiments of the present application. In the process of performing M rounds of obfuscation processing on the encrypted data, by introducing substitution boxes, replacement boxes and round keys, the encrypted data undergoes multiple rounds of substitution, replacement and XOR operations, thereby enhancing the randomness and unpredictability of the encrypted data and obtaining the final encrypted data: Preset substitution boxes and replacement boxes: The substitution box is an array of fixed size, which is used to perform substitution operations on the bits of a data block. The size of the substitution box is the same as the size of the data block, and each element represents the position of the bit after substitution. The replacement box is a lookup table of fixed size, which is used to perform nonlinear substitution on the bits of a data block. The size of the replacement box is usually 256 bytes, and each element represents the byte value after substitution. The substitution box and replacement box can be generated randomly or based on key derivation to increase the randomness and security of the obfuscation process.

[0075] The generated permutation box and replacement box are used as parameters of the obfuscation process to guide the permutation and replacement operations of the data block.

[0076] When performing a permutation operation on encrypted data, it is necessary to divide the encrypted data into multiple sub-blocks and rearrange the bits in each sub-block according to the preset permutation box. Data block division: Determine the size of the permutation box, assuming that the size of the permutation box is n bits. Divide the encrypted data into multiple sub-blocks of n bits. If the length of the encrypted data is not an integer multiple of n, padding can be performed at the end of the last sub-block, and the padding bits can use a fixed value or a random value. The number of sub-blocks after division is the length of the encrypted data divided by n, rounded up. Rearrangement of bits in a sub-block: For each sub-block, rearrange the bits in the sub-block according to the preset position of the permutation box. The specific steps are as follows: Initialize a temporary array of the same size as the sub-block to store the permuted sub-blocks. The size of the temporary array is n bits, which is the same as the size of the sub-block. Each element of the temporary array is initialized to 0. Traverse each bit of the sub-block and place the bit at the corresponding position of the temporary array according to the value of the corresponding position in the permutation box. The permutation box is an array of size n, in which each element represents the position of the permuted bit. For the ith bit of the sub-block (i starts at 0), find the value j of the element with index i in the permutation box. Place the value of the ith bit of the sub-block into the jth position of the temporary array. Combine the bits in the temporary array in the order after permutation to obtain the permuted sub-block. The size of the permuted sub-block is the same as the size of the original sub-block, both of which are n bits. The order of the bits in the permuted sub-block is consistent with the order of the bits in the temporary array.

[0077] Combination of permuted sub-blocks: Combine the permuted sub-blocks in the order before permutation to obtain the permuted encrypted data. The combination process is to splice the permuted sub-blocks in sequence to form a complete encrypted data. The splicing order is the same as the order of sub-block division, that is, the first permuted sub-block corresponds to the first sub-block of the original encrypted data, and so on. The length of the permuted encrypted data is the same as the length of the original encrypted data. Through the above steps, the encrypted data is permuted, the encrypted data is divided into multiple sub-blocks, and the bits in each sub-block are rearranged according to the preset permutation box, and finally the permuted encrypted data is obtained. The design of the permutation box needs to meet certain security requirements to avoid weak keys or predictable permutation patterns. The permutation box can be generated randomly or based on key derivation to increase the randomness and security of the permutation operation. At the same time, in the implementation process, it is necessary to ensure that the size of the permutation box is consistent with the size of the sub-block to avoid security vulnerabilities caused by data truncation or padding.

[0078] When performing a replacement operation on the replaced encrypted data, the encrypted data needs to be divided into multiple sub-blocks, and the bytes in each sub-block are replaced using a pre-built byte replacement table. The replaced encrypted data is divided into multiple sub-blocks, and the size of each sub-block is the same as the input size of the replacement box (usually 1 byte). If the length of the encrypted data is not an integer multiple of the input size of the replacement box, padding can be performed at the end of the last sub-block, and the padding bytes can use fixed values ​​or random values. The number of sub-blocks after division is the length of the encrypted data divided by the input size of the replacement box, rounded up.

[0079] Construction of byte substitution table: Construct a 256-byte byte substitution table as the storage structure of the replacement box. The index range of the byte substitution table is 0 to 255, corresponding to all possible byte values. Each element in the table is a byte, which is used to store the replaced byte value. The byte substitution table can be generated by random generation or key derivation to increase the randomness and security of the replacement operation. Replacement of bytes in sub-blocks: For each sub-block obtained by division, each byte in the sub-block is used as an index of the byte substitution table. The specific steps are as follows: Traverse each byte in the sub-block. Use the value of the current byte as the index of the byte substitution table. In the byte substitution table, find the element at the corresponding position according to the index value to obtain the replaced byte value. Replace the current byte in the sub-block with the corresponding replacement byte found in the byte substitution table. The size of the replaced sub-block is the same as the size of the original sub-block, both of which are the input size of the replacement box (usually 1 byte).

[0080] Splicing of replaced sub-blocks: All replaced sub-blocks are spliced ​​in sequence according to the order before division as the replaced encrypted data. The splicing process is to connect the replaced sub-blocks in sequence to form a complete encrypted data. The splicing order is the same as the order of sub-block division, that is, the first replaced sub-block corresponds to the first sub-block of the original encrypted data, and so on. The length of the replaced encrypted data is the same as the length of the replaced encrypted data. Through the above steps, the replaced encrypted data is replaced, the encrypted data is divided into multiple sub-blocks, and the bytes in each sub-block are replaced using the pre-built byte substitution table, and finally the replaced encrypted data is obtained. The design of the byte substitution table needs to meet certain security requirements to avoid weak keys or predictable substitution patterns. The byte substitution table can be generated by random generation or based on key derivation to increase the randomness and security of the replacement operation. At the same time, in the implementation process, it is necessary to ensure that the size of the byte substitution table is 256 bytes, covering all possible byte values, and the replaced byte values ​​should be randomly distributed to enhance the nonlinear characteristics of the replacement operation.

[0081] When obfuscating the replaced encrypted data, it is necessary to generate multiple round keys and perform bitwise XOR operations on the encrypted data of each round with the corresponding round key. Generation of round keys: adopt the key arrangement scheme, use the generated session key as input, and derive M round keys. The length of each round key is the same as the length of the replaced encrypted data, ensuring that it can be bitwise XORed with the encrypted data.

[0082] The key scheduling scheme can be implemented in the following ways: Hash function: The session key and round number are used as inputs to generate round keys through a hash function (such as SHA-256). The session key and round number can be concatenated, and then the concatenated data is hashed to obtain a fixed-length hash value. The hash value is truncated or extended to the same length as the encrypted data as the round key for that round. Pseudo-random number generator (PRNG): The session key is used as a seed to generate a series of random numbers through a pseudo-random number generator. A secure pseudo-random number generation algorithm such as CTR-DRBG or HMAC-DRBG can be used. The generated random numbers are truncated or extended to the same length as the encrypted data as the round key. Other key derivation functions: Use specialized key derivation functions such as HKDF (HMAC-based Key Derivation Function) or PBKDF2 (Password-BasedKey Derivation Function2). The session key is used as input to generate key material of the required length through a key derivation function. The key material is divided into M equal-length parts as round keys.

[0083] XOR operation: For the i-th round of obfuscation, the replaced encrypted data is subjected to bitwise XOR operation with the i-th round key to obtain the XORed encrypted data. The XOR operation can be implemented by performing XOR operation on the corresponding bits of the encrypted data and the round key. The specific steps are as follows: the replaced encrypted data and the i-th round key are bitwise aligned; each corresponding bit of the encrypted data and the round key is subjected to XOR operation. The result of the XOR operation is used as the output of this round of obfuscation, that is, the XORed encrypted data. The XOR operation has the following properties: the XOR operation is reversible, that is, the XORed result can be restored to the original data by performing XOR operation again. The XOR operation can introduce randomness and obfuscation effects, making the encrypted data more difficult to predict and analyze. Multi-round obfuscation: The XORed encrypted data is used as the input of the next round of obfuscation, and M rounds of obfuscation are repeated. In each round of obfuscation, a different round key is used to perform XOR operation with the encrypted data.

[0084] After M rounds of obfuscation, the final encrypted data is obtained. XOR operation is a simple and effective obfuscation method. By performing bitwise XOR operation on the encrypted data and the round key, randomness and obfuscation effects are introduced, making it difficult for attackers to directly analyze and crack the encrypted data. The iterative process of multiple rounds of obfuscation further enhances the security of the encrypted data. Each round uses a different round key for XOR operation, which changes the encrypted data in each round, increasing the difficulty of cracking.

[0085] Example 2

[0086] Encryption of private data, collection of financial private data to be encrypted:

[0087] Structured customer information: name "XXXX", ID number "XXXX", bank card number "XXXX"

[0088] Unstructured transaction record text: "XXXX paid 1,234.56 via bank card XXXX123456 at 21:30 on May 10, 2023"

[0089] Generate session key: Perform SHA256 hash on the structured customer information "XXXXXXXXXXXX123456" to obtain a 256-bit hash value:

[0090] a4b8c9d0e1f2g3h4i5j6k7l8m9n0opqrstuvwxyz0XXXXABCDEFGHIJKLM.

[0091] Perform MD5 hashing on the unstructured transaction record text to obtain a 128-bit hash value:

[0092] a1b2c3d4e5f6g7h8i9j0klmnopqrstu; concatenate the hash values ​​to get a 384-bit initial vector:

[0093] a4b8c9d0e1f2g3h4i5j6k7l8m9n0opqrstuvwxyz0XXXXABCDEFGHIJKLMa1b2c3d4e5f6g7h8i9j0klmnopqrstu. Assuming the RC5 key length is 256 bits, encryption is performed for 12 rounds, and the above 384-bit initial vector is hashed using SHA3-384 to obtain:

[0094] ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz0011223344556677889900AABBCCDDEEFF. Split the SHA3 hash value into three 128-bit subvectors: V1: ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567; V2:

[0095] 89abcdefghijklmnopqrstuvwxyz001122; V3: 3344556677889900AABBCCDDEEFF; Use the 256-bit initial key K0 to encrypt for 12 rounds and generate 12 256-bit subkeys K1 to K12; Use K1, K2, K3 to perform RC5 encryption on V1, V2, and V3 respectively, and get: C1: a0a1a2a3a4a5a6a7a8a9aaabacadaeaf; C2: b0b1b2b3b4b5b6b7b8b9babbbcbdbebf; C3: c0c1c2c3c4c5c6c7c8c9cacbcccdcecf.

[0096] Use CBC mode to link C1 to C3: Let IV be a 256-bit initialization vector of all 0s, XOR IV with V1 to get C'0: ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567. XOR C1 with C'0 to get R1: 0b0c0d0e0f0g0h0i0j0k0l0m0n0o0p0q, encrypt R1 with K1 to get E1, XOR E1 with V1 to get C'1:

[0097] 343434343434343434343434343434. C2 and C'1 are XORed to get R2:

[0098] bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd, encrypt R2 with K2 to get E2, XOR E2 with V2 to get C'2:

[0099] 78787878787878787878787878787878. C3 and C'2 are XORed to get R3:

[0100] b8b9babbbcbdbebfb0b1b2b3b4b5b6b7, encrypt R3 with K3 to get E3, XOR E3 and V3 to get C'3: cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd.

[0101] Concatenate C'1, C'2, and C'3 to get a 384-bit session key:

[0102] 3434343434343434343434343434347878787878787878787878787878787878787878cdcdc dcdcdcdcdcdcdcdcdcdcdcdcdcd. Use the 3072-bit RSA public key to encrypt the session key, get the encrypted session key, and perform RC5 block encryption on the financial privacy data: Plaintext data block: "XXXXXXXXXXXX12345678$1, 234.562023-05-1021:30". Use the session key as the key, encrypt in RC5 algorithm CBC mode, and get the ciphertext data block:

[0103] a68qw9ertyu5iop34asdf2gh78jk12l3zx4cv6bn5m1qaz7ws8xedc9rfv4tgb65hy78uj90mki87ol6p54hy3jn21qw0ms9xd7cv4fr3gt6yh. Perform three rounds of obfuscation on the ciphertext data block: Block: The ciphertext data block size is 96 bytes, divided into 1 block B1. Initialize MT19937 with the session key seed and generate a pseudo-random exchange sequence {1} without deduplication. There is only one data block, no need to exchange, output B1 as the exchanged ciphertext; use 128-byte substitution box P to rearrange the bit positions in B1 to obtain the replaced data block B1'; use 256-byte substitution box S to replace each byte in B1' to obtain the replaced data block B1"; derive three 128-byte round keys RK1, RK2, RK3 from the session key; round keys RK1, RK2, RK3 are XORed with B1" respectively, complete three rounds of confusion, and obtain the final ciphertext,

[0104] k86rq0ertyu2iop31asdf5gh46jk80l7zx9cv1bn2m4qaz8ws0xedc3rfv7tgb12hy45uj67mki09ol3p21hy8jn54qw7ms6xd0cv9fr8gt1yh. Output the final ciphertext data after 3 rounds of obfuscation.

Claims

1. An encryption method based on RSA algorithm, comprising: Collecting data to be encrypted; wherein the data to be encrypted includes structured data and unstructured data; The symmetric block encryption algorithm RC5 is used to generate the session key of the data to be encrypted with the preset key length and number of encryption rounds; Use the preset RSA public key to encrypt the generated session key; The symmetric block encryption algorithm RC5 and the encrypted session key are used to encrypt the data to be encrypted and generate encrypted data; The encrypted data is subjected to M rounds of obfuscation processing to obtain the final encrypted data.

2. The encryption method based on the RSA algorithm according to claim 1, characterized in that: Generate a session key, including: Use the SHA256 algorithm to perform hash calculation on the structured data to be encrypted, and obtain a 256-bit structured data hash value; Use the MD5 algorithm to perform hash calculation on the unstructured data to be encrypted, and obtain a 128-bit unstructured data hash value; The structured data hash value and the unstructured data hash value are concatenated in a preset order to obtain a concatenated hash value of 384 bits in length as an initial vector; Set the key length of the RC5 algorithm to L bits and the number of encryption rounds to T, where L and T are positive integers; The SHA3-384 algorithm is used to perform hash calculation on the initial vector to obtain a 384-bit SHA3 hash value.

3. The encryption method based on the RSA algorithm according to claim 2, characterized in that: Generate session keys, also include: Divide the SHA3 hash value into S sub-vectors, denoted as V1 to V s ; For the i-th subvector V among the obtained S subvectors i , using the generated i-th subkey K i Perform RC5 encryption to obtain an encrypted subvector C with a length of L bits i ; Wherein, i is an integer from 1 to S; The Cipher Block Chaining (CBC) mode is used with S encrypted sub-vectors C1 to C s As input, iterative calculation is performed to obtain S feedback encryption sub-vectors C1' to C s '; The obtained S feedback encryption sub-vectors C1' to C s 'Concatenate to obtain a session key with a length of 384 bits.

4. The encryption method based on the RSA algorithm according to claim 3, characterized in that: Using CBC mode, we get S feedback encryption sub-vectors C1' to C s ',include: Performing a bitwise XOR operation on the first sub-vector V1 and the preset initial vector IV, obtaining the XOR result as the initial value of the feedback encryption sub-vector C0'; wherein the length of the initial vector IV is L bits; The i-th encrypted subvector C i The feedback encrypted subvector C obtained from the previous iteration i-1 'Perform bitwise XOR operation to obtain the XOR result R with a length of L bits i ; Use the generated i-th subkey K i As the key, the XOR result R i Perform RC5 encryption operation to obtain the encryption result E with a length of L bits i ; The encrypted result E i Perform bitwise XOR operation with the i-th sub-vector Vi to obtain the feedback encryption sub-vector C with a length of L bits i '; Repeat the above iterative process to obtain S feedback encryption sub-vectors C1' to C s '.

5. The encryption method based on the RSA algorithm according to any one of claims 2 to 4, characterized in that: Generate encrypted data, including: The encrypted data obtained by encrypting the data to be encrypted by using the symmetric block encryption algorithm RC5 and the encrypted session key is divided into N blocks, and stored in the buffer area, where N is an integer greater than 1; The Mersenne Twister algorithm is used to generate a pseudo-random exchange sequence including N exchange indexes, wherein the exchange index is a positive integer between 1 and N, and is used to indicate the position of the data block in the buffer area; Obtain the first exchange index in the generated pseudo-random exchange sequence, and obtain two data blocks at corresponding positions from the buffer area storing the encrypted data blocks according to the first exchange index, and mark them as data block blockA and data block blockB respectively; Exchange the storage locations of data block blockA and data block blockB in the cache area; Get the next swap index in the pseudo-random swap sequence, and repeat the swap storage location until all data blocks are completed; According to the order after the exchange, N blocks of encrypted data are output from the buffer area as generated encrypted data.

6. The encryption method based on the RSA algorithm according to claim 5, characterized in that: The Mersenne Twister algorithm is used to generate a pseudo-random exchange sequence containing N exchange indices, including: Initialize the internal state of the Mersenne Twister algorithm, which includes a seed value and a state vector; use a key derivation function based on a hash function, take the generated session key as input, derive a seed value, and set the seed value as the initial seed value of the Mersenne Twister algorithm; According to the internal state of the Mersenne Twister algorithm, a new state vector is generated by using a linear feedback shift register and bit operation; wherein the linear feedback shift register performs a shift operation on the current state vector and performs an XOR operation with a preset feedback polynomial to update the state vector; the bit operation performs a bit operation on the updated state vector to mix the bits of the state vector; Perform a modulo N operation on the generated new state vector to obtain a random integer ranging from 1 to N as a candidate exchange index in the pseudo-random exchange sequence; A hash table is used to determine whether the generated candidate exchange index is repeated with the previously generated exchange index; the candidate exchange index is used as a key to perform a hash operation, and the corresponding key-value pair is searched in the hash table. If the key-value pair is found, it means that the candidate exchange index is repeated, and the candidate exchange index is regenerated. Otherwise, the generated candidate exchange index is used as a valid exchange index; Add the obtained valid exchange index to the pseudo-random exchange sequence, insert the valid exchange index as a key into the hash table, and update the content of the hash table; obtain the current timestamp, perform an XOR operation with the generated new state vector, obtain the final state vector, and use the final state vector as the new internal state of the Mersenne Twister algorithm; Determine whether the number of exchange indexes in the pseudo-random exchange sequence reaches N. If so, output a pseudo-random exchange sequence containing N exchange indexes. Otherwise, repeat the step of generating valid exchange indexes until N valid exchange indexes are generated.

7. The encryption method based on the RSA algorithm according to claim 6, characterized in that: The hash table is constructed and updated using the following steps: Initialize a hash table of size N, and the hash function is modulo N; The generated valid exchange index is used as the key and inserted into the corresponding bucket in the hash table, and the key is added to the head of the linked list using the head interpolation method; When determining whether a candidate exchange index is repeated, the candidate exchange index is used as the key, the hash value is calculated, and a search is performed in the linked list in the corresponding bucket to determine whether the same key exists. If so, it indicates a repeat, otherwise it does not exist.

8. The encryption method based on the RSA algorithm according to claim 6, characterized in that: Perform M rounds of obfuscation on the encrypted data to obtain the final encrypted data, including: A set of fixed-size substitution boxes and replacement boxes are preset, wherein the substitution box is used to perform a substitution operation on the bits of a data block, and the replacement box is used to perform a nonlinear replacement on the bits of a data block; the generated substitution boxes and replacement boxes are used as parameters for obfuscation processing; The generated encrypted data is taken as input, and the encrypted data consists of N data blocks; the encrypted data is divided into a plurality of sub-blocks, and the size of each sub-block is the same as the size of the substitution box; For each sub-block, rearrange the bits in the sub-block according to the preset position of the substitution box to obtain a permuted sub-block; Combine the replaced sub-blocks in the order before replacement to obtain the replaced encrypted data.

9. The encryption method based on the RSA algorithm according to claim 8, characterized in that: The encrypted data is subjected to M rounds of obfuscation processing to obtain the final encrypted data, which also includes: Divide the permuted encrypted data into a plurality of sub-blocks, each sub-block having a size equal to the input size of the substitution box; Construct a 256-byte byte replacement table as the storage structure of the replacement box. The index range of the byte replacement table is 0 to 255. Each element in the table is a byte for storing the byte value after replacement. For each sub-block obtained by division, each byte in the sub-block is used as an index of the byte replacement table; In the byte replacement table, according to the value of each byte in the sub-block, the element at the corresponding index position in the table is searched to obtain the byte value after replacement; Replace each byte in the sub-block with the corresponding replacement byte found in the byte replacement table to obtain a replaced sub-block; All the replaced sub-blocks are concatenated in sequence according to the order before the division to serve as the replaced encrypted data.

10. The encryption method based on the RSA algorithm according to claim 9, characterized in that: The encrypted data is subjected to M rounds of obfuscation processing to obtain the final encrypted data, which also includes: A key scheduling scheme is adopted to derive M round keys with the generated session key as input, and the length of each round key is the same as the length of the encrypted data after replacement; For the i-th round of obfuscation, the replaced encrypted data is subjected to a bitwise XOR operation with the i-th round key to obtain the XORed encrypted data; wherein i is an integer from 1 to M; The encrypted data after XOR is used as the input of the next round of obfuscation processing, and M rounds of obfuscation processing are repeated to obtain the final encrypted data.

Citation Information

Patent Citations

  • Data acquisition method and system based on RSA asymmetric encryption

    CN116506230B

  • Information processing device

    CN101536401A

  • Hybrid encryption method and system, hybrid decryption method and system, equipment and storage medium

    CN112989391A

  • Data encryption and decryption method and device, electronic equipment and storage medium

    CN113726725A

  • DES encryption method

    CN117978365A

Cited By

  • Aquaculture production process full-cycle tracing management platform based on block chain

    CN120373669A

  • Program authorization method, system and equipment based on confusion encryption program key and medium

    CN120498636A