Method and device for generating and decrypting encrypted message, and electronic equipment
By using a combination of random keys and public keys for encryption between the client and server to generate and decrypt encrypted messages, the data security problem caused by communication key leakage is solved, achieving higher data security.
Patent Information
- Application Number
- CN202110336634.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-03-29
- Publication Date
- 2026-01-06
- Estimated Expiration
- 2041-03-29
AI Technical Summary
In existing technologies, the communication keys agreed upon by the client and server are at risk of being leaked, which could lead to the decryption of encrypted data and result in insufficient data security.
The message to be encrypted is encrypted using a random key to generate the first encrypted data. The random key is then encrypted using the public key to generate the second encrypted data. The two are then combined to form an encrypted message, which is then decrypted by the server using the private key.
It enhances the security of encrypted messages, prevents data leakage, and ensures the security of communication keys.
Smart Images

Figure CN112948867B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of cryptography technology, and more specifically, to a method, apparatus, and electronic device for generating and decrypting encrypted messages. Background Technology
[0002] Currently, many web application systems use symmetric encryption algorithms to encrypt sensitive data on the client side before transmission. The key to this approach is that the client and server agree on a communication key (symmetric key). The client encrypts the data to be encrypted and sends it to the server, and the server decrypts the data.
[0003] Since the client program is exposed, the agreed communication key is at risk of being leaked. Once the communication key is leaked, the encrypted data may be decrypted, resulting in data leakage. Therefore, data security urgently needs to be further strengthened. Summary of the Invention
[0004] The purpose of this application is to at least resolve one of the aforementioned technical deficiencies. The technical solution adopted in this application is as follows:
[0005] In a first aspect, embodiments of this application provide a method for generating encrypted messages, the method comprising:
[0006] The message to be encrypted is encrypted using a random key to obtain the first encrypted data.
[0007] The random key is encrypted using the public key to obtain the second encrypted data;
[0008] The first encrypted data and the second encrypted data are combined to obtain an encrypted message.
[0009] Optionally, the above method further includes:
[0010] The encrypted message is sent to the corresponding server so that the server can decrypt the encrypted message based on the private key corresponding to the public key.
[0011] Optionally, the first encrypted data and the second encrypted data may be combined, including any of the following:
[0012] Insert the entire first encrypted data into the second encrypted data, or insert the entire second encrypted data into the first encrypted data;
[0013] The first encrypted data is split into at least two first sub-data, and each first sub-data is inserted into the second encrypted data; or, the second encrypted data is split into at least two second sub-data, and each second sub-data is inserted into the first encrypted data.
[0014] Optionally, if combining the first encrypted data and the second encrypted data includes inserting the entire first encrypted data into the second encrypted data, then inserting the entire first encrypted data into the second encrypted data includes:
[0015] Insert the first encrypted data into the second encrypted data at the first specified character position;
[0016] If combining the first encrypted data and the second encrypted data includes inserting the entire second encrypted data into the first encrypted data, then inserting the entire second encrypted data into the first encrypted data includes:
[0017] Insert the second encrypted data into the second specified character position in the first encrypted data.
[0018] Optionally, if combining the first encrypted data and the second encrypted data includes inserting the first encrypted data into the second encrypted data at a first specified character position, then the above method further includes:
[0019] The first specified character position and the character length of the second encrypted data are sent to the server so that the server can split the encrypted message based on the first specified character position and the character length of the second encrypted data;
[0020] If combining the first encrypted data and the second encrypted data includes inserting the second encrypted data into the first encrypted data at a second specified character position, then the above method further includes:
[0021] The second specified character position and the character length of the first encrypted data are sent to the server so that the server can split the encrypted message based on the second specified character position and the character length of the first encrypted data.
[0022] Optionally, if combining the first encrypted data and the second encrypted data includes splitting the first encrypted data into at least two first sub-data and inserting each first sub-data into the second encrypted data, then inserting each first sub-data into the second encrypted data includes:
[0023] Determine the third specified character position of each first sub-data in the second encrypted data, and insert each first sub-data into the corresponding third character position;
[0024] If combining the first encrypted data and the second encrypted data includes splitting the second encrypted data into at least two second sub-data, and inserting each second sub-data into the first encrypted data, then inserting each second sub-data into the first encrypted data includes:
[0025] Determine the fourth specified character position of each second sub-data in the first encrypted data, and insert each second sub-data into the corresponding fourth character position.
[0026] Optionally, if combining the first encrypted data and the second encrypted data includes determining the third specified character position of each first sub-data in the second encrypted data, and inserting each first sub-data into the corresponding third character position, then the above method further includes:
[0027] The character length of each first sub-data and the third specified character position corresponding to each first sub-data are sent to the server so that the server can split the encrypted message based on the character length of each first sub-data and the third specified character position corresponding to each first sub-data.
[0028] If combining the first encrypted data and the second encrypted data includes determining the fourth specified character position of each of the two sub-data in the first encrypted data, and inserting each of the second sub-data into the corresponding fourth character position, then the above method further includes:
[0029] The character length of each second sub-data and the corresponding fourth specified character position are sent to the server so that the server can split the encrypted message based on the character length of each second sub-data and the corresponding fourth specified character position.
[0030] Optionally, the above method further includes:
[0031] Generate a random key corresponding to the message to be encrypted.
[0032] Secondly, embodiments of this application provide a method for decrypting encrypted messages, the method comprising:
[0033] When an encrypted message is received from a terminal device, the encrypted message is split to obtain the split message.
[0034] The split message is decrypted based on the private key.
[0035] Optionally, the split message includes first encrypted data and second encrypted data. The first encrypted data is obtained by encrypting the message to be encrypted based on a random key, and the second encrypted data is obtained by encrypting the random key based on the public key corresponding to the private key.
[0036] Optionally, the split message is decrypted based on the private key, including:
[0037] The random key is obtained by decrypting the second encrypted data using the private key.
[0038] The target message is obtained by decrypting the first encrypted data using a random key.
[0039] Optionally, the above method further includes:
[0040] The receiving terminal device sends any of the following:
[0041] The first specified character position and the character length of the second encrypted data;
[0042] The second specified character position and the character length of the first encrypted data;
[0043] The character length of each first sub-data and the position of the third specified character corresponding to each first sub-data;
[0044] The character length of each second sub-data and the position of the fourth specified character corresponding to each second sub-data;
[0045] If the terminal device sends the first specified character position and the character length of the second encrypted data, then the encrypted message is split, including:
[0046] The encrypted message is split based on the first specified character position and the character length of the second encrypted data, wherein the encrypted message is obtained by inserting the first encrypted data into the second encrypted data at the first specified character position;
[0047] If the terminal device sends the second specified character position and the character length of the first encrypted data, then the encrypted message is split, including:
[0048] The encrypted message is split based on the second specified character position and the character length of the first encrypted data, wherein the encrypted message is obtained by inserting the second encrypted data into the second specified character position of the first encrypted data;
[0049] If the character length of each first sub-data and the position of the third specified character corresponding to each first sub-data are received from the terminal device, then the encrypted message is split, including:
[0050] The encrypted message is split based on the character length of each first sub-data and the third specified character position corresponding to each first sub-data. The first sub-data is obtained by splitting the first encrypted data, and the encrypted message is obtained by inserting each first sub-data into the corresponding third character position in the second encrypted data.
[0051] If the character length of each second sub-data and the position of the fourth specified character corresponding to each second sub-data are received from the terminal device, then the encrypted message is split, including:
[0052] The encrypted message is split based on the character length of each second sub-data and the fourth specified character position corresponding to each second sub-data. The second sub-data is obtained by splitting the second encrypted data, and the encrypted message is obtained by inserting each second sub-data into the corresponding fourth character position in the first encrypted data.
[0053] Thirdly, embodiments of this application provide an apparatus for generating encrypted messages, the apparatus comprising:
[0054] The first encryption module is used to encrypt the message to be encrypted based on a random key to obtain the first encrypted data.
[0055] The second encryption module is used to encrypt the random key based on the public key to obtain the second encrypted data;
[0056] The combination module is used to combine the first encrypted data and the second encrypted data to obtain an encrypted message.
[0057] Optionally, the above-mentioned device further includes:
[0058] The message sending module is used to send encrypted messages to the corresponding server, so that the server can decrypt the encrypted messages based on the private key corresponding to the public key.
[0059] Optionally, when combining the first encrypted data and the second encrypted data, the combining module is specifically used for any of the following:
[0060] Insert the entire first encrypted data into the second encrypted data, or insert the entire second encrypted data into the first encrypted data;
[0061] The first encrypted data is split into at least two first sub-data, and each first sub-data is inserted into the second encrypted data; or, the second encrypted data is split into at least two second sub-data, and each second sub-data is inserted into the first encrypted data.
[0062] Optionally, if the combining module, when combining the first encrypted data and the second encrypted data, is specifically used to insert the first encrypted data as a whole into the second encrypted data, then the combining module, when inserting the first encrypted data as a whole into the second encrypted data, is specifically used to:
[0063] Insert the first encrypted data into the second encrypted data at the first specified character position;
[0064] If the combining module, when combining the first encrypted data and the second encrypted data, specifically inserts the entire second encrypted data into the first encrypted data, then the combining module, when inserting the entire second encrypted data into the first encrypted data, specifically performs the following:
[0065] Insert the second encrypted data into the second specified character position in the first encrypted data.
[0066] Optionally, if the combining module, when combining the first encrypted data and the second encrypted data, is specifically used to insert the first encrypted data into the second encrypted data at a first specified character position, then the above-mentioned device further includes:
[0067] The first data sending module is used to send the first specified character position and the character length of the second encrypted data to the server, so that the server can split the encrypted message based on the first specified character position and the character length of the second encrypted data;
[0068] Optionally, if the combining module, when combining the first encrypted data and the second encrypted data, is specifically used to insert the second encrypted data into the second specified character position in the first encrypted data, then the above-mentioned device further includes:
[0069] The first data sending module is used to send the second specified character position and the character length of the first encrypted data to the server, so that the server can split the encrypted message based on the second specified character position and the character length of the first encrypted data.
[0070] Optionally, if the combining module, when combining the first encrypted data and the second encrypted data, specifically splits the first encrypted data into at least two first sub-data and inserts each first sub-data into the second encrypted data, then the combining module, when inserting each first sub-data into the second encrypted data, specifically performs the following:
[0071] Determine the third specified character position of each first sub-data in the second encrypted data, and insert each first sub-data into the corresponding third character position;
[0072] If, when combining the first encrypted data and the second encrypted data, the combining module specifically splits the second encrypted data into at least two second sub-data, and inserts each second sub-data into the first encrypted data, then the combining module specifically inserts each second sub-data into the first encrypted data as follows:
[0073] Determine the fourth specified character position of each second sub-data in the first encrypted data, and insert each second sub-data into the corresponding fourth character position.
[0074] Optionally, if the combining module, when combining the first encrypted data and the second encrypted data, is specifically used to determine the third specified character position of each first sub-data in the second encrypted data, and insert each first sub-data into the corresponding third character position, then the above device further includes:
[0075] The third data sending module is used to send the character length of each first sub-data and the third specified character position corresponding to each first sub-data to the server, so that the server can split the encrypted message based on the character length of each first sub-data and the third specified character position corresponding to each first sub-data.
[0076] Optionally, if the combining module, when combining the first encrypted data and the second encrypted data, specifically determines the fourth specified character position of each of the two sub-data items in the first encrypted data and inserts each of the second sub-data items into the corresponding fourth character position, then the above-mentioned device further includes:
[0077] The fourth data sending module is used to send the character length of each second sub-data and the fourth specified character position corresponding to each second sub-data to the server, so that the server can split the encrypted message based on the character length of each second sub-data and the fourth specified character position corresponding to each second sub-data.
[0078] Optionally, the above-mentioned device further includes:
[0079] The key generation module is used to generate a random key corresponding to the message to be encrypted.
[0080] Fourthly, embodiments of this application provide a decryption device for encrypted messages, the device comprising:
[0081] The message splitting module is used to split the encrypted message upon receiving it from the terminal device, and obtain the split message.
[0082] The message decryption module is used to decrypt the split messages based on the private key.
[0083] Optionally, the split message includes first encrypted data and second encrypted data. The first encrypted data is obtained by encrypting the message to be encrypted based on a random key, and the second encrypted data is obtained by encrypting the random key based on the public key corresponding to the private key.
[0084] Optionally, the message decryption module is specifically used for:
[0085] The random key is obtained by decrypting the second encrypted data using the private key.
[0086] The target message is obtained by decrypting the first encrypted data using a random key.
[0087] Optionally, the above-mentioned device further includes: a data receiving module;
[0088] The data receiving module is used to receive any of the following sent by the terminal device:
[0089] The first specified character position and the character length of the second encrypted data;
[0090] The second specified character position and the character length of the first encrypted data;
[0091] The character length of each first sub-data and the position of the third specified character corresponding to each first sub-data;
[0092] The character length of each second sub-data and the position of the fourth specified character corresponding to each second sub-data;
[0093] If the terminal device sends the first specified character position and the character length of the second encrypted data, the message splitting module, when splitting the encrypted message, is specifically used for:
[0094] The encrypted message is split based on the first specified character position and the character length of the second encrypted data, wherein the encrypted message is obtained by inserting the first encrypted data into the second encrypted data at the first specified character position;
[0095] If the terminal device sends the second specified character position and the character length of the first encrypted data, the message splitting module, when splitting the encrypted message, is specifically used for:
[0096] The encrypted message is split based on the second specified character position and the character length of the first encrypted data, wherein the encrypted message is obtained by inserting the second encrypted data into the second specified character position of the first encrypted data;
[0097] If the terminal device sends the character length of each first sub-data and the third specified character position corresponding to each first sub-data, the message splitting module, when splitting the encrypted message, is specifically used for:
[0098] The encrypted message is split based on the character length of each first sub-data and the third specified character position corresponding to each first sub-data. The first sub-data is obtained by splitting the first encrypted data, and the encrypted message is obtained by inserting each first sub-data into the corresponding third character position in the second encrypted data.
[0099] If the terminal device sends the character length of each second sub-data and the fourth specified character position corresponding to each second sub-data, the message splitting module, when splitting the encrypted message, is specifically used for:
[0100] The encrypted message is split based on the character length of each second sub-data and the fourth specified character position corresponding to each second sub-data. The second sub-data is obtained by splitting the second encrypted data, and the encrypted message is obtained by inserting each second sub-data into the corresponding fourth character position in the first encrypted data.
[0101] Fifthly, embodiments of this application provide an electronic device, which includes: a processor and a memory;
[0102] Memory, used to store operation instructions;
[0103] A processor is configured to execute, by invoking operation instructions, the methods shown in any embodiment of the first aspect or any embodiment of the second aspect of this application.
[0104] In a sixth aspect, embodiments of this application provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the methods shown in any embodiment of the first aspect or any embodiment of the second aspect of this application.
[0105] The beneficial effects of the technical solutions provided in this application are:
[0106] The scheme provided in this application encrypts the message to be encrypted using a random key to obtain first encrypted data, and then encrypts the random key using a public key to obtain second encrypted data. The first and second encrypted data are then combined to obtain an encrypted message. In this scheme, because encryption is based on a random key and a public key, and the encrypted message is obtained by combining the encrypted data, the security of the encrypted message is improved, and data leakage is avoided. Attached Figure Description
[0107] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments of this application will be briefly introduced below.
[0108] Figure 1 A flowchart illustrating a method for generating encrypted messages provided in an embodiment of this application;
[0109] Figure 2 A flowchart illustrating a method for decrypting encrypted messages provided in an embodiment of this application;
[0110] Figure 3 A flowchart illustrating a method for generating and decrypting encrypted messages provided in an embodiment of this application;
[0111] Figure 4 A schematic diagram of the structure of an encrypted message generation device provided in an embodiment of this application;
[0112] Figure 5 A schematic diagram of the structure of a decryption device for encrypted messages provided in an embodiment of this application;
[0113] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0114] The embodiments of this application are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain this application, and should not be construed as limiting the invention.
[0115] Those skilled in the art will understand that, unless specifically stated otherwise, the singular forms “a,” “an,” “the,” and “the” used herein may also include the plural forms. It should be further understood that the term “comprising” as used in this application means the presence of the stated features, integers, steps, operations, elements, and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof. It should be understood that when we say an element is “connected” or “coupled” to another element, it can be directly connected or coupled to the other element, or there may be intermediate elements. Furthermore, “connected” or “coupled” as used herein can include wireless connections or wireless coupling. The term “and / or” as used herein includes all or any units and all combinations of one or more associated listed items.
[0116] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.
[0117] Asymmetric encryption, also known as asymmetric encryption algorithms, requires two keys: a public key and a private key. The public and private keys are a pair; if data is encrypted using the public key, it can only be decrypted using the corresponding private key. Because encryption and decryption use two different keys, this type of algorithm is called an asymmetric encryption algorithm.
[0118] Symmetric encryption: An encryption algorithm that requires the same key to be used for both encryption and decryption. Due to its speed, symmetric encryption is typically used when the message sender needs to encrypt large amounts of data. Symmetric encryption is also known as keyed encryption. The term "symmetric" means that both parties using this encryption method use the same key for both encryption and decryption. The key is the instruction that controls the encryption and decryption process. The algorithm is a set of rules that specifies how to perform encryption and decryption.
[0119] National Cryptographic Algorithms: A series of algorithms standardized by the State Cryptography Administration. These include symmetric encryption algorithms, elliptic curve asymmetric encryption algorithms, and hash algorithms. Specifically, they include SM1, SM2, SM3, and SM4, among others.
[0120] SM1 is a symmetric encryption algorithm with a 128-bit encryption strength, implemented in hardware.
[0121] SM2 is a public-key algorithm (asymmetric encryption algorithm) published by the State Cryptography Administration, with an encryption strength of 256 bits.
[0122] SM3 is a cryptographic hash algorithm with a hash value length of 32 bytes. It was released at the same time as the SM2 algorithm.
[0123] SMS4 is a symmetric encryption algorithm that was released with the WAPI standard. It can be implemented in software and has a encryption strength of 128 bits.
[0124] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will now be described with reference to the accompanying drawings.
[0125] Figure 1 The diagram illustrates a flowchart of a method for generating encrypted messages according to an embodiment of this application. Figure 1 As shown, this method mainly includes:
[0126] Step S110: Encrypt the message to be encrypted using a random key to obtain the first encrypted data;
[0127] Step S120: Encrypt the random key based on the public key to obtain the second encrypted data;
[0128] Step S130: Combine the first encrypted data and the second encrypted data to obtain an encrypted message.
[0129] In this embodiment of the application, the random key can be a communication key generated by the national cryptographic symmetric encryption algorithm SM4, and a corresponding random key can be generated each time a communication message is encrypted.
[0130] In this embodiment of the application, an asymmetric national cryptographic SM2 key pair can be pre-generated. The public key in the key pair can be embedded into the client's JavaScript SDK package through obfuscation encryption, and the private key in the key pair can be stored in the encryption machine on the server side.
[0131] In this embodiment of the application, the message to be encrypted can be encrypted using a random key to obtain first encrypted data, and the random key can be encrypted using a public key to obtain second encrypted data. Then, the first encrypted data and the second encrypted data can be combined to obtain an encrypted message.
[0132] In the encrypted message, the first encrypted data is obtained by encrypting the message to be encrypted using a random key, and the second encrypted data is obtained by encrypting the random key using a public key. Since the private key corresponding to the public key is generally stored on the server and is not easily lost, encrypting the random key with the public key ensures the security of the random key and prevents its loss, thereby guaranteeing the security of the message. Furthermore, because the encrypted message is obtained by combining the first and second encrypted data, a third party cannot decompose the encrypted message and therefore cannot decrypt it if they do not know how the first and second encrypted data are combined.
[0133] The method provided in this application encrypts the message to be encrypted using a random key to obtain first encrypted data, and then encrypts the random key using a public key to obtain second encrypted data. The first and second encrypted data are then combined to obtain an encrypted message. In this solution, because encryption is based on a random key and a public key, and the encrypted message is obtained by combining the encrypted data, the security of the encrypted message is improved, and data leakage is avoided.
[0134] In one optional embodiment of this application, the above method further includes:
[0135] The encrypted message is sent to the corresponding server so that the server can decrypt the encrypted message based on the private key corresponding to the public key.
[0136] In this embodiment of the application, after generating the encrypted message, the encrypted message can be sent to the corresponding server. After receiving the encrypted message, the server can decrypt the encrypted message to obtain the message data.
[0137] In one optional embodiment of this application, the first encrypted data is inserted entirely into the second encrypted data, or the second encrypted data is inserted entirely into the first encrypted data;
[0138] The first encrypted data is split into at least two first sub-data, and each first sub-data is inserted into the second encrypted data; or, the second encrypted data is split into at least two second sub-data, and each second sub-data is inserted into the first encrypted data.
[0139] In this embodiment of the application, when assembling the encrypted message, one of the first encrypted data and the second encrypted data can be inserted as a whole into the other to obtain the encrypted message. Alternatively, one of the first encrypted data and the second encrypted data can be split first, and the resulting sub-data can be inserted into the unsplit data respectively.
[0140] In one optional embodiment of this application, combining the first encrypted data and the second encrypted data includes inserting the entire first encrypted data into the second encrypted data. Inserting the entire first encrypted data into the second encrypted data includes:
[0141] Insert the first encrypted data into the second encrypted data at the first specified character position;
[0142] If combining the first encrypted data and the second encrypted data includes inserting the entire second encrypted data into the first encrypted data, then inserting the entire second encrypted data into the first encrypted data includes:
[0143] Insert the second encrypted data into the second specified character position in the first encrypted data.
[0144] In this embodiment of the application, when inserting the first encrypted data into the second encrypted data as a whole, the insertion position can be specified in the second encrypted data, that is, the first specified character position. For example, it can be the Nth character in the forward order or the Nth character in the reverse order of the second encrypted data.
[0145] Accordingly, when inserting the second encrypted data into the first encrypted data as a whole, the insertion position can be specified in the first encrypted data, that is, the second specified character position. For example, it can be the Mth character in the forward order or the Mth character in the reverse order of the first encrypted data.
[0146] In an optional embodiment of this application, if combining the first encrypted data and the second encrypted data includes inserting the first encrypted data into a first specified character position in the second encrypted data, then the above method further includes:
[0147] The first specified character position and the character length of the second encrypted data are sent to the server so that the server can split the encrypted message based on the first specified character position and the character length of the second encrypted data;
[0148] If combining the first encrypted data and the second encrypted data includes inserting the second encrypted data into the first encrypted data at a second specified character position, then the above method further includes:
[0149] The second specified character position and the character length of the first encrypted data are sent to the server so that the server can split the encrypted message based on the second specified character position and the character length of the first encrypted data.
[0150] In this embodiment of the application, when the method of combining encrypted messages is to insert the first encrypted data into the first specified character position of the second encrypted data, the first specified character position and the character length of the second encrypted data can be sent to the server. The server can extract the character length of the second encrypted data from the encrypted message starting from the first specified character position. The extracted data is the second encrypted data. The remaining data in the encrypted message can be concatenated at the first specified character position to obtain the first encrypted data.
[0151] Accordingly, when the method of combining encrypted messages is to insert the second encrypted data into the second specified character position of the first encrypted data, the first specified character position and the character length of the second encrypted data can be sent to the server. The server can extract the character length of the first encrypted data from the encrypted message starting from the second specified character position. The extracted data is the first encrypted data. The remaining data in the encrypted message can be concatenated at the second specified character position to obtain the second encrypted data.
[0152] In one optional embodiment of this application, if combining the first encrypted data and the second encrypted data includes splitting the first encrypted data into at least two first sub-data and inserting each first sub-data into the second encrypted data, then inserting each first sub-data into the second encrypted data includes:
[0153] Determine the third specified character position of each first sub-data in the second encrypted data, and insert each first sub-data into the corresponding third character position;
[0154] If combining the first encrypted data and the second encrypted data includes splitting the second encrypted data into at least two second sub-data, and inserting each second sub-data into the first encrypted data, then inserting each second sub-data into the first encrypted data includes:
[0155] Determine the fourth specified character position of each second sub-data in the first encrypted data, and insert each second sub-data into the corresponding fourth character position.
[0156] In this embodiment of the application, the method of combining encrypted messages can be to split the first encrypted data to obtain at least two first sub-data, and then insert each first sub-data into the second encrypted data to obtain encrypted messages.
[0157] As an example, the first encrypted data can be split by specifying the number of first sub-data, such as specifying the number of first sub-data as a1, and splitting the first encrypted data into a1 first sub-data of equal character length; or the first encrypted data can be split by specifying the character length of each first sub-data, such as specifying the character length of each first sub-data as b1, b2, b3 and b4 respectively, and the sum of the character lengths of each first sub-data equals the character length of the first encrypted data. Then, according to the character order of the first sub-data, the characters in the first b1 positions, the characters from the b1+1 position to the b2 position, the characters from the b1+b2+1 position to the b3 position, and the characters from the b1+b2+b3+1 position to the b4 position can be extracted as the first sub-data respectively.
[0158] As an example, each character position can be numbered according to the character order of the second encrypted data, and then the third specified character position of each first sub-data in the second encrypted data can be specified by specifying the number.
[0159] Accordingly, the method of combining encrypted messages can be to split the second encrypted data to obtain at least two second sub-data, and then insert each second sub-data into the first encrypted data to obtain the encrypted message.
[0160] As an example, the first encrypted data can be split by specifying the number of second sub-data, such as specifying the number of second sub-data as a2, and splitting the second encrypted data into first sub-data of equal character length a2; or the first encrypted data can be split by specifying the character length of each first sub-data, such as specifying the character length of each first sub-data as c1, c2, c3 and c4 respectively, and the sum of the character lengths of each first sub-data is equal to the character length of the first encrypted data. Then, according to the character order of the first sub-data, the characters in the first c1 positions, the characters in the c2 positions starting from the c1+1 position, the characters in the c3 positions starting from the c1+c2+1 position, and the characters in the c4 positions starting from the c1+c2+c3+1 position can be extracted as the first sub-data respectively.
[0161] As an example, each character position can be numbered according to the character order of the first encrypted data, and then the third specified character position of each second sub-data in the first encrypted data can be specified by specifying the number.
[0162] In an optional embodiment of this application, if combining the first encrypted data and the second encrypted data includes determining a third specified character position for each first sub-data in the second encrypted data, and inserting each first sub-data into the corresponding third character position, then the above method further includes:
[0163] The character length of each first sub-data and the third specified character position corresponding to each first sub-data are sent to the server so that the server can split the encrypted message based on the character length of each first sub-data and the third specified character position corresponding to each first sub-data.
[0164] If combining the first encrypted data and the second encrypted data includes determining the fourth specified character position of each of the two sub-data in the first encrypted data, and inserting each of the second sub-data into the corresponding fourth character position, then the above method further includes:
[0165] The character length of each second sub-data and the corresponding fourth specified character position are sent to the server so that the server can split the encrypted message based on the character length of each second sub-data and the corresponding fourth specified character position.
[0166] In this embodiment of the application, when the method of combining encrypted messages is to determine the third specified character position of each first sub-data in the second encrypted data and insert each first sub-data into the corresponding third character position, the character length of each first sub-data and the third specified character position corresponding to each first sub-data can be sent to the server. The server can extract the data corresponding to the character length of each first sub-data from the encrypted message starting from the third specified character position corresponding to each first sub-data, thereby extracting each first sub-data. Then, the first sub-data are combined according to the splitting method to obtain the first encrypted data. The remaining data in the encrypted message are concatenated at each third specified character position to obtain the second encrypted data.
[0167] Accordingly, when the method of combining encrypted messages is to determine the fourth specified character position of each second sub-data in the first encrypted data and insert each second sub-data into the corresponding fourth character position, the character length of each second sub-data and the fourth specified character position of each second sub-data can be sent to the server. The server can extract the data corresponding to the character length of each second sub-data from the encrypted message starting from the fourth specified character position of each second sub-data, thereby extracting each second sub-data. Then, according to the splitting method, the second sub-data are combined to obtain the second encrypted data. The remaining data in the encrypted message are concatenated at each fourth specified character position to obtain the first encrypted data.
[0168] As an example, one possible approach is to split the second encrypted data into a second sub-data of length 1 character, and then extract a string from the first encrypted data such that its length is one character longer than the second encrypted data. The fourth specified character positions are located between adjacent characters in this sub-string, meaning that characters from the second encrypted data are inserted sequentially between adjacent characters in the sub-string, following the character order of the second encrypted data. In practical use, the length of the second encrypted data string may not be less than the length of the first encrypted data string. In this case, padding can be added after the end of the first encrypted data. The string extracted from the padded first encrypted data is then made so that its length is one character longer than the second encrypted data string. When the server splits the encrypted message, the padded data in the string can be deleted.
[0169] In practical use, different combinations of encrypted message methods can be configured for different business channels.
[0170] In one optional embodiment of this application, the above method further includes:
[0171] Generate a random key corresponding to the message to be encrypted.
[0172] In this embodiment of the application, a random key can be generated before each message to be encrypted, so that each message to be encrypted corresponds to a random key.
[0173] Figure 2 The diagram illustrates a flowchart of a method for decrypting encrypted messages according to an embodiment of this application. Figure 2 As shown, this method mainly includes:
[0174] Step S210: When an encrypted message is received from a terminal device, the encrypted message is split to obtain a split message;
[0175] Step S220: Decrypt the split message based on the private key.
[0176] In this embodiment of the application, when the terminal device generates an encrypted message, it can encrypt the message to be encrypted using a random key to obtain first encrypted data, encrypt the random key using a public key to obtain second encrypted data, and then combine the first encrypted data and the second encrypted data to obtain an encrypted message.
[0177] In this embodiment of the application, when the server receives an encrypted message sent by the terminal device, it can split the encrypted message to obtain a split message, and then decrypt the split message according to the private key.
[0178] In the encrypted message, the first encrypted data is obtained by encrypting the message to be encrypted using a random key, and the second encrypted data is obtained by encrypting the random key using a public key. Since the private key corresponding to the public key is generally stored on the server and is not easily lost, encrypting the random key with the public key ensures the security of the random key and prevents its loss, thereby guaranteeing the security of the message. Furthermore, because the encrypted message is obtained by combining the first and second encrypted data, it cannot be disassembled or decrypted by a third party who does not know the combination method.
[0179] The method provided in this application, upon receiving an encrypted message from a terminal device, splits the encrypted message into a split message, and then decrypts the split message using a private key. This solution improves the security of the encrypted message and effectively prevents data leakage by first splitting the encrypted message and then decrypting it using the private key.
[0180] In one optional embodiment of this application, the split message includes first encrypted data and second encrypted data. The first encrypted data is obtained by encrypting the message to be encrypted based on a random key, and the second encrypted data is obtained by encrypting the random key based on the public key corresponding to the private key.
[0181] In one optional embodiment of this application, decrypting the split message based on the private key includes:
[0182] The random key is obtained by decrypting the second encrypted data using the private key.
[0183] The target message is obtained by decrypting the first encrypted data using a random key.
[0184] In this embodiment of the application, after the server splits the encrypted message into first encrypted data and second encrypted data, it can first decrypt the second encrypted data with the private key to obtain a random key, and then decrypt the first encrypted data with the random key to obtain the target message, i.e., the original message.
[0185] In one optional embodiment of this application, the above method further includes:
[0186] The receiving terminal device sends any of the following:
[0187] The first specified character position and the character length of the second encrypted data;
[0188] The second specified character position and the character length of the first encrypted data;
[0189] The character length of each first sub-data and the position of the third specified character corresponding to each first sub-data;
[0190] The character length of each second sub-data and the position of the fourth specified character corresponding to each second sub-data;
[0191] If the terminal device sends the first specified character position and the character length of the second encrypted data, then the encrypted message is split, including:
[0192] The encrypted message is split based on the first specified character position and the character length of the second encrypted data, wherein the encrypted message is obtained by inserting the first encrypted data into the second encrypted data at the first specified character position;
[0193] If the terminal device sends the second specified character position and the character length of the first encrypted data, then the encrypted message is split, including:
[0194] The encrypted message is split based on the second specified character position and the character length of the first encrypted data, wherein the encrypted message is obtained by inserting the second encrypted data into the second specified character position of the first encrypted data;
[0195] If the character length of each first sub-data and the position of the third specified character corresponding to each first sub-data are received from the terminal device, then the encrypted message is split, including:
[0196] The encrypted message is split based on the character length of each first sub-data and the third specified character position corresponding to each first sub-data. The first sub-data is obtained by splitting the first encrypted data, and the encrypted message is obtained by inserting each first sub-data into the corresponding third character position in the second encrypted data.
[0197] If the character length of each second sub-data and the position of the fourth specified character corresponding to each second sub-data are received from the terminal device, then the encrypted message is split, including:
[0198] The encrypted message is split based on the character length of each second sub-data and the fourth specified character position corresponding to each second sub-data. The second sub-data is obtained by splitting the second encrypted data, and the encrypted message is obtained by inserting each second sub-data into the corresponding fourth character position in the first encrypted data.
[0199] In this embodiment of the application, when the method of combining encrypted messages is to insert the first encrypted data into the first specified character position of the second encrypted data, the first specified character position and the character length of the second encrypted data can be sent to the server. The server can extract the character length of the second encrypted data from the encrypted message starting from the first specified character position. The extracted data is the second encrypted data. The remaining data in the encrypted message can be concatenated at the first specified character position to obtain the first encrypted data.
[0200] Accordingly, when the method of combining encrypted messages is to insert the second encrypted data into the second specified character position of the first encrypted data, the first specified character position and the character length of the second encrypted data can be sent to the server. The server can extract the character length of the first encrypted data from the encrypted message starting from the second specified character position. The extracted data is the first encrypted data. The remaining data in the encrypted message can be concatenated at the second specified character position to obtain the second encrypted data.
[0201] In this embodiment of the application, when the method of combining encrypted messages is to determine the third specified character position of each first sub-data in the second encrypted data and insert each first sub-data into the corresponding third character position, the character length of each first sub-data and the third specified character position corresponding to each first sub-data can be sent to the server. The server can extract the data corresponding to the character length of each first sub-data from the encrypted message starting from the third specified character position corresponding to each first sub-data, thereby extracting each first sub-data. Then, the first sub-data are combined according to the splitting method to obtain the first encrypted data. The remaining data in the encrypted message are concatenated at each third specified character position to obtain the second encrypted data.
[0202] Accordingly, when the method of combining encrypted messages is to determine the fourth specified character position of each second sub-data in the first encrypted data and insert each second sub-data into the corresponding fourth character position, the character length of each second sub-data and the fourth specified character position of each second sub-data can be sent to the server. The server can extract the data corresponding to the character length of each second sub-data from the encrypted message starting from the fourth specified character position of each second sub-data, thereby extracting each second sub-data. Then, according to the splitting method, the second sub-data are combined to obtain the second encrypted data. The remaining data in the encrypted message are concatenated at each fourth specified character position to obtain the first encrypted data.
[0203] In practical applications, a front-end JavaScript SDK package can be developed to implement various national cryptographic algorithms using JavaScript. A JavaScript cryptographic envelope packaging interface is encapsulated, combining the four steps of generating a random communication key, encrypting ciphertext, encrypting the random communication key, and packaging the ciphertext and key into a cryptographic envelope within a single JavaScript interface. For projects using the JavaScript SDK package on the front end, the cryptographic envelope packaging logic is transparent; they only need to call this interface and pass the necessary parameters to complete the packaging. A server-side Java JAR package is also developed, encapsulating the interfaces for various national cryptographic algorithms on the server side.
[0204] As an example, Figure 3 The diagram shows a flowchart of the message generation and decryption method provided in this application, where the front end is the client, the terminal device, and the server is the server.
[0205] A pre-generated asymmetric SM2 key pair is used. The public key PubKey is embedded into the client's JavaScript SDK package through obfuscation encryption, while the private key PriKey is stored in the encryption machine on the server.
[0206] The client generates a random communication key before each communication request.
[0207] The client uses the national standard symmetric encryption algorithm SM4 and the communication key Key to encrypt the communication data Data that needs to be transmitted, generating the communication ciphertext SecurityData.
[0208] The client uses the Chinese national cryptographic asymmetric encryption algorithm SM2 and the asymmetric public key PubKey (already embedded in the SDK package) to encrypt the communication key Key, generating the ciphertext SecurityKey.
[0209] The client uses specific password envelope packaging rules to package SecurityData and SecurityKey into password envelopes and sends them to the server.
[0210] Based on and Figure 1 The method shown follows the same principle. Figure 4 This illustration shows a schematic diagram of the structure of an encrypted message generation apparatus provided in an embodiment of this application, as shown below. Figure 4 As shown, the encrypted message generation device 30 may include:
[0211] The first encryption module 310 is used to encrypt the message to be encrypted based on a random key to obtain the first encrypted data;
[0212] The second encryption module 320 is used to encrypt the random key based on the public key to obtain the second encrypted data;
[0213] The combination module 330 is used to combine the first encrypted data and the second encrypted data to obtain an encrypted message.
[0214] The apparatus provided in this application encrypts a message to be encrypted using a random key to obtain first encrypted data, and then encrypts the random key using a public key to obtain second encrypted data. The first and second encrypted data are then combined to obtain an encrypted message. In this scheme, because encryption is performed using a random key and a public key, and the encrypted message is obtained by combining the encrypted data, the security of the encrypted message is improved, and data leakage is avoided.
[0215] Optionally, the above-mentioned device further includes:
[0216] The message sending module is used to send encrypted messages to the corresponding server, so that the server can decrypt the encrypted messages based on the private key corresponding to the public key.
[0217] Optionally, when combining the first encrypted data and the second encrypted data, the combining module is specifically used for any of the following:
[0218] Insert the entire first encrypted data into the second encrypted data, or insert the entire second encrypted data into the first encrypted data;
[0219] The first encrypted data is split into at least two first sub-data, and each first sub-data is inserted into the second encrypted data; or, the second encrypted data is split into at least two second sub-data, and each second sub-data is inserted into the first encrypted data.
[0220] Optionally, if the combining module, when combining the first encrypted data and the second encrypted data, is specifically used to insert the first encrypted data as a whole into the second encrypted data, then the combining module, when inserting the first encrypted data as a whole into the second encrypted data, is specifically used to:
[0221] Insert the first encrypted data into the second encrypted data at the first specified character position;
[0222] If the combining module, when combining the first encrypted data and the second encrypted data, specifically inserts the entire second encrypted data into the first encrypted data, then the combining module, when inserting the entire second encrypted data into the first encrypted data, specifically performs the following:
[0223] Insert the second encrypted data into the second specified character position in the first encrypted data.
[0224] Optionally, if the combining module, when combining the first encrypted data and the second encrypted data, is specifically used to insert the first encrypted data into the second encrypted data at a first specified character position, then the above-mentioned device further includes:
[0225] The first data sending module is used to send the first specified character position and the character length of the second encrypted data to the server, so that the server can split the encrypted message based on the first specified character position and the character length of the second encrypted data;
[0226] Optionally, if the combining module, when combining the first encrypted data and the second encrypted data, is specifically used to insert the second encrypted data into the second specified character position in the first encrypted data, then the above-mentioned device further includes:
[0227] The first data sending module is used to send the second specified character position and the character length of the first encrypted data to the server, so that the server can split the encrypted message based on the second specified character position and the character length of the first encrypted data.
[0228] Optionally, if the combining module, when combining the first encrypted data and the second encrypted data, specifically splits the first encrypted data into at least two first sub-data and inserts each first sub-data into the second encrypted data, then the combining module, when inserting each first sub-data into the second encrypted data, specifically performs the following:
[0229] Determine the third specified character position of each first sub-data in the second encrypted data, and insert each first sub-data into the corresponding third character position;
[0230] If, when combining the first encrypted data and the second encrypted data, the combining module specifically splits the second encrypted data into at least two second sub-data, and inserts each second sub-data into the first encrypted data, then the combining module specifically inserts each second sub-data into the first encrypted data as follows:
[0231] Determine the fourth specified character position of each second sub-data in the first encrypted data, and insert each second sub-data into the corresponding fourth character position.
[0232] Optionally, if the combining module, when combining the first encrypted data and the second encrypted data, is specifically used to determine the third specified character position of each first sub-data in the second encrypted data, and insert each first sub-data into the corresponding third character position, then the above device further includes:
[0233] The third data sending module is used to send the character length of each first sub-data and the third specified character position corresponding to each first sub-data to the server, so that the server can split the encrypted message based on the character length of each first sub-data and the third specified character position corresponding to each first sub-data.
[0234] Optionally, if the combining module, when combining the first encrypted data and the second encrypted data, specifically determines the fourth specified character position of each of the two sub-data items in the first encrypted data and inserts each of the second sub-data items into the corresponding fourth character position, then the above-mentioned device further includes:
[0235] The fourth data sending module is used to send the character length of each second sub-data and the fourth specified character position corresponding to each second sub-data to the server, so that the server can split the encrypted message based on the character length of each second sub-data and the fourth specified character position corresponding to each second sub-data.
[0236] Optionally, the above-mentioned device further includes:
[0237] The key generation module is used to generate a random key corresponding to the message to be encrypted.
[0238] It is understood that the above-mentioned modules of the encrypted message generation device in this embodiment have the ability to implement... Figure 1 The embodiments shown illustrate the functionality of the corresponding steps in the encrypted message generation method. This functionality can be implemented in hardware or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above-described functions. These modules can be software and / or hardware, and each module can be implemented individually or multiple modules can be integrated. For a detailed description of the functions of each module in the encrypted message generation device, please refer to [link to relevant documentation]. Figure 1 The corresponding description of the encrypted message generation method in the illustrated embodiments will not be repeated here.
[0239] Based on and Figure 2 The method shown follows the same principle. Figure 5 This illustration shows a structural schematic diagram of a decryption device for encrypted messages provided in an embodiment of this application. Figure 5 As shown, the decryption device 40 for the encrypted message may include:
[0240] The message splitting module 410 is used to split the encrypted message upon receiving it from the terminal device to obtain the split message.
[0241] The message decryption module 420 is used to decrypt the split message based on the private key.
[0242] The apparatus provided in this application, upon receiving an encrypted message from a terminal device, splits the encrypted message into a split message, and then decrypts the split message based on a private key. This solution improves the security of the encrypted message and effectively prevents data leakage by first splitting the encrypted message and then decrypting it using the private key.
[0243] Optionally, the split message includes first encrypted data and second encrypted data. The first encrypted data is obtained by encrypting the message to be encrypted based on a random key, and the second encrypted data is obtained by encrypting the random key based on the public key corresponding to the private key.
[0244] Optionally, the message decryption module is specifically used for:
[0245] The random key is obtained by decrypting the second encrypted data using the private key.
[0246] The target message is obtained by decrypting the first encrypted data using a random key.
[0247] Optionally, the above-mentioned device further includes: a data receiving module;
[0248] The data receiving module is used to receive any of the following sent by the terminal device:
[0249] The first specified character position and the character length of the second encrypted data;
[0250] The second specified character position and the character length of the first encrypted data;
[0251] The character length of each first sub-data and the position of the third specified character corresponding to each first sub-data;
[0252] The character length of each second sub-data and the position of the fourth specified character corresponding to each second sub-data;
[0253] If the terminal device sends the first specified character position and the character length of the second encrypted data, the message splitting module, when splitting the encrypted message, is specifically used for:
[0254] The encrypted message is split based on the first specified character position and the character length of the second encrypted data, wherein the encrypted message is obtained by inserting the first encrypted data into the second encrypted data at the first specified character position;
[0255] If the terminal device sends the second specified character position and the character length of the first encrypted data, the message splitting module, when splitting the encrypted message, is specifically used for:
[0256] The encrypted message is split based on the second specified character position and the character length of the first encrypted data, wherein the encrypted message is obtained by inserting the second encrypted data into the second specified character position of the first encrypted data;
[0257] If the terminal device sends the character length of each first sub-data and the third specified character position corresponding to each first sub-data, the message splitting module, when splitting the encrypted message, is specifically used for:
[0258] The encrypted message is split based on the character length of each first sub-data and the third specified character position corresponding to each first sub-data. The first sub-data is obtained by splitting the first encrypted data, and the encrypted message is obtained by inserting each first sub-data into the corresponding third character position in the second encrypted data.
[0259] If the terminal device sends the character length of each second sub-data and the fourth specified character position corresponding to each second sub-data, the message splitting module, when splitting the encrypted message, is specifically used for:
[0260] The encrypted message is split based on the character length of each second sub-data and the fourth specified character position corresponding to each second sub-data. The second sub-data is obtained by splitting the second encrypted data, and the encrypted message is obtained by inserting each second sub-data into the corresponding fourth character position in the first encrypted data.
[0261] It is understood that the above-mentioned modules of the encrypted message decryption device in this embodiment have the ability to implement... Figure 2 The embodiments shown illustrate the functionality of the corresponding steps in the encrypted message decryption method. This functionality can be implemented in hardware or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above-described functions. These modules can be software and / or hardware, and each module can be implemented individually or multiple modules can be integrated. For a detailed description of the functions of each module in the encrypted message decryption device, please refer to [link to relevant documentation]. Figure 2 The corresponding description of the decryption method for the encrypted messages in the illustrated embodiments will not be repeated here.
[0262] This application provides an electronic device, including a processor and a memory;
[0263] Memory, used to store operation instructions;
[0264] A processor is configured to execute the methods provided in any embodiment of this application by invoking operation instructions.
[0265] As an example, Figure 6 A schematic diagram of the structure of an electronic device to which this application embodiment applies is shown, such as... Figure 6 As shown, the electronic device 2000 includes a processor 2001 and a memory 2003. The processor 2001 and the memory 2003 are connected, for example, via a bus 2002. Optionally, the electronic device 2000 may also include a transceiver 2004. It should be noted that in practical applications, the transceiver 2004 is not limited to one type, and the structure of the electronic device 2000 does not constitute a limitation on the embodiments of this application.
[0266] In this embodiment, the processor 2001 is used to implement the method shown in the above method embodiment. The transceiver 2004 may include a receiver and a transmitter. In this embodiment, the transceiver 2004 is used to enable the electronic device of this embodiment to communicate with other devices during execution.
[0267] Processor 2001 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It can implement or execute the various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. Processor 2001 may also be a combination that implements computing functions, such as including one or more microprocessor combinations, a combination of a DSP and a microprocessor, etc.
[0268] Bus 2002 may include a pathway for transmitting information between the aforementioned components. Bus 2002 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. Bus 2002 can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 6 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.
[0269] The memory 2003 may be ROM (Read Only Memory) or other types of static storage devices capable of storing static information and instructions, RAM (Random Access Memory) or other types of dynamic storage devices capable of storing information and instructions, or EEPROM (Electrically Erasable Programmable Read Only Memory), CD-ROM (Compact Disc Read Only Memory) or other optical disc storage, optical disc storage (including compressed optical discs, laser discs, optical discs, digital universal optical discs, Blu-ray discs, etc.), magnetic disk storage media or other magnetic storage devices, or any other medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but not limited thereto.
[0270] Optionally, the memory 2003 is used to store application code that executes the scheme of this application, and its execution is controlled by the processor 2001. The processor 2001 is used to execute the application code stored in the memory 2003 to implement the method provided in any embodiment of this application.
[0271] The electronic device provided in this application is applicable to any of the above-described methods, and will not be described again here.
[0272] This application provides an electronic device that, compared to existing technologies, encrypts a message to be encrypted using a random key to obtain first encrypted data, and then encrypts the random key using a public key to obtain second encrypted data. The first and second encrypted data are then combined to obtain an encrypted message. In this solution, because encryption is based on a random key and a public key, and the encrypted message is obtained by combining the encrypted data, the security of the encrypted message is improved, preventing data leakage.
[0273] This application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the method shown in the above-described method embodiments.
[0274] The computer-readable storage medium provided in this application is applicable to any of the above-described method embodiments, and will not be described again here.
[0275] This application provides a computer-readable storage medium. Compared with existing technologies, it encrypts the message to be encrypted using a random key to obtain first encrypted data, and then encrypts the random key using a public key to obtain second encrypted data. The first and second encrypted data are then combined to obtain an encrypted message. In this solution, because encryption is based on a random key and a public key, and the encrypted message is obtained by combining the encrypted data, the security of the encrypted message is improved, and data leakage is avoided.
[0276] It should be understood that although the steps in the flowcharts of the accompanying figures are shown sequentially as indicated by the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the accompanying figures may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the sub-steps or stages of other steps.
[0277] The above are only some embodiments of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A method for generating an encrypted message, characterized by, The method comprises: encrypting the plaintext message based on a random key to obtain first encrypted data; encrypting the random key based on a public key to obtain second encrypted data; combining the first encrypted data and the second encrypted data, including any of the following: inserting the first encrypted data into a first specified character position in the second encrypted data; inserting the second encrypted data into a second specified character position in the first encrypted data; wherein the second specified character position and the character length of the first encrypted data are sent to a server, so that the server splits the encrypted message based on the second specified character position and the character length of the first encrypted data; the first specified character position and the character length of the second encrypted data are sent to a server, so that the server splits the encrypted message based on the first specified character position and the character length of the second encrypted data; obtaining the encrypted message; if the combining the first encrypted data and the second encrypted data includes splitting the first encrypted data into at least two first sub-data, and inserting each of the first sub-data into the second encrypted data, then the inserting each of the first sub-data into the second encrypted data comprises: determining a third specified character position of each of the first sub-data in the second encrypted data, and inserting each of the first sub-data into the corresponding third character position; if the combining the first encrypted data and the second encrypted data includes splitting the second encrypted data into at least two second sub-data, and inserting each of the second sub-data into the first encrypted data, then the inserting each of the second sub-data into the first encrypted data comprises: determining a fourth specified character position of each of the second sub-data in the first encrypted data, and inserting each of the second sub-data into the corresponding fourth character position; if the combining the first encrypted data and the second encrypted data includes determining a third specified character position of each of the first sub-data in the second encrypted data, and inserting each of the first sub-data into the corresponding third character position, then the method further comprises: sending the character length of each of the first sub-data and the third specified character position corresponding to each of the first sub-data to a server, so that the server splits the encrypted message based on the character length of each of the first sub-data and the third specified character position corresponding to each of the first sub-data; if the combining the first encrypted data and the second encrypted data includes determining a fourth specified character position of each of the second sub-data in the first encrypted data, and inserting each of the second sub-data into the corresponding fourth character position, then the method further comprises: sending the character length of each of the second sub-data and the fourth specified character position corresponding to each of the second sub-data to a server, so that the server splits the encrypted message based on the character length of each of the second sub-data and the fourth specified character position corresponding to each of the second sub-data.
2. The method of claim 1, wherein, Further comprising: Send the encrypted message to the corresponding server, so that the server decrypts the encrypted message based on the private key corresponding to the public key.
3. The method according to any one of claims 1-2, characterized in that, Also includes: Generate a random key corresponding to the message to be encrypted.
4. A decryption method of an encrypted message, characterized by, Includes: When receiving the encrypted message sent by the terminal device, split the encrypted message to obtain the split message; Decrypt the split message based on the private key; Also includes: Receive any of the following sent by the terminal device: The first specified character position and the character length of the second encrypted data; The second specified character position and the character length of the first encrypted data; The character length of each first sub-data and the third specified character position corresponding to each first sub-data; The character length of each second sub-data and the fourth specified character position corresponding to each second sub-data; If the terminal device sends the first specified character position and the character length of the second encrypted data, the split of the encrypted message includes: Split the encrypted message based on the first specified character position and the character length of the second encrypted data, wherein the encrypted message is obtained by inserting the first encrypted data into the first specified character position in the second encrypted data; If the terminal device sends the second specified character position and the character length of the first encrypted data, the split of the encrypted message includes: Split the encrypted message based on the second specified character position and the character length of the first encrypted data, wherein the encrypted message is obtained by inserting the second encrypted data into the second specified character position in the first encrypted data; If the terminal device sends the character length of each first sub-data and the third specified character position corresponding to each first sub-data, the split of the encrypted message includes: Split the encrypted message based on the character length of each first sub-data and the third specified character position corresponding to each first sub-data, wherein the first sub-data is split from the first encrypted data, and the encrypted message is obtained by inserting each first sub-data into the corresponding third character position in the second encrypted data; If the terminal device sends the character length of each second sub-data and the fourth specified character position corresponding to each second sub-data, the split of the encrypted message includes: Split the encrypted message based on the character length of each second sub-data and the fourth specified character position corresponding to each second sub-data, wherein the second sub-data is split from the second encrypted data, and the encrypted message is obtained by inserting each second sub-data into the corresponding fourth character position in the first encrypted data.
5. The method of claim 4, wherein, The split message includes first encrypted data and second encrypted data, the first encrypted data is obtained by encrypting the message to be encrypted based on the random key, and the second encrypted data is obtained by encrypting the random key based on the public key corresponding to the private key.
6. The method of claim 5, wherein, The decrypting the split message based on the private key comprises: decrypting the second encrypted data based on the private key to obtain a random key; decrypting the first encrypted data based on the random key to obtain a target message.
7. An apparatus for generating an encrypted message, characterized by A device for performing the method of any one of claims 1-3, comprising: a first encryption module configured to encrypt a to-be-encrypted message based on a random key to obtain first encrypted data; a second encryption module configured to encrypt the random key based on a public key to obtain second encrypted data; a combination module configured to combine the first encrypted data and the second encrypted data to obtain an encrypted message.
8. A decryption apparatus for decrypting an encrypted message, characterized by comprising: A device for performing the method of any one of claims 4-6, comprising: a message splitting module configured to split an encrypted message sent by a terminal device to obtain a split message when the encrypted message is received; a message decryption module configured to decrypt the split message based on a private key.
9. An electronic device, comprising: comprising a processor and a memory; the memory is configured to store operation instructions; the processor is configured to execute the method of any one of claims 1-6 by calling the operation instructions.
10. A computer-readable storage medium, characterized in that, The storage medium has a computer program stored thereon, and the computer program is executed by the processor to implement the method of any one of claims 1-6. The storage medium has a computer program stored thereon, and the computer program is executed by the processor to implement the method of any one of claims 1-6.
Citation Information
Patent Citations
Data encryption method, device and system, data decryption method, device and system and readable storage medium
CN111967023A
Electronic terminal device for safe storage of identification data and operating method thereof
KR1020170105921A