BASE64-based message data encryption and decryption method and related product

By performing the remnant operation on the length of the BASE64 encoded string to generate dynamic index value sets for secondary encryption, the problem of insufficient security of BASE64 encoding is solved, and the encryption and decryption effect with high security and low performance consumption is achieved.

CN120498713APending Publication Date: 2025-08-15CHINA TELECOM CORP LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510466362.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-14
Publication Date
2025-08-15

AI Technical Summary

Technical Problem

In the prior art, BASE64 encoding is not secure enough in data security applications and is easily cracked. The additional use of encryption methods such as DES and AES will lead to high performance overhead.

Method used

The offset number is determined by performing the remnant operation on the length of the BASE64 encoded string, and a dynamic index value set is generated using the mapped character table, and a secondary encryption is performed to generate an encrypted string, and the original text is restored through reverse operations during decryption.

Benefits of technology

Improves the security of message data, reduces performance consumption, avoids additional encoding and key use, and simplifies encoding methods.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120498713A_ABST
    Figure CN120498713A_ABST
Patent Text Reader

Abstract

The invention provides a BASE64-based message data encryption method, a BASE64-based message data decryption method and related products, and the encryption method comprises the steps: carrying out BASE64 coding on first message data to obtain a first coded character string; determining a first offset number according to the character string length of the first coded character string, and determining a first index value set corresponding to the first coded character string according to the first offset number; the first index value set comprises a plurality of first index values; querying a preset mapping character table, and determining a first encryption character corresponding to each first index value in the first index value set; and generating a first encrypted character string for the first message data according to the first encrypted character. According to the embodiment of the invention, the security of message data encryption can be improved. And additional codes and identifiers are not generated, and any additional secret key is not used. In addition, the coding mode is simple, the calculated amount is small, system resources can be saved, and therefore performance consumption is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of message data encryption and decryption, and in particular to a BASE64-based message data encryption and decryption method and related products; specifically, it relates to a BASE64-based message data encryption method, a BASE64-based message data decryption method, a BASE64-based message data encryption device, a BASE64-based message data decryption device, an electronic device, and a computer-readable storage medium. Background Art

[0002] In networks with high security requirements, Ethernet switching chips must effectively protect against unknown vulnerabilities or backdoor attacks. If conventional Ethernet switching chips perform algorithmic encryption on message data storage, they can improve system security and effectively prevent backdoor attacks.

[0003] In related technologies, message data is usually encrypted algorithmically using a key or using some specific rules.

[0004] BASE64 (Binary ASCII Standard Encoding for 64-bit) is a common data encoding method that can convert non-ASCII (American Standard Code for Information Interchange) characters into ASCII characters. Its fast encoding speed is required in many situations, such as delivering certificates, email data, and HTTP (Hypertext Transfer Protocol) data transmission.

[0005] Because BASE64 encoding is unreadable, it is used for encryption and decryption in the field of data security. However, since its encoding principle is open to the public and decoding tools are very common, in actual data security applications, if BASE64 is used for encoding, it needs to be combined with other encryption and decryption methods, such as DES (Data Encryption Standard) and AES (Advanced Encryption Standard). It is rarely used alone for encryption and decryption because its security is not reliable enough and it can be easily intercepted and cracked during transmission. If DES, AES and other encryption methods are used for additional encryption, the performance overhead is relatively large. Summary of the Invention

[0006] In view of the above problems, a message data encryption method based on BASE64, a message data decryption method based on BASE64, a message data encryption device based on BASE64, a message data decryption device based on BASE64, an electronic device, and a computer-readable storage medium are proposed to overcome the above problems or at least partially solve the above problems, including:

[0007] A message data encryption method based on BASE64, the encryption method comprising:

[0008] Performing BASE64 encoding on the first message data to obtain a first encoded character string;

[0009] Determining a first offset number according to the string length of the first encoded string, and determining a first index value set corresponding to the first encoded string according to the first offset number; the first index value set includes a plurality of first index values;

[0010] Querying a preset mapping character table to determine a first encrypted character corresponding to each first index value in the first index value set;

[0011] A first encrypted character string is generated for the first message data according to the first encrypted character.

[0012] Optionally, determining a first index value set corresponding to the first encoded character string according to the first offset number includes:

[0013] Determining a second index value for each character in the first encoded string;

[0014] The first index value is determined according to the second index value and the first offset number, and the first index value set is determined according to the first index value.

[0015] Optionally, determining the first index value according to the second index value and the first offset number includes:

[0016] For every first offset number of characters, calculate the sum of the second index values of the consecutive first offset number and the first offset number to obtain the first index value;

[0017] The determining the first index value set according to the first index value includes:

[0018] The first index value set is determined based on the second index value whose sum with the first offset number is not calculated and the first index value.

[0019] Optionally, determining the first index value according to the second index value and the first offset number includes:

[0020] The sum of each second index value and the first offset number is calculated to obtain the first index value corresponding to each second index value.

[0021] Optionally, determining the first offset number according to the string length of the first encoded string includes:

[0022] Perform a modulo operation on the character string length and a preset value to obtain the first offset number.

[0023] The embodiment of the present invention further provides a method for decrypting message data based on BASE64, the decryption method comprising:

[0024] Obtaining a first encrypted string to be decrypted, where the first encrypted string is encrypted based on the above-mentioned BASE64-based message data encryption method;

[0025] Determining a first offset number according to the length of the first encrypted string, and determining a first index value set corresponding to the first encrypted string; the first index value set includes a plurality of first index values;

[0026] Determine, according to the first offset number and the first index value set, a second index value corresponding to each first index value;

[0027] Querying a preset mapping character table to determine the first decrypted character corresponding to each second index value;

[0028] Generate first message data according to the first decrypted character.

[0029] The embodiment of the present invention further provides a message data encryption device based on BASE64, the encryption device comprising:

[0030] An encoding module, configured to perform BASE64 encoding on the first message data to obtain a first encoded character string;

[0031] A secondary mapping module is used to determine a first offset number based on the string length of the first encoded string, and determine a first index value set corresponding to the first encoded string based on the first offset number; the first index value set includes multiple first index values; query a preset mapping character table to determine the first encrypted character corresponding to each first index value in the first index value set; and generate a first encrypted string for the first message data based on the first encrypted character.

[0032] The embodiment of the present invention further provides a message data decryption device based on BASE64, the decryption device comprising:

[0033] a demapping module configured to obtain a first encrypted string to be decrypted, the first encrypted string being encrypted using the BASE64-based message data encryption method described above; determine a first offset number based on a string length of the first encrypted string, and determine a first index value set corresponding to the first encrypted string, the first index value set including a plurality of first index values; determine a second index value corresponding to each first index value based on the first offset number and the first index value set; and query a preset mapping character table to determine a first decrypted character corresponding to each second index value;

[0034] A decoding module is used to generate first message data according to the first decrypted character.

[0035] An embodiment of the present invention also provides an electronic device, including a processor, a memory, and a computer program stored in the memory and capable of running on the processor. When the computer program is executed by the processor, it implements the above-mentioned BASE64-based message data encryption method or the above-mentioned BASE64-based message data decryption method.

[0036] An embodiment of the present invention further provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, the computer program implements the above-mentioned BASE64-based message data encryption method or the above-mentioned BASE64-based message data decryption method.

[0037] The embodiments of the present invention have the following advantages:

[0038] In an embodiment of the present invention, first message data is BASE64 encoded to obtain a first encoded string; a first offset number is determined based on the string length of the first encoded string, and a first index value set corresponding to the first encoded string is determined based on the first offset number; the first index value set includes multiple first index values; a preset mapping character table is queried to determine the first encrypted character corresponding to each first index value in the first index value set; and a first encrypted string for the first message data is generated based on the first encrypted character.

[0039] Through the embodiment of the present invention, the randomness of the length of different messages can be utilized in combination with the existing encoding method to generate a first index value set; this is equivalent to adding a "dynamic key" to improve the security of message data encryption.

[0040] Furthermore, the embodiment of the present invention performs secondary encryption, but the final encoding length is the same as the BASE64 encoding, and no additional codes and identifiers are generated, nor any additional keys are used.

[0041] In addition, the encoding method of the embodiment of the present invention is simple and the calculation amount is small, which is conducive to saving system resources and thus reducing performance consumption. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] In order to more clearly illustrate the technical solution of the present invention, the following briefly introduces the drawings required for use in the description of the present invention. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0043] Figure 1 This is a flowchart of a method for encrypting message data based on BASE64 according to an embodiment of the present invention;

[0044] Figure 2 This is a flowchart of another method for encrypting message data based on BASE64 according to an embodiment of the present invention;

[0045] Figure 3 This is a flowchart of another method for encrypting message data based on BASE64 according to an embodiment of the present invention;

[0046] Figure 4 This is a flowchart of another method for encrypting message data based on BASE64 according to an embodiment of the present invention;

[0047] Figure 5 This is a flowchart of a method for decrypting message data based on BASE64 according to an embodiment of the present invention;

[0048] Figure 6 This is a flowchart of encryption and decryption steps according to an embodiment of the present invention;

[0049] Figure 7 1 is a schematic structural diagram of a BASE64-based message data encryption device according to an embodiment of the present invention;

[0050] Figure 8 The present invention is a schematic structural diagram of a BASE64-based message data decryption device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0051] To make the above-mentioned objects, features, and advantages of the present invention more clearly understood, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments. It should be understood that the embodiments described are only a portion of the embodiments of the present invention, not all of them. All other embodiments derived by persons of ordinary skill in the art based on the embodiments of the present invention without inventive effort are also within the scope of protection of the present invention.

[0052] Reference Figure 1, shows a flowchart of a method for encrypting message data based on BASE64 according to an embodiment of the present invention, which may include the following steps:

[0053] Step 101: Perform BASE64 encoding on first message data to obtain a first encoded character string.

[0054] Among them, the first message data may refer to the message data currently to be encrypted; the message data may refer to an information unit formatted according to the protocol specification and used for transmission, which may include control information (such as source / destination address, check code) and payload (actual transmitted data content), etc. The embodiment of the present invention does not impose any restrictions on this.

[0055] After obtaining the first message data to be encrypted, the first message data may be firstly BASE64-encoded to obtain a first encoded character string.

[0056] Step 102: Determine a first offset number based on the string length of the first encoded string, and determine a first index value set corresponding to the first encoded string based on the first offset number; the first index value set includes multiple first index values.

[0057] In actual applications, since the BASE64 encoding principle is open to the public and decoding tools are very common, if BASE64 is used for encoding, other encryption and decryption methods such as DES and AES need to be combined in related technologies. However, if DES, AES and other heavy encryption methods are used in addition, the performance overhead is relatively large.

[0058] In order to reduce performance overhead, the embodiment of the present invention can first determine the first offset number based on the string length of the first encoded string; since different message lengths are random, it is equivalent to being based on a "dynamic key", thereby improving the encryption security of the embodiment of the present invention.

[0059] After determining the first offset number, the first index value corresponding to each character in the first encoded string can be determined based on the first offset number, and a first index value set can be determined based on the multiple first index values.

[0060] Step 103: query a preset mapping character table to determine the first encrypted character corresponding to each first index value in the first index value set.

[0061] Next, a preset mapping character table may be queried to determine the first encrypted character corresponding to each first index value in the first index value set.

[0062] Step 104: Generate a first encrypted character string for the first message data according to the first encrypted character.

[0063] After determining the first encrypted characters corresponding to the first index values, a first encrypted string may be composed according to the multiple first encrypted characters, that is, the first encrypted string obtained by encrypting the first message data.

[0064] In an embodiment of the present invention, first message data is BASE64 encoded to obtain a first encoded string; a first offset number is determined based on the string length of the first encoded string, and a first index value set corresponding to the first encoded string is determined based on the first offset number; the first index value set includes multiple first index values; a preset mapping character table is queried to determine the first encrypted character corresponding to each first index value in the first index value set; and a first encrypted string for the first message data is generated based on the first encrypted character.

[0065] Through the embodiment of the present invention, the randomness of the length of different messages can be utilized in combination with the existing encoding method to generate a first index value set; this is equivalent to adding a "dynamic key" to improve the security of message data encryption.

[0066] Furthermore, the embodiment of the present invention performs secondary encryption, but the final encoding length is the same as the BASE64 encoding, and no additional codes and identifiers are generated, nor any additional keys are used.

[0067] In addition, the encoding method of the embodiment of the present invention is simple and the calculation amount is small, which is conducive to saving system resources and thus reducing performance consumption.

[0068] Reference Figure 2 , shows a flowchart of another method for encrypting message data based on BASE64 according to an embodiment of the present invention, which may include the following steps:

[0069] Step 201: Perform BASE64 encoding on first message data to obtain a first encoded character string.

[0070] After obtaining the first message data to be encrypted, the first message data may be firstly BASE64-encoded to obtain a first encoded character string.

[0071] Exemplarily, the first message data may be converted into binary first: each character of the first message data may be converted into a corresponding 8-bit binary (ASCII code).

[0072] Then, split it into groups of 6 bits: start from the beginning of the binary data, divide it into groups of 6 bits, and fill in 0 if the last group has less than 6 bits.

[0073] Next, you can look up the BASE64 table for conversion: convert each group of 6 binary digits into decimal, and then look up the corresponding character in the BASE64 table.

[0074] Add equal signs: If the length of the original data is not a multiple of 3, add one or two = signs at the end of the encoded result.

[0075] Step 202: Perform a modulo operation on the character string length and a preset value to obtain a first offset number.

[0076] In some feasible embodiments, after the first encoded character string is determined, the character string length of the first encoded character string may be determined.

[0077] Then, a modulo operation may be performed on the string length and a preset value, and the remainder is used as the first offset number.

[0078] For example, if the index values in the mapping character table are a set of numbers in sequence, the preset value may be the total number of the numbers in the set. For example, if the index values in the mapping character table are all integers from 0 to 63, the preset value may be 64.

[0079] If the string length is 8, the first offset number is 8; if the string length is 0, the first offset number is 64. This embodiment of the present invention does not impose any limitation on this.

[0080] Step 203: Determine the second index value of each character in the first encoded string.

[0081] After determining the first encoded string, the second index value of each character in the first encoded string may be determined based on a preset character mapping table. For example, the preset character mapping table may be as shown in Table 1 below:

[0082] Table 1:

[0083]

[0084]

[0085] Based on Table 1, assuming that the first encoded string is cmV0dXJU, the corresponding second index values are: 28, 38, 21, 52, 29, 23, 9 and 20 respectively.

[0086] Step 204: Determine the first index value according to the second index value and the first offset number, and determine the first index value set according to the first index value.

[0087] In some feasible embodiments, after determining the second index value corresponding to each character in the first encoded string, the first index value corresponding to each second index value may be determined according to the second index value and the first offset number.

[0088] Then, a first index value set may be determined based on the multiple first index values.

[0089] Step 205: Query a preset mapping character table to determine the first encrypted character corresponding to each first index value in the first index value set.

[0090] After the first index value set is determined, a preset mapping character table (eg, Table 1 above) may be queried to determine the first encrypted character corresponding to each first index value in the first index value set.

[0091] Exemplarily, assuming that the first index value set is: [36, 46, 29, 60, 37, 31, 128], based on Table 1, it can be determined that the first encrypted characters are [k, u, d, 8, i, f, R, c] respectively.

[0092] Step 206: Generate a first encrypted character string for the first message data according to the first encrypted character.

[0093] After determining multiple first encryption characters, a first encryption string for the first message data can be generated based on these multiple first encryption characters; assuming that the first encryption characters are [k, u, d, 8, i, f, R, c], a first encryption string can be generated: kud8ifRc, which is not limited in this embodiment of the present invention.

[0094] In an embodiment of the present invention, first message data is BASE64 encoded to obtain a first encoded string; a modulo operation is performed on the string length and a preset value to obtain a first offset number; a second index value of each character in the first encoded string is determined; a first index value is determined based on the second index value and the first offset number, and a first index value set is determined based on the first index value; and a preset mapping character table is queried to determine the first encrypted character corresponding to each first index value in the first index value set.

[0095] Through the embodiment of the present invention, the randomness of the length of different messages can be utilized in combination with the existing encoding method to generate a first index value set; this is equivalent to adding a "dynamic key" to improve the security of message data encryption.

[0096] Furthermore, the embodiment of the present invention performs secondary encryption, but the final encoding length is the same as the BASE64 encoding, and no additional codes and identifiers are generated, nor any additional keys are used.

[0097] In addition, the encoding method of the embodiment of the present invention is simple and the calculation amount is small, which is conducive to saving system resources and thus reducing performance consumption.

[0098] Reference Figure 3 , shows a flowchart of another method for encrypting message data based on BASE64 according to an embodiment of the present invention, which may include the following steps:

[0099] Step 301: Perform BASE64 encoding on first message data to obtain a first encoded character string.

[0100] After obtaining the first message data to be encrypted, the first message data may be firstly BASE64-encoded to obtain a first encoded character string.

[0101] Step 302: Perform a modulo operation on the character string length and a preset value to obtain a first offset number.

[0102] In some feasible embodiments, after the first encoded character string is determined, the character string length of the first encoded character string may be determined.

[0103] Then, a modulo operation may be performed on the character string length and a preset value, and the remainder obtained by the modulo operation is used as the first offset number.

[0104] Step 303: Determine the second index value of each character in the first encoded string.

[0105] After the first encoded character string is determined, the second index value of each character in the first encoded character string may be determined based on a preset mapping character table.

[0106] Step 304: Calculate the sum of the second index values of the consecutive first offset number of characters and the first offset number to obtain the first index value.

[0107] After determining the second index value of each character in the first encoded string, a secondary mapping can be performed with an interval and length equal to the first offset number. That is, starting from the starting position, the sum of the second index values corresponding to the consecutive first offset number of characters and the first offset number is calculated respectively, thereby obtaining the first index values corresponding to these second index values.

[0108] Then, the second index values corresponding to the first offset number of characters are not mapped again, and so on, until all the second index values are processed.

[0109] Step 305: Determine a first index value set based on the second index value whose sum with the first offset number is not calculated and the first index value.

[0110] After all the second index values are processed, the first index value and the second index value not summed with the first offset number are obtained.

[0111] Then, a first index value set may be obtained based on the second index value that has not been summed with the first offset number and the first index value.

[0112] Specifically, the second index value whose sum with the first offset number is not calculated may be used as the first index value in the first index value set, and the calculated first index value may be used as an element in the first index value set.

[0113] Step 306: query a preset mapping character table to determine the first encrypted character corresponding to each first index value in the first index value set.

[0114] After obtaining the first index value set, the preset mapping character table may be queried one by one based on the first index values in the first index value set to determine the first encrypted character corresponding to each first index value in the first index value set.

[0115] Step 307: Generate a first encrypted character string for the first message data according to the first encrypted character.

[0116] After determining the plurality of first encrypted characters, a first encrypted character string for the first message data may be generated based on the plurality of first encrypted characters.

[0117] In an embodiment of the present invention, first message data is BASE64 encoded to obtain a first encoded string; a modulo operation is performed on the string length and a preset value to obtain a first offset number; a second index value of each character in the first encoded string is determined; every first offset number of characters, the sum of the second index values of the consecutive first offset number and the first offset number is calculated to obtain a first index value; a first index value set is determined based on the second index values whose sum with the first offset number is not calculated and the first index value; a preset mapping character table is queried to determine the first encrypted character corresponding to each first index value in the first index value set; and a first encrypted string for the first message data is generated based on the first encrypted character.

[0118] Through the embodiment of the present invention, the randomness of the length of different messages can be utilized in combination with the existing encoding method to generate a first index value set; this is equivalent to adding a "dynamic key" to improve the security of message data encryption.

[0119] Furthermore, the embodiment of the present invention performs secondary encryption, but the final encoding length is the same as the BASE64 encoding, and no additional codes and identifiers are generated, nor any additional keys are used.

[0120] In addition, the encoding method of the embodiment of the present invention is simple and the calculation amount is small, which is conducive to saving system resources and thus reducing performance consumption.

[0121] Reference Figure 4 , shows a flowchart of another method for encrypting message data based on BASE64 according to an embodiment of the present invention, which may include the following steps:

[0122] Step 401: Perform BASE64 encoding on first message data to obtain a first encoded character string.

[0123] After obtaining the first message data to be encrypted, the first message data may be firstly BASE64-encoded to obtain a first encoded character string.

[0124] Step 402: Perform a modulo operation on the character string length and a preset value to obtain a first offset number.

[0125] In some feasible embodiments, after the first encoded character string is determined, the character string length of the first encoded character string may be determined.

[0126] Then, a modulo operation may be performed on the character string length and a preset value, and the remainder obtained by the modulo operation is used as the first offset number.

[0127] Step 403: Determine the second index value of each character in the first encoded string.

[0128] After the first encoded character string is determined, the second index value of each character in the first encoded character string may be determined based on a preset mapping character table.

[0129] Step 404: Calculate the sum of each second index value and the first offset number to obtain the first index value corresponding to each second index value.

[0130] In some feasible embodiments, after determining the second index value of each character in the first encoded string, the sum of the second index value and the first offset number can be calculated for each second index value to obtain the first index value corresponding to each second index value.

[0131] Then, a first index value set may be generated based on the obtained multiple first index values, which is not limited in this embodiment of the present invention.

[0132] Step 405: query a preset mapping character table to determine the first encrypted character corresponding to each first index value in the first index value set.

[0133] After obtaining the first index value set, the preset mapping character table may be queried one by one based on the first index values in the first index value set to determine the first encrypted character corresponding to each first index value in the first index value set.

[0134] Step 406: Generate a first encrypted character string for the first message data according to the first encrypted character.

[0135] After determining the plurality of first encrypted characters, a first encrypted character string for the first message data may be generated based on the plurality of first encrypted characters.

[0136] In an embodiment of the present invention, first message data is BASE64 encoded to obtain a first encoded string; a modulo operation is performed on the string length and a preset value to obtain a first offset number; a second index value of each character in the first encoded string is determined; the sum of each second index value and the first offset number is calculated to obtain a first index value corresponding to each second index value; a preset mapping character table is queried to determine a first encrypted character corresponding to each first index value in a first index value set; and a first encrypted string for the first message data is generated based on the first encrypted character.

[0137] Through the embodiment of the present invention, the randomness of the length of different messages can be utilized in combination with the existing encoding method to generate a first index value set; this is equivalent to adding a "dynamic key" to improve the security of message data encryption.

[0138] Furthermore, the embodiment of the present invention performs secondary encryption, but the final encoding length is the same as the BASE64 encoding, and no additional codes and identifiers are generated, nor any additional keys are used.

[0139] In addition, the encoding method of the embodiment of the present invention is simple and the calculation amount is small, which is conducive to saving system resources and thus reducing performance consumption.

[0140] Based on the above encryption method, the embodiment of the present invention also provides a corresponding decryption method; specifically, refer to Figure 5 , shows a flowchart of the steps of a BASE64-based message data decryption method according to an embodiment of the present invention.

[0141] like Figure 5 As shown, the BASE64-based message data decryption method may include the following steps:

[0142] Step 501: Obtain a first encrypted string to be decrypted, where the first encrypted string is encrypted based on a BASE64-based message data encryption method according to any of the above embodiments.

[0143] In practical applications, when the first message data is transmitted, the first message data may be encrypted using a BASE64-based message data encryption method as described in any of the above embodiments, thereby obtaining a first encrypted string.

[0144] Exemplarily, after obtaining the first message data to be encrypted, the first message data can be BASE64 encoded to obtain a first encoded string. Then, the first offset number can be determined based on the string length of the first encoded string; since different message lengths are random, it is equivalent to being based on a "dynamic key", which improves the encryption security of the embodiment of the present invention. After determining the first offset number, the first index value corresponding to each character in the first encoded string can be determined based on the first offset number, and the first index value set can be determined based on these multiple first index values. Next, a preset mapping character table can be queried to determine the first encrypted character corresponding to each first index value in the first index value set. After determining the first encrypted character corresponding to each first index value, the first encrypted string can be composed based on these multiple first encrypted characters, that is, the first encrypted string obtained after encrypting the first message data.

[0145] In another example, after obtaining the first message data to be encrypted, the first message data can be first BASE64-encoded to obtain a first encoded string. After determining the first encoded string, the string length of the first encoded string can be determined. Then, a modulo operation can be performed on the string length and a preset value, and the remainder can be used as a first offset number. After determining the first encoded string, the second index value of each character in the first encoded string can be determined based on a preset mapping character table. After determining the second index value corresponding to each character in the first encoded string, the first index value corresponding to each second index value can be determined based on the second index value and the first offset number. Then, based on these multiple first index values, a first index value set can be determined. After determining the first index value set, the preset mapping character table can be queried to determine the first encrypted character corresponding to each first index value in the first index value set. After determining the multiple first encrypted characters, a first encrypted string for the first message data can be generated based on these multiple first encrypted characters.

[0146] In another example, after obtaining the first message data to be encrypted, the first message data can be first BASE64-encoded to obtain a first encoded string. After determining the first encoded string, the string length of the first encoded string can be determined. Then, a modulo operation can be performed on the string length and a preset value, and the remainder obtained by the modulo operation can be used as the first offset number. After determining the first encoded string, the second index value of each character in the first encoded string can be determined based on a preset mapping character table. After determining the second index value of each character in the first encoded string, a secondary mapping can be performed with an interval and length equal to the first offset number. That is, starting from the starting position, the sum of the second index values corresponding to consecutive characters of the first offset number and the first offset number is calculated, thereby obtaining the first index values corresponding to these second index values. Then, the second index values corresponding to characters separated by the first offset number are not subjected to secondary mapping, and so on, until all second index values are processed. After all second index values are processed, the first index value and the second index value not summed with the first offset number are obtained. Then, a first index value set can be obtained based on the second index value, not summed with the first offset number, and the first index value. After obtaining the first index value set, a preset mapping character table can be queried one by one based on the first index values in the first index value set to determine the first encryption character corresponding to each first index value in the first index value set. After determining multiple first encryption characters, a first encrypted string for the first message data can be generated based on the multiple first encryption characters.

[0147] In another example, after obtaining the first message data to be encrypted, the first message data can be BASE64 encoded to obtain a first encoded string. After determining the first encoded string, the string length of the first encoded string can be determined. A modulo operation can then be performed on the string length and a preset value, and the remainder obtained from the modulo operation can be used as a first offset. After determining the first encoded string, the second index value of each character in the first encoded string can be determined based on a preset mapping character table. After determining the second index value of each character in the first encoded string, the sum of the second index value and the first offset can be calculated for each second index value to obtain the first index value corresponding to each second index value. A first index value set can then be generated based on the obtained multiple first index values, although this is not limited in this embodiment of the present invention. After obtaining the first index value set, the preset mapping character table can be queried one by one based on the first index values in the first index value set to determine the first encrypted character corresponding to each first index value in the first index value set. After determining the plurality of first encryption characters, a first encryption string for the first message data may be generated based on the plurality of first encryption characters. The embodiment of the present invention does not limit the specific encryption method.

[0148] After the first encrypted string is transmitted, it needs to be decrypted to obtain the first message data therein; specifically, the first encrypted string to be decrypted can be obtained first.

[0149] Step 502: Determine a first offset number based on the length of the first encrypted string, and determine a first index value set corresponding to the first encrypted string; the first index value set includes multiple first index values.

[0150] After obtaining the first encrypted string, the string length of the characters included in the first encrypted string may be determined first; then, the first offset number may be determined based on the string length.

[0151] Illustratively, since the encryption process does not generate additional characters, the string length of the first encrypted string is consistent with the string length of the first encoded string, so the offset number determined based on the same string length is also consistent.

[0152] Based on this, the embodiment of the present invention can determine the first offset number based on the string length of the first encrypted string.

[0153] In some feasible embodiments, after obtaining the first encrypted string, the first index value corresponding to each character in the first encrypted string may be determined based on a preset mapping character table, and a first index value set having the first index value as an element may be obtained.

[0154] Step 503: Determine the second index value corresponding to each first index value according to the first offset number and the first index value set.

[0155] After obtaining the first offset number and the first index value set, the second index value corresponding to the first index value can be inferred based on the first offset number.

[0156] Exemplarily, if the encryption process is to calculate the sum of each second index value and the first offset number, the decryption process is also to calculate the difference between each first index value and the first offset number to obtain the second index value.

[0157] Step 504: query a preset mapping character table to determine the first decrypted character corresponding to each second index value.

[0158] After obtaining the second index value, a preset mapping character table may be queried to determine the first decrypted character corresponding to each second index value, ie, the character in the first message data.

[0159] Step 505: Generate first message data according to the first decrypted character.

[0160] After obtaining the first decrypted characters, the first decrypted characters may be concatenated in sequence to obtain the first message data.

[0161] For example, the above encryption and decryption methods are further described below using a specific example:

[0162] Encryption process:

[0163] 1. Obtain the first message data to be encrypted.

[0164] 2. Perform BASE64 encoding on the first message data to obtain a BASE64 encoded string (ie, a first encoded string).

[0165] 3. Calculate the string length n of the first encoded string after encoding, and then perform a modulo operation with 64 to obtain the first offset number m; if n is 0, assign m to 64.

[0166] 4. Perform a secondary mapping with an interval and length of m (i.e., starting from the starting position, calculate the sum of the second index values of m consecutive characters in the first encoded string and the first offset number m to obtain the second index value; then, without summing up after an interval of m characters, sum the second index values of the subsequent m characters; and repeat this cycle). Based on the preset mapping character table and the first index value, and the second index value not calculated and summed, determine the first encrypted character, and thus obtain the first encrypted string.

[0167] Decoding process:

[0168] 1. Calculate the length n of the first encrypted string, and then perform a modulo operation with 64 to obtain the first offset m. If n is 0, assign m a value of 64.

[0169] 2. Perform an inverse mapping of the first index values corresponding to each character in the first encrypted string, with both an interval and a length of m. Specifically, starting from the starting position, calculate the difference between the first index values of m consecutive characters in the first encrypted string and the first offset m to obtain the second index value. Then, without calculating the difference between every m characters, calculate the difference between the first index values of the next m characters, and repeat this cycle.

[0170] Based on the preset mapping character table and the second index value, and the first index value without calculating the difference, a first decryption character is determined to obtain the first message data.

[0171] Take the first message data "RETURN" as an example and encrypt it:

[0172] 1. Perform conventional BASE64 encoding on the original string RETURN to obtain the BASE64 encoded string: cmV0dXJU. The decimal values corresponding to its characters are shown in Table 1.

[0173] 2. The length n of the encoded string is obtained as 8, and the first offset value m is obtained as 8 after taking the remainder (here and the subsequent remainder refer to the remainder modulo 64).

[0174] 3. Perform an offset modulo calculation on the value corresponding to the BASE64 encoded string with a length and interval of m to obtain the decimal value corresponding to the offset modulo. At this time, all values still have a one-to-one mapping relationship with the BASE64 character table.

[0175] 4. Perform secondary mapping on all offset modulo characters to obtain the encrypted string kud8ifRc.

[0176] The decryption process is as follows:

[0177] 1. Get the first encrypted string "kud8ifRc", the string length n is 8, and take the remainder (here and the subsequent remainder refer to the remainder modulo 64) to obtain the first offset value m, which is 8.

[0178] 2. Obtain a first index value by using a preset mapping character table.

[0179] 3. De-map characters with length and interval both equal to m to obtain the normal BASE64 string cmV0dXJU (i.e., the first decrypted character).

[0180] 4. Use BASE64 decoding rules to decode and obtain the original string RETURN (i.e., the first message data).

[0181] Table 2 shows the correspondence between the first message data (RETURN), the first encoded string (cmV0dXJU), the first index value, the second index value, and the first encrypted character (kud8ifRc) in the above example:

[0182] Table 2:

[0183]

[0184]

[0185] For example, Figure 6 , shows a flowchart of encryption and decryption steps according to an embodiment of the present invention:

[0186] First, the first message data is BASE64-encoded to obtain a first encoded string. Then, interval secondary mapping is performed based on the first offset number to obtain a first encrypted string. Specifically, the interval secondary mapping can be used to perform an inverse mapping of the first index value corresponding to each character in the first encrypted string, with both an interval and a length of m. Specifically, starting from the starting position, the difference between the first index value of each consecutive m characters in the first encrypted string and the first offset number m is calculated to obtain a second index value. Then, the difference between the first index values of the next m characters is calculated without performing the difference between the first index values of the next m characters, and this cycle is repeated.

[0187] During decryption, the first encrypted string may be de-mapped to obtain a first encoded string; and then BASE64 decoding may be performed to obtain first message data.

[0188] In an embodiment of the present invention, a first encrypted string to be decrypted is obtained, where the first encrypted string is encrypted based on a BASE64-based message data encryption method such as any one of the above embodiments; a first offset number is determined based on the string length of the first encrypted string, and a first index value set corresponding to the first encrypted string is determined; the first index value set includes multiple first index values; based on the first offset number and the first index value set, a second index value corresponding to each first index value is determined; a preset mapping character table is queried to determine a first decryption character corresponding to each second index value; and first message data is generated based on the first decryption character.

[0189] Through the embodiment of the present invention, the randomness of the length of different messages can be utilized in combination with the existing encoding method to generate a first index value set; this is equivalent to adding a "dynamic key" to improve the security of message data encryption.

[0190] Furthermore, the embodiment of the present invention performs secondary encryption, but the final encoding length is the same as the BASE64 encoding, and no additional codes and identifiers are generated, nor any additional keys are used.

[0191] In addition, the encoding method of the embodiment of the present invention is simple and the calculation amount is small, which is conducive to saving system resources and thus reducing performance consumption.

[0192] It should be noted that for the sake of simplicity, the method embodiments are described as a series of actions. However, those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in this specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.

[0193] Reference Figure 7, shows a schematic structural diagram of a message data encryption device based on BASE64 according to an embodiment of the present invention, which may include the following modules:

[0194] The encoding module 701 is configured to perform BASE64 encoding on the first message data to obtain a first encoded character string;

[0195] The secondary mapping module 702 is used to determine a first offset number based on the string length of the first encoded string, and determine a first index value set corresponding to the first encoded string based on the first offset number; the first index value set includes multiple first index values; query a preset mapping character table to determine the first encrypted character corresponding to each first index value in the first index value set; and generate a first encrypted string for the first message data based on the first encrypted character.

[0196] In an optional embodiment of the present invention, the secondary mapping module 702 is used to determine the second index value of each character in the first encoded string; determine the first index value based on the second index value and the first offset number, and determine the first index value set based on the first index value.

[0197] In an optional embodiment of the present invention, the secondary mapping module 702 is used to calculate the sum of the second index values of the consecutive first offset number and the first offset number every first offset number of characters to obtain the first index value; and determine the first index value set based on the second index value whose sum with the first offset number is not calculated and the first index value.

[0198] In an optional embodiment of the present invention, the secondary mapping module 702 is configured to calculate the sum of each second index value and the first offset number to obtain the first index value corresponding to each second index value.

[0199] In an optional embodiment of the present invention, the secondary mapping module 702 is configured to perform a modulo operation on the character string length and a preset value to obtain a first offset number.

[0200] In an embodiment of the present invention, first message data is BASE64 encoded to obtain a first encoded string; a first offset number is determined based on the string length of the first encoded string, and a first index value set corresponding to the first encoded string is determined based on the first offset number; the first index value set includes multiple first index values; a preset mapping character table is queried to determine the first encrypted character corresponding to each first index value in the first index value set; and a first encrypted string for the first message data is generated based on the first encrypted character.

[0201] Through the embodiment of the present invention, the randomness of the length of different messages can be utilized in combination with the existing encoding method to generate a first index value set; this is equivalent to adding a "dynamic key" to improve the security of message data encryption.

[0202] Furthermore, the embodiment of the present invention performs secondary encryption, but the final encoding length is the same as the BASE64 encoding, and no additional codes and identifiers are generated, nor any additional keys are used.

[0203] In addition, the encoding method of the embodiment of the present invention is simple and the calculation amount is small, which is conducive to saving system resources and thus reducing performance consumption.

[0204] Reference Figure 8 , shows a schematic structural diagram of a message data decryption device based on BASE64 according to an embodiment of the present invention, which may include the following modules:

[0205] The de-mapping module 801 is configured to obtain a first encrypted string to be decrypted, the first encrypted string being encrypted using the above-described BASE64-based message data encryption method; determine a first offset number based on the string length of the first encrypted string, and determine a first index value set corresponding to the first encrypted string; the first index value set including a plurality of first index values; determine a second index value corresponding to each first index value based on the first offset number and the first index value set; and query a preset mapping character table to determine a first decrypted character corresponding to each second index value.

[0206] The decoding module 802 is configured to generate first message data according to the first decrypted character.

[0207] In an embodiment of the present invention, a first encrypted string to be decrypted is obtained, where the first encrypted string is encrypted based on a BASE64-based message data encryption method such as any one of the above embodiments; a first offset number is determined based on the string length of the first encrypted string, and a first index value set corresponding to the first encrypted string is determined; the first index value set includes multiple first index values; based on the first offset number and the first index value set, a second index value corresponding to each first index value is determined; a preset mapping character table is queried to determine a first decryption character corresponding to each second index value; and first message data is generated based on the first decryption character.

[0208] Through the embodiment of the present invention, the randomness of the length of different messages can be utilized in combination with the existing encoding method to generate a first index value set; this is equivalent to adding a "dynamic key" to improve the security of message data encryption.

[0209] Furthermore, the embodiment of the present invention performs secondary encryption, but the final encoding length is the same as the BASE64 encoding, and no additional codes and identifiers are generated, nor any additional keys are used.

[0210] In addition, the encoding method of the embodiment of the present invention is simple and the calculation amount is small, which is conducive to saving system resources and thus reducing performance consumption.

[0211] An embodiment of the present invention also provides an electronic device, including a processor, a memory, and a computer program stored in the memory and capable of running on the processor. When the computer program is executed by the processor, it implements the above-mentioned BASE64-based message data encryption method or the above-mentioned BASE64-based message data decryption method.

[0212] An embodiment of the present invention further provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, the computer program implements the above-mentioned BASE64-based message data encryption method or the above-mentioned BASE64-based message data decryption method.

[0213] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0214] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0215] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, apparatus, or computer program products. Thus, embodiments of the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, embodiments of the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0216] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the process in the flowchart and / or block diagram. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0217] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.

[0218] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0219] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they become aware of the basic creative concepts. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.

[0220] Finally, it should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that includes a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or terminal device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or terminal device that includes the element.

[0221] The above provides a detailed introduction to a BASE64-based message data encryption method, a BASE64-based message data decryption method, a BASE64-based message data encryption device, a BASE64-based message data decryption device, an electronic device and a computer-readable storage medium. Specific examples are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as limiting the present invention.

Claims

1. A message data encryption method based on BASE64, characterized in that: The encryption method includes: Performing BASE64 encoding on the first message data to obtain a first encoded character string; Determining a first offset number according to the string length of the first encoded string, and determining a first index value set corresponding to the first encoded string according to the first offset number; the first index value set includes a plurality of first index values; Querying a preset mapping character table to determine a first encrypted character corresponding to each first index value in the first index value set; A first encrypted character string is generated for the first message data according to the first encrypted character.

2. The method according to claim 1, characterized in that The determining, according to the first offset number, a first index value set corresponding to the first encoded string includes: Determining a second index value for each character in the first encoded string; The first index value is determined according to the second index value and the first offset number, and the first index value set is determined according to the first index value.

3. The method according to claim 2, characterized in that The determining the first index value according to the second index value and the first offset number includes: For every first offset number of characters, calculate the sum of the second index values of the consecutive first offset number and the first offset number to obtain the first index value; The determining the first index value set according to the first index value includes: The first index value set is determined based on the second index value whose sum with the first offset number is not calculated and the first index value.

4. The method according to claim 2, characterized in that The determining the first index value according to the second index value and the first offset number includes: The sum of each second index value and the first offset number is calculated to obtain the first index value corresponding to each second index value.

5. The method according to claim 1, characterized in that The determining of the first offset number according to the length of the first encoded character string includes: Perform a modulo operation on the character string length and a preset value to obtain the first offset number.

6. A method for decrypting message data based on BASE64, characterized in that: The decryption method comprises: Obtaining a first encrypted string to be decrypted, where the first encrypted string is encrypted based on the BASE64-based message data encryption method according to any one of claims 1 to 5; Determining a first offset number according to the length of the first encrypted string, and determining a first index value set corresponding to the first encrypted string; the first index value set includes a plurality of first index values; Determine, according to the first offset number and the first index value set, a second index value corresponding to each first index value; Querying a preset mapping character table to determine the first decrypted character corresponding to each second index value; Generate first message data according to the first decrypted character.

7. A message data encryption device based on BASE64, characterized in that: The encryption device comprises: An encoding module, configured to perform BASE64 encoding on the first message data to obtain a first encoded character string; A secondary mapping module is used to determine a first offset number based on the string length of the first encoded string, and determine a first index value set corresponding to the first encoded string based on the first offset number; the first index value set includes multiple first index values; query a preset mapping character table to determine the first encrypted character corresponding to each first index value in the first index value set; and generate a first encrypted string for the first message data based on the first encrypted character.

8. A message data decryption device based on BASE64, characterized in that: The decryption device comprises: a demapping module configured to obtain a first encrypted string to be decrypted, the first encrypted string being encrypted based on the BASE64-based message data encryption method according to any one of claims 1 to 5; determine a first offset number based on a string length of the first encrypted string, and determine a first index value set corresponding to the first encrypted string, the first index value set including a plurality of first index values; determine a second index value corresponding to each first index value based on the first offset number and the first index value set; and query a preset mapping character table to determine a first decrypted character corresponding to each second index value; A decoding module is used to generate first message data according to the first decrypted character.

9. An electronic device, characterized in that: The invention comprises a processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein when the computer program is executed by the processor, the method for encrypting message data based on BASE64 according to any one of claims 1 to 5 or the method for decrypting message data based on BASE64 according to claim 6 is implemented.

10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, which, when executed by a processor, implements the message data encryption method based on BASE64 as claimed in any one of claims 1 to 5, or the message data decryption method based on BASE64 as claimed in claim 6.