Short message encryption method and short message decryption method
Through hashing algorithm and encryption technology, the content of SMS is digitally signed and encrypted, and the session key is encrypted using the public key, which solves the problem of insufficient information security in SMS transmission and achieves efficient data protection.
Patent Information
- Application Number
- CN202410991784.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-23
- Publication Date
- 2024-11-05
AI Technical Summary
In the prior art, mobile phone text messages lack security during transmission and cannot effectively protect sensitive and confidential information, resulting in a high risk of information leakage.
The hash algorithm is used to generate an information digest, and the private key is used to encrypt the digest to obtain a digital signature, generate a session key to encrypt the content of the SMS, and use the other party's public key to encrypt the session key, form a SMS ciphertext and digital signature, and transmit it through SMS. , ensure that there is no clear text involved during the transmission process.
It significantly improves the security of SMS transmission, prevents information leakage, and ensures the confidentiality of data during transmission.
Smart Images

Figure CN118900411A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of data encryption technology, and in particular to a text message encryption method and a text message decryption method. Background Art
[0002] At present, in some cases, it is necessary to use text messages for business processing, and the Internet cannot be used for business processing. For example, when conducting highway intelligence information review business in the field of highway intelligence, staff are required to send the review message to the relevant reviewers in the form of text messages under isolated network conditions. The relevant reviewers also need to reply to the review opinions in the form of text messages. In the prior art, text messages are sent using mobile phone text messaging services. Ordinary text messages are transmitted in plain text. For security reasons, sensitive and confidential information is often not allowed to be sent and received in plain text to prevent the information from being illegally eavesdropped or leaked to related units, causing significant losses. Therefore, ordinary mobile phone text message transmission methods cannot meet the needs. Summary of the invention
[0003] The embodiments of the present application provide a text message encryption method and a text message decryption method, which can improve the security of text message transmission.
[0004] A first aspect of an embodiment of the present application provides a method for encrypting a text message, which is applied to a first device and includes:
[0005] Get the content of the SMS to be sent;
[0006] Performing a hash operation on the content of the SMS message using a preset hash algorithm to generate a first information digest;
[0007] Encrypting the first information summary using the local private key to obtain a digital signature;
[0008] Generate a session key, where the session key is a symmetric key;
[0009] Encrypting the content of the SMS using the session key to obtain SMS ciphertext;
[0010] Encrypting the session key using the public key of the second device pre-stored in the local database to obtain a session key ciphertext;
[0011] The session key ciphertext, the SMS ciphertext, and the digital signature are sent to the second device in the form of an SMS.
[0012] Optionally, before obtaining the content of the SMS to be sent, the method further includes:
[0013] Exchange public keys with the second device.
[0014] Optionally, exchanging public keys of both parties with the second device includes:
[0015] Generate its own public key and private key using an asymmetric encryption algorithm, wherein the public key and the private key are a key pair to each other;
[0016] Generate a first character string according to a first generation rule;
[0017] Performing a hash operation on the public key and the first character string using a preset hash algorithm to obtain a second summary;
[0018] Sending the first generation rule, the public key, and the second digest to a second device, so that the second device verifies and stores the public key;
[0019] receiving a second generation rule, a public key of the second device, and a third digest sent by the second device;
[0020] Verify the public key of the second device according to the second generation rule, the public key of the second device and the third digest to obtain a verification result;
[0021] When the verification result is characterized as passed, the public key of the second device is stored in a local database.
[0022] Optionally, the performing verification on the public key of the enemy device according to the second generation rule, the public key of the second device and the third digest to obtain a verification result includes:
[0023] Obtain each word and word combination order in the second generation rule;
[0024] Query the mapping word of each word through the local word mapping table;
[0025] Combining the mapped words according to the word combination order to obtain a second character string;
[0026] Performing a hash operation on the public key of the second device and the second character string using the preset hash algorithm to obtain a fourth digest;
[0027] A verification result is generated by comparing the third digest and the fourth digest.
[0028] Optionally, sending the session key ciphertext, the SMS ciphertext, and the digital signature to the second device in the form of an SMS includes:
[0029] Combining the session key ciphertext, the message ciphertext and the digital signature into information to be transmitted;
[0030] Segmenting the information to be transmitted according to the segmentation rule, and generating segment identifiers according to the order before segmentation;
[0031] Combining each segment identifier with the segment information corresponding to the segment identifier to generate a ciphertext text message;
[0032] Send all the encrypted text messages to the second device.
[0033] A second aspect of an embodiment of the present application provides a method for decrypting a text message, which is applied to a second device and includes:
[0034] Receiving a text message sent by the first device;
[0035] Parsing the SMS message to obtain the session key ciphertext, SMS ciphertext and digital signature;
[0036] Decrypting the digital signature using a public key of the first device pre-selected and stored in a local database to obtain a first information digest;
[0037] Decrypting the session key ciphertext using the local private key to obtain the session key;
[0038] Decrypting the SMS ciphertext using the session key to obtain SMS content;
[0039] Performing a hash operation on the content of the SMS message using a preset hash algorithm to obtain a second message digest;
[0040] Determining whether the first information digest is consistent with the second information digest;
[0041] If yes, storing the session key and the SMS ciphertext;
[0042] When the user needs to view the message, the session key is used to decrypt the ciphertext of the short message to obtain the content of the short message and display it.
[0043] Optionally, before receiving the text message sent by the first device, the method further includes:
[0044] Exchange public keys of both parties with the first device.
[0045] Optionally, exchanging public keys of both parties with the first device includes:
[0046] Generate its own public key and private key using an asymmetric encryption algorithm, wherein the public key and the private key are a key pair to each other;
[0047] Generate a second character string according to a second generation rule;
[0048] Performing a hash operation on the public key and the second character string using a preset hash algorithm to obtain a third summary;
[0049] sending the second generation rule, the public key, and the third digest to the first device, so that the first device verifies and stores the public key;
[0050] receiving a first generation rule, a public key of the first device, and a second digest sent by the first device;
[0051] Verify the public key of the first device according to the first generation rule, the public key of the first device, and the second digest to obtain a verification result;
[0052] When the verification result is characterized as passed, the public key of the first device is stored in a local database.
[0053] Optionally, the performing verification on the public key of the first device according to the first generation rule, the public key of the first device, and the second digest to obtain a verification result includes:
[0054] Obtain each word and word combination order in the first generation rule;
[0055] Query the mapping word of each word through the local word mapping table;
[0056] Combining the mapping words according to the word combination order to obtain a first character string;
[0057] Performing a hash operation on the public key of the first device and the first character string using the preset hash algorithm to obtain a fifth digest;
[0058] A verification result is generated by comparing the second digest and the fifth digest.
[0059] Optionally, the receiving a text message sent by the first device includes:
[0060] Receiving multiple encrypted text messages sent by the first device;
[0061] Obtaining the segment identifier and segment information of each of the ciphertext text messages;
[0062] The segmented information is combined according to the sequence of the segment identifiers to obtain a short message.
[0063] A third aspect of an embodiment of the present application provides a first device, including:
[0064] An acquisition unit, in which the application acquires the content of the SMS to be sent;
[0065] A first generating unit, configured to perform a hash operation on the content of the SMS message using a preset hash algorithm to generate a first information digest;
[0066] A first encryption unit, used to encrypt the first information summary using the local private key to obtain a digital signature;
[0067] A second generating unit, used to generate a session key, wherein the session key is a symmetric key;
[0068] A second encryption unit, used to encrypt the SMS content using the session key to obtain a ciphertext SMS;
[0069] A third encryption unit, configured to encrypt the session key using the public key of the second device pre-stored in the local database to obtain a ciphertext of the session key;
[0070] The sending unit is used to send the session key ciphertext, the SMS ciphertext, and the digital signature to the second device in the form of SMS.
[0071] Optionally, the first device further includes:
[0072] The exchanging unit is used to exchange the public keys of both parties with the second device.
[0073] Optionally, the switching unit includes:
[0074] A first generation module, used to generate its own public key and private key using an asymmetric encryption algorithm, wherein the public key and the private key are a key pair;
[0075] A second generating module, used to generate a first character string according to a first generating rule;
[0076] A hash module, configured to perform a hash operation on the public key and the first character string using a preset hash algorithm to obtain a second summary;
[0077] a sending module, configured to send the first generation rule, the public key and the second digest to a second device, so that the second device verifies and stores the public key;
[0078] A receiving module, configured to receive a second generation rule, a public key of the second device, and a third summary sent by the second device;
[0079] a verification module, configured to verify the public key of the second device according to the second generation rule, the public key of the second device and the third digest, to obtain a verification result;
[0080] The storage module is used to store the public key of the second device in a local database when the verification result is characterized as passed.
[0081] Optionally, the verification module is specifically used for:
[0082] Obtain each word and word combination order in the second generation rule;
[0083] Query the mapping word of each word through the local word mapping table;
[0084] Combining the mapped words according to the word combination order to obtain a second character string;
[0085] Performing a hash operation on the public key of the second device and the second character string using the preset hash algorithm to obtain a fourth digest;
[0086] A verification result is generated by comparing the third digest and the fourth digest.
[0087] Optionally, the sending unit is specifically used for:
[0088] Combining the session key ciphertext, the message ciphertext and the digital signature into information to be transmitted;
[0089] Segmenting the information to be transmitted according to the segmentation rule, and generating segment identifiers according to the order before segmentation;
[0090] Combining each segment identifier with the segment information corresponding to the segment identifier to generate a ciphertext text message;
[0091] Send all the encrypted text messages to the second device.
[0092] A fourth aspect of the embodiments of the present application provides a first device, including:
[0093] Processor, memory, input-output unit, and bus;
[0094] The processor is connected to the memory, the input and output unit, and the bus;
[0095] A program is stored in the memory, and the processor calls the program to execute the method in the first aspect and any possible implementation manner of the first aspect.
[0096] A fifth aspect of the embodiments of the present application provides a second device, including:
[0097] A receiving unit, configured to receive a text message sent by the first device;
[0098] A parsing unit, used to parse the SMS message to obtain a session key ciphertext, a SMS ciphertext and a digital signature;
[0099] A first decryption unit, configured to decrypt the digital signature using a public key of the first device pre-selected and stored in a local database to obtain a first information digest;
[0100] A second decryption unit, used to decrypt the session key ciphertext using the local private key to obtain the session key;
[0101] A third decryption unit, used to decrypt the SMS ciphertext using the session key to obtain SMS content;
[0102] A hash unit, configured to perform a hash operation on the content of the SMS message using a preset hash algorithm to obtain a second information summary;
[0103] a judging unit, configured to judge whether the first information digest is consistent with the second information digest;
[0104] a storage unit, configured to store the session key and the SMS ciphertext when the judgment unit determines that the first information digest is consistent with the second information digest;
[0105] The display unit is used to decrypt the SMS ciphertext using the session key to obtain the SMS content and display it when the user needs to view the message.
[0106] Optionally, the second device further includes:
[0107] The exchanging unit is used to exchange the public keys of both parties with the first device.
[0108] Optionally, the switching unit includes:
[0109] A first generation module, used to generate its own public key and private key using an asymmetric encryption algorithm, wherein the public key and the private key are a key pair;
[0110] A second generating module, used to generate a second character string according to a second generating rule;
[0111] A hash module, configured to perform a hash operation on the public key and the second character string using a preset hash algorithm to obtain a third summary;
[0112] a sending module, configured to send the second generation rule, the public key and the third digest to the first device, so that the first device verifies and stores the public key;
[0113] A receiving module, configured to receive a first generation rule, a public key of the first device, and a second digest sent by the first device;
[0114] a verification module, configured to verify the public key of the first device according to the first generation rule, the public key of the first device and the second digest, and obtain a verification result;
[0115] The storage module is used to store the public key of the first device in a local database when the verification result is characterized as passed.
[0116] Optionally, the verification module is specifically used for:
[0117] Obtain each word and word combination order in the first generation rule;
[0118] Query the mapping word of each word through the local word mapping table;
[0119] Combining the mapping words according to the word combination order to obtain a first character string;
[0120] Performing a hash operation on the public key of the first device and the first character string using the preset hash algorithm to obtain a fifth digest;
[0121] A verification result is generated by comparing the second digest and the fifth digest.
[0122] Optionally, the receiving unit is specifically used for:
[0123] Receiving multiple encrypted text messages sent by the first device;
[0124] Obtaining the segment identifier and segment information of each of the ciphertext text messages;
[0125] The segmented information is combined according to the sequence of the segment identifiers to obtain a short message.
[0126] A sixth aspect of the embodiments of the present application provides a second device, including:
[0127] Processor, memory, input-output unit, and bus;
[0128] The processor is connected to the memory, the input and output unit, and the bus;
[0129] A program is stored in the memory, and the processor calls the program to execute the method in the second aspect and any possible implementation manner of the second aspect.
[0130] A seventh aspect of an embodiment of the present application provides a computer-readable storage medium, on which a program is stored. When the program is executed on a computer, the computer executes the method in the first aspect and any possible implementation of the first aspect.
[0131] It can be seen from the above technical solutions that the embodiments of the present application have the following advantages:
[0132] After the first device obtains the content of the SMS to be sent, it first performs a hash operation on the SMS content using a preset hash algorithm to obtain a first information summary, then uses the local private key to encrypt the first information summary to obtain a digital signature, and then generates a session key and uses the session key to encrypt the SMS content to obtain an SMS ciphertext. Then, it uses the public key of the second device to encrypt the session key to obtain a session key ciphertext. Finally, the session key ciphertext, SMS ciphertext and digital signature are sent to the second device in the form of an SMS. Plain text is not involved in the data transmission process, and the second device needs to verify the digital signature before performing the corresponding decryption, which greatly improves the security of SMS transmission messages. BRIEF DESCRIPTION OF THE DRAWINGS
[0133] Figure 1 This is a flow chart of an embodiment of a method for encrypting short messages in an embodiment of the present application;
[0134] Figure 2 A schematic diagram of a process of exchanging public keys between a first device and a second device in an embodiment of the present application;
[0135] Figure 3 This is a flow chart of an embodiment of performing verification on the second public key in the embodiment of the present application;
[0136] Figure 4 A flowchart of an embodiment of sending a session key ciphertext, a text message ciphertext, and a digital signature to a second device in the form of a text message in an embodiment of the present application;
[0137] Figure 5 This is a flow chart of an embodiment of a method for decrypting short messages in an embodiment of the present application;
[0138] Figure 6 A schematic diagram of a flow chart of an embodiment of exchanging public keys between a second device and a first device in an embodiment of the present application;
[0139] Figure 7 This is a flow chart of an embodiment of performing verification on a first public key in an embodiment of the present application;
[0140] Figure 8 A schematic diagram of a process of receiving a text message sent by a first device in an embodiment of the present application;
[0141] Fig. 9 This is a structural schematic diagram of an embodiment of the first device in the embodiments of the present application;
[0142] Fig.10 This is a structural schematic diagram of another embodiment of the first device in the embodiment of the present application;
[0143] Fig.11This is a schematic diagram of the structure of an embodiment of the second device in the embodiments of the present application;
[0144] Fig.12 This is a structural diagram of another embodiment of the second device in the embodiments of the present application. DETAILED DESCRIPTION
[0145] The embodiments of the present application provide a text message encryption method and a text message decryption method for improving security.
[0146] The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0147] See also Figure 1 In the embodiment of the present application, an embodiment of the SMS encryption method includes:
[0148] S101, obtaining the content of the SMS to be sent;
[0149] In actual application, the first user inputs the SMS content to be sent into the first device, and the first device can obtain the SMS content to be sent.
[0150] S102, performing a hash operation on the content of the SMS message using a preset hash algorithm to generate a first information digest;
[0151] After the first device obtains the content of the SMS to be sent, it can use the preset hash algorithm to perform a hash operation on the content of the SMS to generate a first SMS summary. The preset hash algorithm is an algorithm negotiated by the first device and the second device. When the two parties communicate, both parties need to use the preset hash algorithm when performing the hash operation. If the preset hash algorithm is to be changed, the two parties must negotiate to change the preset hash algorithm together. After the algorithm is changed, it must also be ensured that the preset hash algorithm changed by both parties is the same algorithm.
[0152] S103, using the local private key to encrypt the first information summary to obtain a digital signature;
[0153] After generating the first information summary, the first device may encrypt the first information summary using the local private key to obtain a digital signature. The encryption operation in this step may also be referred to as a signature operation.
[0154] S104, generating a session key, wherein the session key is a symmetric key;
[0155] Since the content of the SMS to be sent is in plain text, and in order to prevent leakage of information, the plain text is not allowed to be sent directly, so the first device needs to generate a session key, which is both an encryption key and a decryption key.
[0156] S105, encrypting the SMS content using the session key to obtain SMS ciphertext;
[0157] After the first device generates the session key, it can use the session key to encrypt the SMS content, thereby obtaining the SMS ciphertext, which is the ciphertext after the SMS content is encrypted.
[0158] S106. Encrypt the session key using the public key of the second device pre-stored in the local database to obtain a ciphertext of the session key;
[0159] Since the session key is both an encryption key and a decryption key, if the second device wants to obtain the plaintext of the SMS ciphertext, it needs to use the session key to decrypt the SMS ciphertext, so the first device needs to send the session key information to the second device. Also for security reasons, the session key cannot be transmitted in plaintext, so the first device needs to use the public key of the second device to encrypt the session key to obtain the session key ciphertext. Since the session key ciphertext is obtained by encrypting the session key using the public key of the second device, only the private key of the second device can decrypt the session key ciphertext, and the private key of the second device is kept private by the second device and is not disclosed to any device, so transmitting the session key ciphertext to the second device greatly improves security.
[0160] S107. Send the session key ciphertext, the SMS ciphertext, and the digital signature to the second device in the form of an SMS.
[0161] The first device may combine the session key ciphertext, the SMS ciphertext, and the digital signature into a form of a SMS, and then send the form to the second device.
[0162] In this embodiment, after obtaining the content of the SMS to be sent, the first device first performs a hash operation on the SMS content using a preset hash algorithm to obtain a first information summary, then uses the local private key to encrypt the first information summary to obtain a digital signature, then generates a session key and uses the session key to encrypt the SMS content to obtain an SMS ciphertext, then uses the public key of the second device to encrypt the session key to obtain a session key ciphertext, and finally sends the session key ciphertext, the SMS ciphertext and the digital signature to the second device in the form of an SMS. Plain text is not involved in the data transmission process, and the second device needs to verify the digital signature before performing the corresponding decryption, which greatly improves the security of SMS transmission messages.
[0163] See also Figure 2 , in some embodiments of the present application, Figure 1 The illustrated embodiment may further include a process of exchanging public keys between the first device and the second device, and the process may specifically include the following steps S201 to S207:
[0164] S201. Generate a first public key and a first private key using an asymmetric encryption algorithm, where the first public key and the first private key are a key pair;
[0165] Before obtaining the content of the SMS to be sent, the first device can first exchange the public keys of both parties with the second device, but not the private keys of both parties. The private keys of both parties are still kept by and only by the owner. Before exchanging the public keys, the first device needs to generate a key pair of the first public key and the first private key. In this embodiment, the first device generates the first public key and the first private key using an asymmetric encryption algorithm. The first public key is the public key of the first device, and the first private key is the private key of the first device. It should be noted that in the embodiment of the present application, the asymmetric encryption algorithm can be the RSA (Rivest-Shamir-Adleman) algorithm, the ECC (Elliptic Curve Cryptography) algorithm, the DSA (Digital Signature Algorithm) algorithm, the ElGamal algorithm, etc. This application does not limit this.
[0166] S202, generating a first character string according to a first generation rule;
[0167] The first device can generate the first character string using the first generation rule. In the embodiment of the present application, the first device and the second device both store the same word mapping table, and the single mapping table includes words and mapping words corresponding to the words, wherein each word is unique and each mapping word is also unique. The first generation rule is a combination rule of multiple words and these words.
[0168] S203, performing a hash operation on the first public key and the first character string using a preset hash algorithm to obtain a second information summary;
[0169] After generating the first character string, the first device may combine the first public key and the first character string to obtain a first combined character string, and then perform a hash operation on the first combined character string using a preset hash algorithm to obtain a second information summary.
[0170] S204, sending the first generation rule, the first public key, and the second information digest to a second device;
[0171] After generating the second information digest, the first device may send the first generation rule, the first public key and the second information digest to the second device, so that the second device performs tamper-proof verification on the second information digest using the first generation rule and the first public key.
[0172] S205, receiving a second generation rule, a second public key, and a third information digest sent by the second device;
[0173] During the public key exchange process, the first device will send the first generation rule, the first public key and the second information digest to the second device. Similarly, the second device will send the second generation rule, the second public key and the third information digest to the first device, and the first device can receive the second generation rule, the second public key and the third information digest.
[0174] S206, verifying the second public key according to the second generation rule and the third information digest to obtain a verification result;
[0175] After receiving the second generation rule, the second public key and the third information digest from the second device, the first device can use the second generation rule and the second public key to perform verification on the third information digest, and obtain a verification result after verification. The verification result includes two types: pass and fail.
[0176] S207: When the verification result is characterized as passed, the second public key is stored in a local database.
[0177] When the verification result is characterized as passed, it means that the second generation rule, the second public key and the third information summary sent by the second information have not been tampered with, and the second public key is safe and correct. At this time, the first device can store the second device in the local database for persistent storage.
[0178] It should be noted that in the process of exchanging public keys between the two parties, the messages are transmitted in the form of text messages. If the message to be sent at a time exceeds the capacity of a single text message, the message needs to be split according to the capacity of the text message to obtain multiple sub-messages. In addition, a length needs to be reserved in each sub-message to store the sub-message number. The number is generated in sequence and represents the position of the sub-message in the message before splitting. In this way, the recipient can combine multiple sub-messages according to the number to obtain a complete message.
[0179] In this embodiment, when the two parties exchange public keys, an anti-counterfeiting verification process is added to ensure the security of the exchange of public keys.
[0180] See also Figure 3 In some embodiments of the present application, step S206 in the above embodiment performs verification on the second public key according to the second generation rule and the third information digest to obtain a verification result, which may specifically include the following steps S2061 to S2065:
[0181] S2061, obtaining each word and word combination order in the second generation rule;
[0182] S2062, querying the mapping word of each word through the local word mapping table;
[0183] S2063, combining the mapping words according to the word combination order to obtain a second character string;
[0184] S2064. Perform a hash operation on the second public key and the second character string using the preset hash algorithm to obtain a fourth information digest;
[0185] S2065. Generate a verification result by comparing the third information digest and the fourth information digest.
[0186] When the first device performs verification on the second public key, it first obtains each word and the word combination order in the second generation rule. For each word, the first device performs an exact match query on the word in the word mapping table, and obtains the unique mapping word of the word from the word mapping table. After obtaining the mapping words of all words, the first device combines these mapping words according to the word combination order to obtain a second character string, and then combines the second public key and the second character string to obtain a second combined character string, and then uses a preset hash algorithm to perform a hash operation on the second combined character string to obtain a fourth information system digest, and finally compares the fourth information digest with the third information digest to generate a verification result. If the third information digest is consistent with the fourth information digest, the verification result is characterized as verification passed, and if the third information digest is inconsistent with the fourth information digest, the verification result is characterized as verification failed.
[0187] In this embodiment, a second generation rule is added during the verification process of the second public key. The first device needs to use the second generation rule to generate a second string, and then combine the second public key with the second string to obtain a new string. The new string is used as the input of the preset hash algorithm, which increases the complexity of verification and helps to improve security.
[0188] See also Figure 4 In some embodiments of the present application, step S107 in the above embodiment sends the session key ciphertext, the SMS ciphertext, and the digital signature to the second device in the form of a SMS, which may specifically include the following steps S1071 to S1074:
[0189] S1071, combining the session key ciphertext, the message ciphertext, and the digital signature into information to be transmitted;
[0190] S1072, segmenting the information to be transmitted according to a segmentation rule, and generating segment identifiers according to the order before segmentation;
[0191] S1073, combining each segment identifier with the segment information corresponding to the segment identifier to generate a ciphertext SMS;
[0192] S1074. Send all the encrypted text messages to the second device.
[0193] In this embodiment, the first device first combines the session key ciphertext, the SMS ciphertext and the digital signature to obtain the information to be transmitted, and then segments the information to be transmitted according to the segmentation rule to obtain multiple segmented information, and at the same time generates a segment identifier for each segmented information according to the order of the segmented information before segmentation, and then combines each segmented information and the corresponding segment identifier to obtain multiple ciphertext SMS messages, each of which includes a segmented information and a corresponding segment identifier. After generating multiple ciphertext SMS messages, all the ciphertext SMS messages generated this time can be sent to the second device. It should be noted that the segmentation rule is the rule for segmenting the information to be transmitted. When the information to be transmitted exceeds the length of a single SMS, it needs to be segmented. When segmenting, it is necessary to ensure that each segment reaches the upper limit of the length of a single SMS (except the last segment). Each segment includes the content of the segmented information and the content of the segment identifier. The segment identifier occupies a fixed length, and the length of the segmented information is the difference between the length of a single SMS and the length of the segment identifier. When combining the segment information with the segment identifier, the segment identifier can be placed at the front or at the back, or can be inserted between the segment information. However, all ciphertext messages should adopt a unified format, such as the segment identifiers are placed at the front or at the back, and this unified format needs to be negotiated in advance by the first device and the second device. If a change is required in the middle, the two parties must also negotiate in advance. It should be noted that the segment identifier in the ciphertext message is not plain text, but in the form of ciphertext. In this embodiment, the first device can first encrypt the segment identifier using the second public key, and then use the segment information corresponding to the encrypted segment identifier to combine into a ciphertext message.
[0194] In this embodiment, the segment identifier can be placed at the front or at the back, or can be inserted between segmented information. The location of the segment identifier in the encrypted text message is only known by the first device and the second device. Even if the encrypted text message is intercepted, the interceptor does not know where the segment identifier is. And even if the interceptor knows the location of the segment identifier, the segment identifier is encrypted by the first device using the second public key, and the interceptor cannot decrypt the segment identifier without the second private key. Therefore, this embodiment greatly improves the security of the encrypted text message transmission process.
[0195] See also Figure 5 In the embodiment of the present application, an embodiment of the SMS decryption method includes:
[0196] S501, receiving a text message sent by a first device;
[0197] The first device sends information to the second device in the form of a text message, and the second device can receive the corresponding text message.
[0198] S502, parsing the SMS message to obtain a session key ciphertext, a SMS ciphertext and a digital signature;
[0199] After receiving the SMS message, the second device can parse the SMS message to obtain the session key ciphertext, SMS ciphertext and digital signature. The session key ciphertext is obtained by encrypting the SMS content with the second public key by the first device. The SMS ciphertext is obtained by encrypting the SMS content with the session key. The digital signature is obtained by encrypting the first message digest with the first private key by the first device. The first message digest is obtained by performing a hash operation on the SMS content by the first device using a preset hash algorithm.
[0200] S503, decrypting the digital signature using the first public key pre-stored in the local database to obtain a first information summary;
[0201] Then, the second device can decrypt the digital signature using the first public key pre-stored in the local database to obtain the first information digest. The first public key is the public key of the first device.
[0202] S504, using the local private key to decrypt the session key ciphertext to obtain the session key;
[0203] Since the session key ciphertext is encrypted by the second public key, the second device can decrypt the session key ciphertext using the second private key to obtain the session key. The second private key is the private key of the second device.
[0204] S505, using the session key to decrypt the SMS ciphertext to obtain SMS content;
[0205] Since the SMS ciphertext is encrypted by the session key, and the session key is a symmetric key, encryption and decryption are both performed by the session key, so the second device can use the session key to decrypt the SMS ciphertext to obtain the SMS content.
[0206] S506, performing a hash operation on the content of the SMS message using a preset hash algorithm to obtain a fifth information digest;
[0207] After obtaining the SMS content, the second device may use a preset hash algorithm to perform a hash operation on the SMS content to obtain a fifth information summary.
[0208] S507, determining whether the first information digest is consistent with the fifth information digest, if so, executing step S508;
[0209] After obtaining the fifth information digest, the second device can determine whether the first information digest is consistent with the fifth information digest. If they are consistent, it means that the short message has not been tampered with, and the second device can execute step S508. If they are inconsistent, it means that the short message has been tampered with, and the second device can directly end the process.
[0210] S508, storing the session key and the SMS ciphertext;
[0211] After the second device determines that the SMS message has not been tampered with, the session key and the SMS ciphertext may be stored.
[0212] S509: When the user needs to view the message, the session key is used to decrypt the SMS ciphertext to obtain the message content and display it.
[0213] When the user needs to view the message, the second device can use the session key to decrypt the SMS ciphertext, obtain the message content and display it.
[0214] In this embodiment, the session key ciphertext, SMS ciphertext and digital signature are all encrypted. Even if they are leaked, the corresponding plaintext is difficult to crack, so it is difficult to cause a security accident. The second device stores the SMS ciphertext instead of the plaintext. Even if it is obtained by a third party, if the third party does not obtain the session key at the same time, it is difficult to crack the plaintext corresponding to the SMS ciphertext, thereby improving the security during storage.
[0215] See also Figure 6 , in some embodiments of the present application, Figure 5 The illustrated embodiment may further include a process in which the second device and the first device exchange public keys, and the process may specifically include the following steps S601 to S607:
[0216] S601. Generate a second public key and a second private key using an asymmetric encryption algorithm, where the second public key and the second private key are a key pair;
[0217] S602, generating a second character string according to a second generation rule;
[0218] S603: Perform a hash operation on the second public key and the second character string using a preset hash algorithm to obtain a sixth information digest;
[0219] S604, sending the second generation rule, the second public key and the sixth information digest to the first device;
[0220] S604, receiving a first generation rule, a first public key, and a second information digest sent by the first device;
[0221] S606, verifying the first public key according to the first generation rule and the second information digest to obtain a verification result;
[0222] S607: When the verification result is characterized as passed, the first public key is stored in a local database.
[0223] Steps S601 to S607 in this embodiment are similar to steps S201 to S207 in the aforementioned embodiment, and are not described again here.
[0224] See also Figure 7 In some embodiments of the present application, step S606 in the above embodiment performs verification on the first public key according to the first generation rule and the second information digest to obtain a verification result, which may specifically include the following steps S6061 to S6065:
[0225] S6061, obtaining each word and word combination order in the first generation rule;
[0226] S6062, querying the mapping word of each word through the local word mapping table;
[0227] S6063, combining the mapping words according to the word combination order to obtain a first character string;
[0228] S6064. Perform a hash operation on the first public key and the first character string using the preset hash algorithm to obtain a seventh information digest;
[0229] S6065: Generate a verification result by comparing the second information digest with the seventh information digest.
[0230] Steps S6061 to S6065 in this embodiment are similar to steps S2061 to S2065 in the aforementioned embodiment, and are not described again here.
[0231] See also Figure 8 In some embodiments of the present application, step S501 in the above embodiment receives a text message sent by the first device, which may specifically include the following steps S5011 to S5013:
[0232] S5011. Receive multiple encrypted text messages sent by the first device;
[0233] S5012, obtaining the segment identifier and segment information of each of the ciphertext text messages;
[0234] S5013. Combine the segmented information according to the order of the segment identifiers to obtain a text message.
[0235] In this embodiment, steps S5011 to S5013 are the reverse processes corresponding to steps S1071 to S1074, and will not be described in detail here.
[0236] See also Fig. 9 In the embodiments of the present application, an embodiment of the first device includes:
[0237] Acquisition unit 901, the application acquires the content of the SMS to be sent;
[0238] The first generating unit 902 is used to perform a hash operation on the SMS content using a preset hash algorithm to generate a first information digest;
[0239] The first encryption unit 903 is used to encrypt the first information summary using the local private key to obtain a digital signature;
[0240] A second generating unit 904 is used to generate a session key, where the session key is a symmetric key;
[0241] The second encryption unit 905 is used to encrypt the SMS content using the session key to obtain SMS ciphertext;
[0242] A third encryption unit 906 is used to encrypt the session key using the public key of the second device pre-stored in the local database to obtain a session key ciphertext;
[0243] The sending unit 907 is used to send the session key ciphertext, the SMS ciphertext, and the digital signature to the second device in the form of a SMS.
[0244] After the acquisition unit 901 acquires the content of the SMS to be sent, the first generation unit 902 first performs a hash operation on the SMS content using a preset hash algorithm to obtain a first information summary, and then the first encryption unit 903 uses the local private key to encrypt the first information summary to obtain a digital signature, and the second generation unit 904 generates a session key, and the second encryption unit 905 uses the session key to encrypt the SMS content to obtain an SMS ciphertext, and then the second encryption unit 905 uses the second public key to encrypt the session key to obtain a session key ciphertext, and finally the third encryption unit 906 sends the session key ciphertext, the SMS ciphertext and the digital signature to the second device in the form of an SMS. Plain text is not involved in the data transmission process, and the second device needs to verify the digital signature before performing the corresponding decryption, which greatly improves the security of SMS transmission messages.
[0245] Optionally, the first device further includes:
[0246] The exchanging unit is used to exchange the public keys of both parties with the second device.
[0247] Optionally, the switching unit includes:
[0248] A first generation module, used to generate its own public key and private key using an asymmetric encryption algorithm, wherein the public key and the private key are a key pair;
[0249] A second generating module, used to generate a first character string according to a first generating rule;
[0250] A hash module, configured to perform a hash operation on the public key and the first character string using a preset hash algorithm to obtain a second summary;
[0251] a sending module, configured to send the first generation rule, the public key and the second digest to a second device, so that the second device verifies and stores the public key;
[0252] A receiving module, configured to receive a second generation rule, a public key of the second device, and a third summary sent by the second device;
[0253] a verification module, configured to verify the public key of the second device according to the second generation rule, the public key of the second device and the third digest, to obtain a verification result;
[0254] The storage module is used to store the public key of the second device in a local database when the verification result is characterized as passed.
[0255] Optionally, the verification module is specifically used for:
[0256] Obtain each word and word combination order in the second generation rule;
[0257] Query the mapping word of each word through the local word mapping table;
[0258] Combining the mapped words according to the word combination order to obtain a second character string;
[0259] Performing a hash operation on the public key of the second device and the second character string using the preset hash algorithm to obtain a fourth digest;
[0260] A verification result is generated by comparing the third digest and the fourth digest.
[0261] Optionally, the sending unit 907 is specifically configured to:
[0262] Combining the session key ciphertext, the message ciphertext and the digital signature into information to be transmitted;
[0263] Segmenting the information to be transmitted according to the segmentation rule, and generating segment identifiers according to the order before segmentation;
[0264] Combining each segment identifier with the segment information corresponding to the segment identifier to generate a ciphertext text message;
[0265] Send all the encrypted text messages to the second device.
[0266] See also Fig.10 , another embodiment of the first device in the embodiment of the present application includes:
[0267] Processor 1001, memory 1002, input and output unit 1003 and bus 1004;
[0268] The processor 1001 is connected to the memory 1002, the input and output unit 1003 and the bus 1004;
[0269] The memory 1001 stores a program, which, when executed, causes the first device to execute the following Figures 1 to 4 Steps in the illustrated embodiment.
[0270] In this embodiment, the function of the processor 1001 is the same as that of the aforementioned Figures 1 to 4 The steps in the illustrated embodiments correspond to each other and will not be described again here.
[0271] See also Fig.11 , an embodiment of the second device in the embodiment of the present application includes:
[0272] The receiving unit 1101 is used to receive a text message sent by the first device;
[0273] The parsing unit 1102 is used to parse the SMS message to obtain the session key ciphertext, SMS ciphertext and digital signature;
[0274] A first decryption unit 1103, used to decrypt the digital signature using the first public key pre-stored in the local database to obtain a first information digest;
[0275] The second decryption unit 1104 is used to decrypt the session key ciphertext using the local private key to obtain the session key;
[0276] The third decryption unit 1105 is used to decrypt the SMS ciphertext using the session key to obtain SMS content;
[0277] A hash unit 1106 is used to perform a hash operation on the SMS content using a preset hash algorithm to obtain a fifth information digest;
[0278] A judging unit 1107, configured to judge whether the first information digest is consistent with the fifth information digest;
[0279] A storage unit 1108, configured to store the session key and the SMS ciphertext when the determination unit 1107 determines that the first information digest is consistent with the fifth information digest;
[0280] The display unit 1109 is used to decrypt the SMS ciphertext using the session key to obtain the message content and display it when the user needs to view the message.
[0281] Optionally, the second device further includes:
[0282] The exchanging unit is used to exchange the public keys of both parties with the first device.
[0283] Optionally, the switching unit includes:
[0284] A first generation module, used to generate its own public key and private key using an asymmetric encryption algorithm, wherein the public key and the private key are a key pair;
[0285] A second generating module, used to generate a second character string according to a second generating rule;
[0286] A hash module, configured to perform a hash operation on the public key and the second character string using a preset hash algorithm to obtain a third summary;
[0287] a sending module, configured to send the second generation rule, the public key and the third digest to the first device, so that the first device verifies and stores the public key;
[0288] A receiving module, configured to receive a first generation rule, a public key of the first device, and a second digest sent by the first device;
[0289] a verification module, configured to verify the public key of the first device according to the first generation rule, the public key of the first device and the second digest, and obtain a verification result;
[0290] The storage module is used to store the public key of the first device in a local database when the verification result is characterized as passed.
[0291] Optionally, the verification module is specifically used for:
[0292] Obtain each word and word combination order in the first generation rule;
[0293] Query the mapping word of each word through the local word mapping table;
[0294] Combining the mapping words according to the word combination order to obtain a first character string;
[0295] Performing a hash operation on the public key of the first device and the first character string using the preset hash algorithm to obtain a fifth digest;
[0296] A verification result is generated by comparing the second digest and the fifth digest.
[0297] Optionally, the receiving unit is specifically used for:
[0298] Receiving multiple encrypted text messages sent by the first device;
[0299] Obtaining the segment identifier and segment information of each of the ciphertext text messages;
[0300] The segmented information is combined according to the sequence of the segment identifiers to obtain a short message.
[0301] See also Fig.12 Another embodiment of the second device in the embodiment of the present application includes:
[0302] Processor 1201, memory 1202, input and output unit 1203 and bus 1204;
[0303] The processor 1201 is connected to the memory 1202, the input and output unit 1203 and the bus 1204;
[0304] The memory 1201 stores a program, which, when executed, causes the second device to execute the following steps: Figures 5 to 8 Steps in the illustrated embodiment.
[0305] In this embodiment, the function of the processor 1201 is the same as that of the aforementioned Figures 5 to 8 The steps in the illustrated embodiments correspond to each other and will not be described again here.
[0306] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0307] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0308] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0309] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0310] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, read-only memory), random access memory (RAM, random access memory), disk or optical disk and other media that can store program code.
Claims
1. A method for encrypting short messages, applied to a first device, It is characterized in that include: Get the content of the SMS to be sent; Performing a hash operation on the content of the SMS message using a preset hash algorithm to generate a first information digest; Encrypting the first information summary using the local private key to obtain a digital signature; Generate a session key, where the session key is a symmetric key; Encrypting the content of the SMS using the session key to obtain SMS ciphertext; Encrypting the session key using the public key of the second device pre-stored in the local database to obtain a session key ciphertext; The session key ciphertext, the SMS ciphertext, and the digital signature are sent to the second device in the form of an SMS.
2. The method according to claim 1, It is characterized in that Before obtaining the content of the short message to be sent, the method further includes: Exchange public keys with the second device.
3. The method according to claim 2, It is characterized in that The exchanging of the public keys of both parties with the second device includes: Generate a first public key and a first private key using an asymmetric encryption algorithm, wherein the first public key and the first private key are a key pair to each other; Generate a first character string according to a first generation rule; Performing a hash operation on the first public key and the first character string using a preset hash algorithm to obtain a second information digest; Sending the first generation rule, the first public key, and the second information digest to a second device, so that the second device verifies and stores the first public key; Receiving a second generation rule, a second public key, and a third information digest sent by the second device; Verify the second public key according to the second generation rule and the third information digest to obtain a verification result; When the verification result is characterized as passing, the second public key is stored in a local database.
4. The method according to claim 3, It is characterized in that The performing verification on the second public key according to the second generation rule and the third information digest to obtain a verification result comprises: Obtain each word and word combination order in the second generation rule; Query the mapping word of each word through the local word mapping table; Combining the mapped words according to the word combination order to obtain a second character string; Performing a hash operation on the second public key and the second character string using the preset hash algorithm to obtain a fourth information digest; A verification result is generated by comparing the third information digest and the fourth information digest.
5. The method according to any one of claims 1 to 4, It is characterized in that The sending the session key ciphertext, the SMS ciphertext, and the digital signature to the second device in the form of a SMS includes: Combining the session key ciphertext, the message ciphertext and the digital signature into information to be transmitted; Segmenting the information to be transmitted according to the segmentation rule, and generating segment identifiers according to the order before segmentation; Combining each segment identifier with the segment information corresponding to the segment identifier to generate a ciphertext text message; Send all the encrypted text messages to the second device.
6. A method for decrypting a short message, applied to a second device, It is characterized in that include: Receiving a text message sent by the first device; Parsing the SMS message to obtain the session key ciphertext, SMS ciphertext and digital signature; Decrypting the digital signature using the first public key pre-stored in the local database to obtain a first information digest; Decrypting the session key ciphertext using the local private key to obtain the session key; Decrypting the SMS ciphertext using the session key to obtain SMS content; Performing a hash operation on the content of the SMS message using a preset hash algorithm to obtain a fifth information digest; Determining whether the first information digest is consistent with the fifth information digest; If yes, storing the session key and the SMS ciphertext; When the user needs to view the message, the session key is used to decrypt the SMS ciphertext to obtain the message content and display it.
7. The method according to claim 6, It is characterized in that Before receiving the text message sent by the first device, the method further includes: Exchange public keys of both parties with the first device.
8. The method according to claim 7, It is characterized in that The exchanging of public keys of both parties with the first device includes: Generate a second public key and a second private key of the second public key and the second private key by using an asymmetric encryption algorithm, wherein the second public key and the second private key are a key pair to each other; Generate a second character string according to a second generation rule; Performing a hash operation on the second public key and the second character string using a preset hash algorithm to obtain a sixth information digest; Sending the second generation rule, the second public key, and the sixth information digest to the first device, so that the first device verifies and stores the second public key; Receiving a first generation rule, a first public key, and a second information digest sent by the first device; Verify the first public key according to the first generation rule and the second information digest to obtain a verification result; When the verification result is characterized as passing, the first public key is stored in a local database.
9. The method according to claim 8, It is characterized in that The performing verification on the first public key according to the first generation rule and the second information digest to obtain a verification result includes: Obtain each word and word combination order in the first generation rule; Query the mapping word of each word through the local word mapping table; Combining the mapping words according to the word combination order to obtain a first character string; Performing a hash operation on the first public key and the first character string using the preset hash algorithm to obtain a seventh information digest; A verification result is generated by comparing the second information digest with the seventh information digest.
10. The method according to any one of claims 6 to 9, It is characterized in that The receiving a text message sent by the first device includes: Receiving multiple encrypted text messages sent by the first device; Obtaining the segment identifier and segment information of each of the ciphertext text messages; The segmented information is combined according to the sequence of the segment identifiers to obtain a short message.
Citation Information
Cited By
Short message secure transmission method and system based on post-quantum algorithm, and electronic equipment
CN119766502A
Short message security transmission method and system based on post-quantum algorithm and electronic device
CN119766502B
