Data encryption method and device
By converting hexadecimal data and random numbers into decimal position numbers, performing data segmentation and cycle mark encryption, the problems of high key maintenance cost and large calculation amount in the existing technology are solved, and efficient and secure data are achieved. encryption process.
Patent Information
- Application Number
- CN202210312773.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-28
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2042-03-28
AI Technical Summary
The maintenance cost of the preset public and private keys in the existing technology is high and the encryption algorithm is computationally intensive, resulting in low efficiency of the data encryption process and difficulty in meeting the demand for increased data volume.
By obtaining hexadecimal data and eight-byte random numbers, converting them into decimal numbers for position numbering, segmenting the data according to bytes, and using the random numbers for loop marking and encryption, the target encrypted data is generated, avoiding the need for preset encryption. The use of keys reduces key maintenance costs and calculations.
This reduces key maintenance costs and encryption calculations without presetting public and private keys, and improves the security and efficiency of data encryption.
Smart Images

Figure CN114465712B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing, and in particular to a data encryption method and device. Background Art
[0002] During the data transmission process, the transmitted data is often encrypted. When the data is transmitted to the client, it is decrypted based on certain decryption principles to prevent data leakage and improve the security of data transmission. Currently, the encryption and decryption of data is mostly done by presetting public and private keys. The random number is encrypted with the public key in the preset key, and the encrypted value is sent to the server. The server decrypts the encrypted value with the private key in the preset key. However, this method requires the maintenance of the secret key, and when the amount of data to be encrypted increases, the amount of calculation required for the encryption algorithm will also increase dramatically. Summary of the invention
[0003] Therefore, the technical problem to be solved by the present invention is to overcome the defects of high maintenance cost of preset public and private keys in the prior art, and excessive amount of encryption algorithm calculation caused by encryption algorithm using preset public and private keys, thereby providing a data encryption method and device.
[0004] According to a first aspect, an embodiment of the present invention provides a data encryption method, the method comprising:
[0005] Obtaining data to be encrypted and a random number, wherein the data to be encrypted is hexadecimal data, and the random number is an eight-byte hexadecimal random number;
[0006] Convert the random number into a decimal number in sequence according to the bytes, and use the unit digit value of the decimal number corresponding to each byte random number to number the position of the byte random number;
[0007] Dividing the data to be encrypted into groups of eight bytes to obtain a plurality of sub-data to be encrypted;
[0008] Using each byte random number in the random number in turn to cyclically mark each sub-data to be encrypted;
[0009] Each sub-data to be encrypted is encrypted in sequence using the random number marked by each sub-data to be encrypted and the position number corresponding to the marked random number to generate target encrypted data.
[0010] Optionally, the step of sequentially encrypting each sub-data to be encrypted by using the random number marked by each sub-data to be encrypted and the position number corresponding to the marked random number includes:
[0011] Get the current position number corresponding to the random number marked by the sub-data to be encrypted;
[0012] Based on the current position number, determining the position to be encrypted in the current sub-data to be encrypted;
[0013] The data at the position to be encrypted is encrypted based on the random number marked by the current sub-data to be encrypted, so as to generate the encrypted data of the current encrypted sub-data.
[0014] Optionally, encrypting the data at the to-be-encrypted position based on the random number marked by the current to-be-encrypted sub-data to generate encrypted data of the current encrypted sub-data includes:
[0015] Encrypting the random number marked by the current sub-data to be encrypted and the data at the position to be encrypted according to a preset encryption rule to generate replacement data;
[0016] The data at the position to be encrypted is replaced by the replacement data to obtain the encrypted data of the current sub-data to be encrypted.
[0017] Optionally, determining the position to be encrypted in the current sub-data to be encrypted based on the current position number includes:
[0018] Determining whether the value of the position number is within the byte number range of the current sub-data to be encrypted;
[0019] When the value of the position number is within the byte number range of the current sub-data to be encrypted, the position corresponding to the value of the position number in the current sub-data to be encrypted is determined as the position to be encrypted.
[0020] Optionally, the determining the position to be encrypted in the current sub-data to be encrypted based on the current position number further includes:
[0021] When the value of the position number is 0, the initial position in the current sub-data to be encrypted is determined as the position to be encrypted in the current sub-data to be encrypted;
[0022] When the value of the position number is 9, the end position in the current sub-data to be encrypted is determined as the position to be encrypted in the current sub-data to be encrypted.
[0023] Optionally, the step of sequentially encrypting each sub-data to be encrypted using the random number marked by each sub-data to be encrypted and the position number corresponding to the marked random number to generate target encrypted data includes:
[0024] The encrypted data of each sub-data to be encrypted are concatenated in sequence to obtain the target encrypted data.
[0025] Optionally, obtaining the data to be encrypted and the random number includes:
[0026] Get the random number and the plaintext to be encrypted;
[0027] The plaintext is compressed to obtain the data to be encrypted corresponding to the plaintext.
[0028] According to a second aspect, an embodiment of the present invention provides a data encryption device, the device comprising:
[0029] An acquisition module, used for acquiring data to be encrypted and a random number, wherein the data to be encrypted is hexadecimal data, and the random number is an eight-byte hexadecimal random number;
[0030] A first processing module is used to convert the random number into a decimal number in sequence according to the bytes, and to position the byte random number using the unit digit value of the decimal number corresponding to each byte random number;
[0031] The second processing module is used to divide the data to be encrypted into groups of eight bytes to obtain a plurality of sub-data to be encrypted;
[0032] A third processing module is used to sequentially use each byte random number in the random number to cyclically mark each sub-data to be encrypted;
[0033] The encryption module is used to encrypt each sub-data to be encrypted in sequence by using the random number marked by each sub-data to be encrypted and the position number corresponding to the marked random number to generate target encrypted data.
[0034] According to a third aspect, an embodiment of the present invention provides an electronic device, including:
[0035] A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the method described in the first aspect or any optional implementation manner of the first aspect by executing the computer instructions.
[0036] According to a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable the computer to execute the method described in the first aspect or any optional implementation manner of the first aspect.
[0037] The technical solution of the present invention has the following advantages:
[0038] The data encryption method and device provided by the present invention obtain data to be encrypted and a random number, wherein the data to be encrypted is hexadecimal data, and the random number is an eight-byte hexadecimal random number; the random number is converted into a decimal number in sequence according to bytes, and the position of the byte random number is numbered according to the unit digit value of the decimal number corresponding to each byte random number; the data to be encrypted is divided into groups of eight bytes to obtain a plurality of sub-data to be encrypted; each byte random number in the random number is used in sequence to cyclically mark each sub-data to be encrypted; each sub-data to be encrypted is encrypted in sequence using the random number marked by each sub-data to be encrypted and the position number corresponding to the marked random number to generate target encrypted data. By converting the random number into a base, and then using the decimal digit value corresponding to each byte of the random number to number the random number, the random number is used to encrypt each sub-data to be encrypted in the encrypted data, and finally the target encrypted data is generated. By utilizing the randomness of the random number and the position number of the random number, the encrypted data is encrypted, without the need to preset public and private keys, which greatly reduces the key maintenance cost, it also reduces the amount of calculation in the encryption process and improves the security of data encryption. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0040] Figure 1 is a flow chart of a data encryption method according to an embodiment of the present invention;
[0041] Figure 2 is an operation flow chart of the data encryption method according to an embodiment of the present invention;
[0042] Figure 3 A schematic diagram of the structure of a data encryption device according to an embodiment of the present invention;
[0043] Figure 4 The figure is a schematic diagram of the structure of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0044] The technical solution of the present invention will be described clearly and completely below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0045] In the description of the present invention, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc., indicating the orientation or positional relationship, are based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as limiting the present invention. In addition, the terms "first", "second", and "third" are used for descriptive purposes only, and cannot be understood as indicating or implying relative importance.
[0046] In the description of the present invention, it should be noted that, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, it can also be the internal connection of two components, it can be a wireless connection, or it can be a wired connection. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0047] In addition, the technical features involved in the different embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.
[0048] The embodiment of the present invention provides a data encryption method, such as Figure 1 As shown, the data encryption method specifically includes the following steps:
[0049] Step S101: Obtain data to be encrypted and a random number, where the data to be encrypted is hexadecimal data and the random number is an eight-byte hexadecimal random number.
[0050] Specifically, in practical applications, there are many encryption algorithms for data transmission of energy storage systems, such as MD5 encryption algorithm, DES encryption algorithm, 3DES encryption algorithm, RSA encryption algorithm, DSA encryption algorithm, AES encryption algorithm, etc. However, most of these algorithms encrypt data based on public-private key pairs. For example, the AES algorithm has the advantages of simplicity, parallel computing, and non-error transmission, but it has the disadvantage of not being able to hide the plaintext mode (for example, the encrypted outline of the image is still there), and it will affect the data transmission and encryption performance. The embodiment of the present invention adopts a lightweight algorithm to encrypt data with less computing power. Since a common encryption method is adopted, the cloud sends a random number to the edge computing gateway, and the edge computing gateway uses the random number to encrypt the data and upload it to the cloud platform. No additional operation is required, as long as the encryption method is mutually recognized, and no additional equipment or computing power is required. In addition, since the random number method does not require key management and issuance, the key maintenance cost is reduced.
[0051] Preferably, the transmission in the embodiment of the present invention is performed using the MQTT protocol. The MQTT protocol is called Message Queuing Telemetry Transport, which is a lightweight communication protocol based on the TCP / IP protocol.
[0052] The embodiment of the present invention fixes the number of bytes of the random number, thereby laying a foundation for subsequent encryption without increasing the length of the original data.
[0053] Step S102: converting the random number into a decimal number in sequence according to the bytes, and numbering the position of the byte random number using the unit digit value of the decimal number corresponding to each byte random number.
[0054] Specifically, in practical applications, the random number is converted from hexadecimal to decimal, and the random number is position numbered according to the unit digit value of the decimal random number, and the position numbers are 0-9, which are all integers.
[0055] Step S103: dividing the data to be encrypted into groups of eight bytes to obtain a number of sub-data to be encrypted.
[0056] Specifically, in practical applications, the data to be encrypted may contain a large amount of data. In order to improve the security of data encryption and speed up the encryption process, the embodiment of the present invention divides the data to be encrypted into groups of eight bytes, and finally obtains a number of sub-data to be encrypted.
[0057] Step S104: cyclically marking each sub-data to be encrypted by using each byte random number in the random number in turn.
[0058] Specifically, in practical applications, the embodiment of the present invention adopts a method in which one byte of random number corresponds to one sub-data to be encrypted, and the sub-data to be encrypted is marked with the random number of the corresponding byte. After the eighth sub-data to be encrypted is marked with the random number of eight bytes, if there is still sub-data to be encrypted, the ninth sub-data to be encrypted is marked again with the random number of the first byte, and so on. In the embodiment of the present invention, one data to be encrypted corresponds to a group of eight-byte random numbers, and the sub-data to be encrypted in the data to be encrypted are cyclically marked with the same group of random numbers. Compared with the situation in which a group of sub-data to be encrypted corresponds to a group of random numbers, it not only reduces the number of times to obtain random numbers and improves the encryption efficiency, but also, because the length of the data to be encrypted is different, the size of the divided sub-data to be encrypted is also different, and the encryption security can still be guaranteed by using random numbers for cyclic marking.
[0059] Step S105: Encrypt each sub-data to be encrypted in sequence using the random number marked by each sub-data to be encrypted and the position number corresponding to the marked random number to generate target encrypted data.
[0060] Specifically, in practical applications, the encryption position of each sub-data to be encrypted can be determined according to the position number corresponding to the marked random number, and the encryption of the sub-data to be encrypted can be completed by encrypting the data at the encryption position using the marked random number, and finally the target encrypted data can be obtained.
[0061] Preferably, the embodiment of the present invention adopts an XOR operation to encrypt the sub-data to be encrypted, thereby reducing the computational difficulty of developing and using the encryption algorithm.
[0062] Specifically, in actual applications, when the user performs decryption, the decryption operation of the encrypted data can be achieved according to the random number and encryption principle. Since the encryption principle is formulated by the program developer, it improves the decryption speed and simplifies the decryption process. At the same time, it avoids the leakage of the encryption and decryption method due to improper storage of the preset key, thereby ensuring the security of the data.
[0063] The data encryption method provided by the embodiment of the present invention performs encrypted communication by using random number interaction. The user obtains random numbers based on the client and modifies the data according to the specific data information and encryption rules of the random numbers. While reducing the complexity of encryption, the dependence on key pairs in encryption is eliminated. In addition, since the data encryption method provided by the embodiment of the present invention does not increase the length of the original data, the cost of data collection and encryption is reduced. By encrypting only based on random numbers, there is no need to use key pairs. Each encryption process is unique and difficult to crack.
[0064] Specifically, in one embodiment, the above step S101 specifically includes the following steps:
[0065] Step S201: Obtain a random number and a plaintext to be encrypted.
[0066] Step S202: compress the plaintext to obtain the data to be encrypted corresponding to the plaintext.
[0067] Specifically, in practical applications, the plaintext to be encrypted consists of a string. If the plaintext to be encrypted is directly encrypted, the data encryption and transmission speed may be slow due to the large amount of plaintext data. The embodiment of the present invention greatly improves the encryption and transmission efficiency by first compressing the plaintext to be encrypted to greatly reduce the data volume, and then encrypting the compressed hexadecimal code stream.
[0068] Preferably, the embodiment of the present invention uses the gzip algorithm to compress the plaintext. By using the gzip algorithm for compression, the compression rate is high, and the volume of the plaintext data can be greatly reduced, which provides the necessary conditions for improving the encryption process in the future. In addition, the gzip algorithm can be used for compression, and it can be combined with the deep algorithm to generate a classification result table. When compressing the plaintext to be compressed, it can be screened through the classification result table. If the classification result table contains compressed data, the corresponding compressed code stream can be directly generated without repeating the compression process, which is of great significance to further improve the efficiency of compression encryption.
[0069] Specifically, before obtaining the random number and the plaintext to be encrypted, in order to ensure the security of the data, the embodiment of the present invention sets up login protection based on the MQTT platform, that is, the user needs to log in through the client using a user name and password. When the login verification is successful, the server will respond and transmit the random number to the client; when the login verification fails, the server will close the encryption process.
[0070] Specifically, in one embodiment, the above step S105 sequentially encrypts each sub-data to be encrypted using the random number marked by each sub-data to be encrypted and the position number corresponding to the marked random number, and specifically includes the following steps:
[0071] Step S301: Obtain the current position number corresponding to the random number marked by the sub-data to be encrypted.
[0072] Specifically, in practical applications, the random number adopted in the embodiment of the present invention is an eight-byte hexadecimal random number. When used for encryption, each byte of the random number is first converted from hexadecimal to decimal, and the position of each byte of the random number is numbered according to the decimal unit digit.
[0073] Step S302: Based on the current position number, determine the position to be encrypted in the current sub-data to be encrypted.
[0074] Step S303: Encrypt the data at the to-be-encrypted position based on the random number marked by the current to-be-encrypted sub-data to generate encrypted data of the current encrypted sub-data.
[0075] By determining the position to be encrypted in the sub-data to be encrypted according to the position number of the random number, and then encrypting the data at the position to be encrypted to obtain encrypted data, the embodiment of the present invention performs base conversion on the random number and uses the position number of the decimal digit to determine the position to be encrypted, and the position number of the random number also has a certain degree of randomness, thereby further improving the security of data encryption.
[0076] Specifically, in one embodiment, the above step S302 specifically includes the following steps:
[0077] Step S401: Determine whether the value of the position number is within the byte number range of the current sub-data to be encrypted.
[0078] Specifically, in actual applications, since the position number is an integer between 0-9, there may be a situation where the original length of the sub-data to be encrypted is exceeded during the encryption process. In order to avoid the situation where the encryption process increases the length of the sub-data to be encrypted, thereby reducing the encryption performance, the embodiment of the present invention first determines the value of the position number, adjusts the encryption process according to the determination result, and improves the speed of data encryption.
[0079] Step S402: When the value of the position number is within the byte number range of the current sub-data to be encrypted, the position corresponding to the value of the position number in the current sub-data to be encrypted is determined as the position to be encrypted.
[0080] Specifically, in actual applications, since the number of bytes of the sub-data to be encrypted is also eight bytes, there are eight positions to be encrypted in the eight-byte sub-data to be encrypted, corresponding to the position numbers 1-8 of the random numbers, that is, when the position number of the random number is 1, it corresponds to the first byte of the sub-data to be encrypted, and so on.
[0081] Specifically, in another embodiment, the above step S402 further includes the following steps:
[0082] Step S403: when the value of the position number is 0, the initial position in the current sub-data to be encrypted is determined as the position to be encrypted in the current sub-data to be encrypted.
[0083] Step S404: when the value of the position number is 9, the end position in the current sub-data to be encrypted is determined as the position to be encrypted in the current sub-data to be encrypted.
[0084] Specifically, in practical applications, the initial position in the embodiment of the present invention is the position after the first byte of data in the current sub-data to be encrypted; the end position is the position after the eighth byte of data in the current sub-data to be encrypted.
[0085] Specifically, in practical applications, as shown in Table 1, XX is the random number of the byte. When the position number of the random number is determined, the encryption position of the sub-data to be encrypted is also randomly determined. The embodiment of the present invention uses eight bytes of random numbers for encryption. When encrypting, each byte of the random number is converted from hexadecimal to decimal, and according to the position number of the decimal unit digit, the position number is a number from 0 to 9, and the data of the random number and the next (or previous) data of the position number are encrypted. The characters with shading are the processing method in the encryption process of the embodiment of the present invention. When it exceeds eight bytes, the random number of the byte is encrypted with the previous byte of the encrypted data, such as the last two lines of the list. In this way, the byte size of the transmitted data will not be increased, and the complexity of the algorithm is also relatively low.
[0086] Preferably, when the position number of the random number is 0, the initial position (first byte) of the sub-data to be encrypted is the encryption position in the sub-data to be encrypted; when the position number of the random number is 9, the end position (eighth byte) in the sub-data to be encrypted is the encryption position in the sub-data to be encrypted, but the actual situation is not limited to this. The change of the encryption position to ensure the high efficiency of data encryption is within the protection scope of the data encryption method provided by the embodiment.
[0087] Table 1 Correspondence between random number position number and encryption position
[0088] Units digit of the 8 - byte random number Original text Encryption method 0 FF FF FF FF FF FF FF FF XX FF FF FF FF FF FF FF FF 1 FF FF FF FF FF FF FF FF FF XX FF FF FF FF FF FF FF 2 FF FF FF FF FF FF FF FF FF FF XX FF FF FF FF FF FF 3 FF FF FF FF FF FF FF FF FF FF FF XX FF FF FF FF FF 4 FF FF FF FF FF FF FF FF FF FF FF FF XX FF FF FF FF 5 FF FF FF FF FF FF FF FF FF FF FF FF FF XX FF FF FF 6 FF FF FF FF FF FF FF FF FF FF FF FF FF FF XX FF FF 7 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF XX FF 8 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF XX FF 9 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF XX FF
[0089] Specifically, in one embodiment, the above step S303 encrypts the data at the to-be-encrypted position based on the random number marked by the current to-be-encrypted sub-data to generate the encrypted data of the current encrypted sub-data, and specifically includes the following steps:
[0090] Step S501: encrypt the random number marked by the sub-data to be encrypted and the data at the position to be encrypted according to a preset encryption rule to generate replacement data.
[0091] Step S502: Replace the data at the position to be encrypted with the replacement data to obtain the encrypted data of the current sub-data to be encrypted.
[0092] Exemplarily, in combination with what is shown in Table 1, when the unit digit of the random number is 3, that is, the position after the third byte data in the sub-data to be encrypted is encrypted, the third byte random number and the fourth byte data in the sub-data to be encrypted are encrypted according to a preset encryption rule, and the replacement data corresponding to the fourth byte data in the sub-data to be encrypted can be obtained, and the encrypted data of the sub-data to be encrypted can be obtained by replacing the fourth byte data in the sub-data to be encrypted with the replacement data.
[0093] Preferably, the embodiment of the present invention uses an XOR operation to encrypt the data to be encrypted, but the actual situation is not limited to this. Changes to the encryption operation method to ensure the security of data encryption are also within the protection scope of the data encryption method provided by the embodiment of the present invention.
[0094] Specifically, in one embodiment, the above step S105 generates target encrypted data, which specifically includes the following steps:
[0095] Step S601: sequentially concatenate the encrypted data of each sub-data to be encrypted to obtain target encrypted data.
[0096] Specifically, in practical applications, the encrypted data of each sub-data to be encrypted are concatenated to obtain target encrypted data corresponding to the data to be encrypted.
[0097] The embodiment of the present invention uses a compression algorithm and an encryption algorithm to compress and then encrypt data, which can solve the following problems:
[0098] 1) Based on the lightweight algorithm, the embodiment of the present invention adopts a common encryption method. The cloud sends a random number to the edge computing gateway, and the edge computing gateway uses the random number to encrypt the data and upload it to the cloud platform. No additional operation is required. As long as the encryption method is mutually recognized, no additional equipment or computing power is required.
[0099] 2) Based on the universality of the encryption method, the data encryption method provided by the embodiment of the present invention requires less memory and CPU usage, thereby improving the encryption and decryption performance of the algorithm;
[0100] 3) Based on the random number encryption method, the embodiment of the present invention does not require key management and distribution, thereby reducing the key maintenance cost.
[0101] Exemplarily, the embodiment of the present invention uses the random number 33DDC599F673F0FB to encrypt the data to be encrypted after being compressed by gzip. The encryption process is shown in Table 2, and the original data is the sub-data to be encrypted.
[0102] Table 2 Comparison of data before and after encryption
[0103] Original data Units digit of the random number Random number Byte to be encrypted Encrypted data 7b 22 6d 65 73 73 61 67 1 33 22 7b 11 6d 65 73 73 61 67 65 73 22 3a 5b 7b 22 74 1 DD 73 65ae 22 3a 5b 7b 22 74 6d 73 64 61 74 61 76 32 7 C5 32 6d 73 64 61 74 61 76f7 22 2c 22 70 61 72 74 69 3 99 70 22 2c 22e9 61 72 74 69 74 69 6f 6e 22 3a 30 2c 6 F6 30 74 69 6f 6e 22 3a c6 2c 22 76 61 6c 75 65 22 3a 5 73 65 22 76 61 6c 75 16 22 3a 22 5b 7b 22 73 6e 22 3a 0 F0 22 d2 5b 7b 22 73 6e 22 3a 20 22 32 2d 32 33 33 30 1 FB 22 20d9 32 2d 32 33 33 30 ... 1 33 ... ... ... 1 DD ... ...
[0104] When the first sub-data to be encrypted in the data to be encrypted is "7b 22 6d 65 73 73 61 67", according to the value of the unit digit of the random number being 1, it is determined that "22" in the first sub-data to be encrypted will be encrypted, and the random number "33" and the "22" in the first sub-data to be encrypted are XORed to obtain the encrypted data "11", and the original "22" is replaced by "11" to obtain the encrypted data "7b 11 6d 65 73 73 61 67" of the first sub-data to be encrypted. When there is still sub-data to be encrypted after the eighth sub-data to be encrypted is processed (such as the last two rows in the list), the ninth sub-data to be encrypted will be encrypted based on the first byte "33" of the random number, and the tenth sub-data to be encrypted will be encrypted based on the second byte "DD" of the random number, and so on. The encryption process of other sub-data to be encrypted is the same as this process and will not be repeated here. This approach is usually used to reduce the complexity of the algorithm without increasing the byte size of the transmitted data.
[0105] By executing the above steps, the data encryption method provided by the embodiment of the present invention obtains the data to be encrypted and the random number, wherein the data to be encrypted is hexadecimal data, and the random number is an eight-byte hexadecimal random number; converts the random number into a decimal number in sequence according to the bytes, and uses the unit digit value of the decimal number corresponding to each byte random number to positionally number the byte random number; divides the data to be encrypted into groups of eight bytes to obtain a plurality of sub-data to be encrypted; uses each byte random number in the random number to cyclically mark each sub-data to be encrypted in sequence; uses the random number marked by each sub-data to be encrypted and the position number corresponding to the marked random number to encrypt each sub-data to be encrypted in sequence to generate target encrypted data. By converting the random number into a base, and then using the decimal digit value corresponding to each byte of the random number to number the random number, the random number is used to encrypt each sub-data to be encrypted in the encrypted data, and finally the target encrypted data is generated. By utilizing the randomness of the random number and the position number of the random number, the encrypted data is encrypted, without the need to preset public and private keys, which greatly reduces the key maintenance cost, it also reduces the amount of calculation in the encryption process and improves the security of data encryption.
[0106] The data encryption method provided by the embodiment of the present invention will be described in detail below with reference to specific application examples.
[0107] Combination Figure 1 and Figure 2As shown in the figure, after the user logs in to the MQTT platform, the server responds to the client and transmits an eight-byte random number. After the client receives the random number, it compresses and encrypts the data, and then returns the encrypted result to the server. After receiving the result, the server responds to the client again according to the preset sending frequency, transmitting a new eight-byte random number. The client uses the new random number to compress and encrypt the new data to be sent, and then sends it to the server. This is repeated to perform encrypted data communication. When a login error occurs, the server will no longer send a random number to ensure the security of the overall data system.
[0108] The embodiment of the present invention provides a data encryption device, such as Figure 3 As shown, the data encryption device comprises:
[0109] The acquisition module 101 is used to acquire the data to be encrypted and the random number, wherein the data to be encrypted is hexadecimal data and the random number is an eight-byte hexadecimal random number. For details, please refer to the relevant description of step S101 in the above method embodiment, which will not be repeated here.
[0110] The first processing module 102 is used to convert the random number into a decimal number in sequence according to the bytes, and use the unit digit value of the decimal number corresponding to each byte random number to position the byte random number. For details, please refer to the relevant description of step S102 in the above method embodiment, which will not be repeated here.
[0111] The second processing module 103 is used to divide the data to be encrypted into groups of eight bytes to obtain a number of sub-data to be encrypted. For details, please refer to the relevant description of step S103 in the above method embodiment, which will not be repeated here.
[0112] The third processing module 104 is used to sequentially use each byte random number in the random number to cyclically mark each sub-data to be encrypted. For details, please refer to the relevant description of step S104 in the above method embodiment, which will not be repeated here.
[0113] The encryption module 105 is used to encrypt each sub-data to be encrypted in sequence using the random number marked by each sub-data to be encrypted and the position number corresponding to the marked random number to generate target encrypted data. For details, please refer to the relevant description of step S105 in the above method embodiment, which will not be repeated here.
[0114] For further description of the above-mentioned data encryption device, please refer to the relevant description of the above-mentioned data encryption method embodiment, which will not be repeated here.
[0115] Through the coordinated cooperation of the above-mentioned components, the data encryption device provided by the embodiment of the present invention converts the random number into a base, and then uses the units digit value of the decimal number corresponding to each byte of the random number to positionally number the random number, and uses the random number to encrypt each sub-data to be encrypted in the encrypted data, and finally generates the target encrypted data. By utilizing the randomness of the random number and the position number of the random number, the encrypted data is encrypted, which does not require the preset public and private keys, greatly reduces the key maintenance cost, and also reduces the amount of calculation in the encryption process, thereby improving the security of data encryption.
[0116] An embodiment of the present invention provides an electronic device, such as Figure 4 As shown, the electronic device includes a processor 901 and a memory 902, wherein the memory 902 and the processor 901 are connected to each other in a communication manner, wherein the processor 901 and the memory 902 may be connected via a bus or other means. Figure 4 The example of connecting through bus is taken in the following.
[0117] The processor 901 may be a central processing unit (CPU). The processor 901 may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or a combination of the above chips.
[0118] The memory 902 is a non-transitory computer-readable storage medium that can be used to store non-transitory software programs, non-transitory computer executable programs and modules, such as program instructions / modules corresponding to the method in the embodiment of the present invention. The processor 901 executes various functional applications and data processing of the processor 901 by running the non-transitory software programs, instructions and modules stored in the memory 902, that is, implements the method in the above method embodiment.
[0119] The memory 902 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required by at least one function; the data storage area may store data created by the processor 901, etc. In addition, the memory 902 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory 902 may optionally include a memory remotely arranged relative to the processor 901, and these remote memories may be connected to the processor 901 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0120] One or more modules are stored in the memory 902 , and when executed by the processor 901 , the method in the above method embodiment is executed.
[0121] The specific details of the above electronic device can be understood by referring to the corresponding descriptions and effects in the above method embodiments, and will not be repeated here.
[0122] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the implemented program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM), a random access memory (RAM), a flash memory, a hard disk drive (HDD) or a solid-state drive (SSD), etc.; the storage medium can also include a combination of the above-mentioned types of memory.
[0123] Obviously, the above embodiments are merely examples for the purpose of clear explanation, and are not intended to limit the implementation methods. For those skilled in the art, other different forms of changes or modifications can be made based on the above description. It is not necessary and impossible to list all the implementation methods here. The obvious changes or modifications derived therefrom are still within the scope of protection of the invention.
Claims
1. A data encryption method, It is characterized in that include: Obtaining data to be encrypted and a random number, wherein the data to be encrypted is hexadecimal data, and the random number is an eight-byte hexadecimal random number; Convert the random number into a decimal number in sequence according to the bytes, and use the unit digit value of the decimal number corresponding to each byte random number to number the position of the byte random number; Dividing the data to be encrypted into groups of eight bytes to obtain a plurality of sub-data to be encrypted; Using each byte random number in the random number in turn to cyclically mark each sub-data to be encrypted; Encrypt each sub-data to be encrypted in sequence using the random number marked by each sub-data to be encrypted and the position number corresponding to the marked random number to generate target encrypted data; The method of sequentially encrypting each sub-data to be encrypted by using the random number marked by each sub-data to be encrypted and the position number corresponding to the marked random number includes: Get the current position number corresponding to the random number marked by the sub-data to be encrypted; Based on the current position number, determining the position to be encrypted in the current sub-data to be encrypted; Encrypting the data at the to-be-encrypted position based on the random number marked by the current to-be-encrypted sub-data to generate encrypted data of the current to-be-encrypted sub-data; The step of encrypting the data at the position to be encrypted based on the random number marked by the sub-data to be encrypted to generate the encrypted data of the sub-data to be encrypted includes: Encrypting the random number marked by the current sub-data to be encrypted and the data at the position to be encrypted according to a preset encryption rule to generate replacement data; The data at the position to be encrypted is replaced by the replacement data to obtain the encrypted data of the current sub-data to be encrypted.
2. The method according to claim 1, It is characterized in that The step of determining the position to be encrypted in the current sub-data to be encrypted based on the current position number includes: Determine whether the value of the position number is within the byte number range of the current sub-data to be encrypted; When the value of the position number is within the byte number range of the current sub-data to be encrypted, the position corresponding to the value of the position number in the current sub-data to be encrypted is determined as the position to be encrypted.
3. The method according to claim 2, It is characterized in that The step of determining the position to be encrypted in the current sub-data to be encrypted based on the current position number further includes: When the value of the position number is 0, the initial position in the current sub-data to be encrypted is determined as the position to be encrypted in the current sub-data to be encrypted; When the value of the position number is 9, the end position in the current sub-data to be encrypted is determined as the position to be encrypted in the current sub-data to be encrypted.
4. The method according to claim 1, It is characterized in that The method of sequentially encrypting each sub-data to be encrypted using the random number marked by each sub-data to be encrypted and the position number corresponding to the marked random number to generate target encrypted data includes: The encrypted data of each sub-data to be encrypted are concatenated in sequence to obtain the target encrypted data.
5. The method according to claim 1, It is characterized in that The obtaining of the data to be encrypted and the random number includes: Get the random number and the plaintext to be encrypted; The plaintext is compressed to obtain the data to be encrypted corresponding to the plaintext.
6. A data encryption device, It is characterized in that include: An acquisition module, used for acquiring data to be encrypted and a random number, wherein the data to be encrypted is hexadecimal data, and the random number is an eight-byte hexadecimal random number; A first processing module is used to convert the random number into a decimal number in sequence according to the bytes, and to position the byte random number using the unit digit value of the decimal number corresponding to each byte random number; The second processing module is used to divide the data to be encrypted into groups of eight bytes to obtain a plurality of sub-data to be encrypted; A third processing module is used to sequentially use each byte random number in the random number to cyclically mark each sub-data to be encrypted; An encryption module, used to encrypt each sub-data to be encrypted in sequence by using the random number marked by each sub-data to be encrypted and the position number corresponding to the marked random number, to generate target encrypted data; The method of encrypting each sub-data to be encrypted in sequence by using the random number marked by each sub-data to be encrypted and the position number corresponding to the marked random number includes: obtaining the current position number corresponding to the random number marked by the current sub-data to be encrypted; determining the position to be encrypted in the current sub-data to be encrypted based on the current position number; encrypting the data at the position to be encrypted based on the random number marked by the current sub-data to be encrypted to generate the encrypted data of the current sub-data to be encrypted; the method of encrypting the data at the position to be encrypted based on the random number marked by the current sub-data to be encrypted to generate the encrypted data of the current sub-data to be encrypted includes: encrypting the random number marked by the current sub-data to be encrypted and the data at the position to be encrypted according to a preset encryption rule to generate replacement data; replacing the data at the position to be encrypted with the replacement data to obtain the encrypted data of the current sub-data to be encrypted.
7. An electronic device, It is characterized in that include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the method according to any one of claims 1 to 5 by executing the computer instructions.
8. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable the computer to execute the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Encryption and decryption method, encryption and decryption device and user terminal
CN108155985A
Long data encryption method and device based on RSA, computer device and storage medium
CN110071909A
