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

By encrypting the encryption encoding using randomly generated offset codes during the encryption process, differentiated encryption results are generated, and the problem of easy cracking of existing encryption algorithms is solved, and the security of data encryption is improved.

CN113765650BActive Publication Date: 2024-12-10BEIJING WODONG TIANJUN INFORMATION TECH CO LTD +1
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202011103678.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-10-15
Publication Date
2024-12-10
Estimated Expiration
2040-10-15

AI Technical Summary

Technical Problem

The existing encryption algorithms are fixed, easily reverse cracked, and have low encryption security.

Method used

By obtaining the to-encrypted encoding and the randomly generated offset code of the characters to be encrypted, the to-encrypted encoding is encrypted, the to-encrypted encoding is generated, and the encrypted encoding is generated based on the intermediate to-encrypted encoding and offset code, the random characteristics of the offset code are used to make it easier to make There are differences in encryption results.

Benefits of technology

It improves the security of data encryption, prevents encryption algorithms from being easily reversely cracked due to fixedness, and achieves high data encryption security.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113765650B_ABST
    Figure CN113765650B_ABST
Patent Text Reader

Abstract

The embodiment of the present invention discloses a data encryption and decryption method, device, electronic device and storage medium. The data encryption method comprises: when an encryption trigger event of character encryption is detected, obtaining the to-be-encrypted code and offset code of the to-be-encrypted character corresponding to the encryption trigger event, wherein the offset code is a random number; encrypting the to-be-encrypted code according to the offset code to obtain an intermediate encryption code; generating an encrypted code according to the intermediate encryption code and the offset code. The technical solution of the embodiment of the present invention, by utilizing the random characteristics of the offset code to encrypt the to-be-encrypted code, makes the encryption results of the same to-be-encrypted code at different times different, solves the problem that the encryption algorithm is easily reverse cracked due to its fixed nature, and achieves the effect of data encryption with higher security.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present invention relate to the field of data processing technology, and in particular to a data encryption and decryption method, device, electronic device and storage medium. Background Art

[0002] Data in the field of e-commerce is often sensitive, such as transaction amounts, supplier quotations, risk control data, etc. Such data is widely used in the analysis and decision-making of various businesses due to its commercial value. To prevent the leakage of such data, it is usually encrypted.

[0003] The prior art mainly uses a general encryption algorithm to encrypt data, such as the fifth version of the message digest algorithm (Message Digest Algorithm MD5, MD5), an asymmetric encryption algorithm (RSA), and the like.

[0004] In the process of implementing the present invention, the inventors found that the prior art has the following technical problems: these encryption algorithms are fixed and can be easily reverse cracked, and the encryption security needs to be improved. Summary of the invention

[0005] The embodiments of the present invention provide a data encryption and decryption method, device, electronic device and storage medium, which solve the problem of low security of data encryption.

[0006] In a first aspect, an embodiment of the present invention provides a data encryption method, which may include:

[0007] When an encryption trigger event of character encryption is detected, the to-be-encrypted code and the offset code of the to-be-encrypted character corresponding to the encryption trigger event are obtained, wherein the offset code is a random number;

[0008] Encrypt the to-be-encrypted code according to the offset code to obtain an intermediate encrypted code;

[0009] Generate an encrypted code based on the intermediate encrypted code and the offset code.

[0010] In a second aspect, an embodiment of the present invention further provides a data decryption method, which may include:

[0011] When a decryption trigger event of character decryption is detected, the to-be-decrypted code of the to-be-decrypted character corresponding to the decryption trigger event is obtained, and an offset code is obtained from the to-be-decrypted code;

[0012] Decrypt the code to be decrypted according to the offset code to obtain the decrypted code;

[0013] According to the decrypted code, the character to be decrypted is obtained.

[0014] In a third aspect, an embodiment of the present invention further provides a data encryption device, which may include:

[0015] The data acquisition module is used to acquire the encrypted code and offset code of the character to be encrypted corresponding to the encryption trigger event when an encryption trigger event of character encryption is detected, wherein the offset code is a random number;

[0016] A data encryption module, used for encrypting the code to be encrypted according to the offset code to obtain an intermediate encryption code;

[0017] The data generation module is used to generate an encrypted code according to the intermediate encryption code and the offset code.

[0018] In a fourth aspect, an embodiment of the present invention further provides a data decryption device, which may include:

[0019] The data acquisition module is used to acquire the to-be-decrypted code of the to-be-decrypted character corresponding to the decryption triggering event when a decryption triggering event of character decryption is detected, and to acquire the offset code from the to-be-decrypted code;

[0020] A data decryption module, used for decrypting the code to be decrypted according to the offset code to obtain the decrypted code;

[0021] The data restoration module is used to obtain the characters to be decrypted based on the decrypted codes.

[0022] In a fifth aspect, an embodiment of the present invention further provides an electronic device, which may include:

[0023] one or more processors;

[0024] A memory for storing one or more programs;

[0025] When one or more programs are executed by one or more processors, the one or more processors implement the data encryption method or data decryption method provided by any embodiment of the present invention.

[0026] In a sixth aspect, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements a data encryption method or a data decryption method provided by any embodiment of the present invention.

[0027] The technical solution of the embodiment of the present invention obtains the encrypted code of the character to be encrypted and the randomly generated offset code, encrypts the encrypted code according to the offset code, and obtains the intermediate encrypted code; then, generates the encrypted code corresponding to the character to be encrypted according to the intermediate encrypted code and the offset code. The above technical solution encrypts the encrypted code by utilizing the random characteristics of the offset code, so that the encryption results of the same code to be encrypted at different times are different, which solves the problem that the encryption algorithm is easy to be reverse cracked due to its fixed nature, and achieves the effect of data encryption with higher security. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] Figure 1 is a flow chart of a data encryption method in Embodiment 1 of the present invention;

[0029] Figure 2 is a flow chart of a data encryption method in Embodiment 2 of the present invention;

[0030] Figure 3 is a flow chart of a data encryption method in Embodiment 3 of the present invention;

[0031] Figure 4a This is a schematic diagram of an optional example of an application of a data encryption method in Embodiment 3 of the present invention;

[0032] Figure 4b This is a schematic diagram of an optional example of an application of a data decryption method in Embodiment 4 of the present invention;

[0033] Figure 5 is a schematic diagram of an encryption result in a data encryption method in Embodiment 3 of the present invention;

[0034] Figure 6 is a flow chart of a data decryption method in Embodiment 4 of the present invention;

[0035] Figure 7 It is a structural block diagram of a data encryption device in Embodiment 5 of the present invention;

[0036] Figure 8 It is a structural block diagram of a data decryption device in Embodiment 6 of the present invention;

[0037] Fig. 9 It is a structural schematic diagram of an electronic device in Embodiment 7 of the present invention. DETAILED DESCRIPTION

[0038] The present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present invention, rather than to limit the present invention. It is also necessary to explain that, for ease of description, only parts related to the present invention, rather than all structures, are shown in the accompanying drawings.

[0039] Embodiment 1

[0040] Figure 1 : is a flow chart of a data encryption method provided in Embodiment 1 of the present invention. This embodiment is applicable to the case where data encryption is performed based on a randomly generated offset code. The method can be executed by a data encryption device provided in an embodiment of the present invention, which can be implemented by software and / or hardware, and can be integrated on an electronic device, which can be various user terminals or servers.

[0041] See also Figure 1 The method of the embodiment of the present invention specifically includes the following steps:

[0042] S110. When an encryption triggering event of character encryption is detected, the to-be-encrypted code and the offset code of the to-be-encrypted character corresponding to the encryption triggering event are obtained, wherein the offset code is a random number.

[0043] Among them, the encryption trigger event can be an event triggered by the client or the server to encrypt the encrypted code of the character to be encrypted. According to the encryption trigger event, the encrypted code of the character to be encrypted corresponding to it and the offset code can be obtained. The offset code is a random number randomly generated when the encryption trigger event is detected. It should be noted that the character to be encrypted can be a character to be encrypted, and the character can be a character in a string that needs to be encrypted. The encrypted code is the encoding of the character to be encrypted, and the encoding can be Unicode encoding, ASCII code, GB2312, ISO-8859-1, GBK, UTF-8, etc., among which Unicode encoding sets a unified and unique binary encoding for each character in each language to meet the requirements of cross-language and cross-platform text conversion and processing.

[0044] On this basis, optionally, the offset code can be generated in any of the following ways: randomly setting the offset code from a preset integer range, the specific value of the preset integer range can be set according to the actual situation, such as [0,127]; determining the offset code according to the random number sent by the server; determining the offset code according to the public key sent by the server and the private key generated by the client, the value range of the public key and the value range of the private key can also be set according to the actual situation, such as the public key K1 is within 0-16, the private key K2 is within 0-8, and the offset code = (K1*K2)-1; determining the offset code according to the ASCII code corresponding to any lowercase letter and uppercase letter, such as using the ASCII code of any letter in az and AZ as the offset code; etc., which are not specifically limited here. As can be seen from the above, the offset code has the characteristic of being updated at all times, and it is a random number.

[0045] S120. Encrypt the code to be encrypted according to the offset code to obtain an intermediate encrypted code.

[0046] Among them, there are many ways to implement encrypting the encrypted code according to the offset code, such as encrypting the encrypted code according to the specific value of the offset code; another example is encrypting the encrypted code according to the first parity of the offset code; another example is first selecting a target encryption strategy that matches the first parity from each preset encryption strategy, and then encrypting the encrypted code according to the target encryption strategy, or the target encryption strategy and the specific value of the offset code; and so on, which are not specifically limited here.

[0047] S130: Generate an encrypted code according to the intermediate encryption code and the offset code.

[0048] Among them, there are many ways to generate the encrypted code according to the intermediate encryption code and the offset code, such as directly loading the offset code in front of, in the middle or after the intermediate encryption code, and generating the encrypted code according to the loading result; another example is to offset the intermediate encryption code again according to the offset code, and generate the encrypted code according to the offset result; another example is to convert the format of the intermediate encryption code and load the offset code into the format conversion result, illustratively, convert the intermediate encryption code into the base64 code of dataURL, and confuse the offset code in the base64 code; etc., which are not specifically limited here. On this basis, optionally, if the number of characters to be encrypted is at least two, the encrypted code can be generated according to the offset code and the intermediate encryption code corresponding to each character to be encrypted, such as loading the offset code in front of or after a certain intermediate encryption code, or in the middle of two certain intermediate encryption codes, etc.

[0049] The reason for setting the above steps is that the intermediate encryption code is a code generated based on the offset code and the code to be encrypted. Since the offset code is random, it means that the offset code in the data encryption process needs to be obtained in the subsequent data decryption process so as to decrypt the data according to the offset code. Therefore, the encrypted code is generated according to the intermediate encryption code and the offset code, and the offset code in the data encryption process can be obtained from the encrypted code later, and the encrypted code can be decrypted according to the offset code, or the intermediate encryption code corresponding to the encrypted code can be decrypted. In other words, the encryption algorithm described in the embodiment of the present invention is reversible, and the characters to be encrypted can be restored in the subsequent data decryption process.

[0050] The technical solution of the embodiment of the present invention obtains the encrypted code of the character to be encrypted and the randomly generated offset code, encrypts the encrypted code according to the offset code, and obtains the intermediate encrypted code; then, generates the encrypted code corresponding to the character to be encrypted according to the intermediate encrypted code and the offset code. The above technical solution encrypts the encrypted code by utilizing the random characteristics of the offset code, so that the encryption results of the same code to be encrypted at different times are different, which solves the problem that the encryption algorithm is easy to be reverse cracked due to its fixed nature, and achieves the effect of data encryption with higher security.

[0051] Embodiment 2

[0052] Figure 2 It is a flow chart of a data encryption method provided in the second embodiment of the present invention. This embodiment is optimized based on the above-mentioned technical solutions. In this embodiment, optionally, obtaining the encrypted code of the character to be encrypted corresponding to the encryption trigger event may specifically include: obtaining the encrypted code and the storage position of the character to be encrypted corresponding to the encryption trigger event; correspondingly, encrypting the code to be encrypted according to the offset code to obtain the intermediate encrypted code, which may specifically include: encrypting the code to be encrypted according to the offset code and the storage position to obtain the intermediate encrypted code. Among them, the explanations of the terms that are the same as or corresponding to the above-mentioned embodiments are not repeated here.

[0053] See also Figure 2 The method of this embodiment may specifically include the following steps:

[0054] S210. When an encryption triggering event of character encryption is detected, the to-be-encrypted code and the to-be-stored position of the to-be-encrypted character corresponding to the encryption triggering event are obtained, and an offset code, wherein the offset code is a random number.

[0055] The location to be stored is a location for storing the code to be encrypted, which may be at least one location in a storage area such as a memory area, a database, etc.

[0056] S220, encrypt the code to be encrypted according to the offset code and the location to be stored to obtain an intermediate encrypted code.

[0057] There are many ways to implement encrypting the encrypted code according to the offset code and the position to be stored, for example, encrypting the encrypted code according to the specific value of the offset code and the specific value of the position to be stored; another example is encrypting the encrypted code according to the first parity of the offset code and the second parity of the position to be stored; another example is screening out an intermediate encryption strategy that matches the first parity from the preset encryption strategy, and screening out a target encryption strategy that matches the second parity from each intermediate encryption strategy, and then encrypting the encrypted code according to the target encryption strategy, the target encryption strategy may be a strategy for performing a certain operation on the encrypted code, the target encryption strategy may be related to the specific value of the offset code, the specific value of the position to be stored, and / or the specific value of the operation result of the position to be stored, and may also be related to the value range of storable data at the position to be stored; and so on, which are not specifically limited here.

[0058] The significance of the above steps is to associate the encoding encryption process with the storage position of the code. When the same offset code is matched with different storage positions, the encryption results of the same code to be encrypted are also different, thereby further improving the security of data encryption. It should be noted that in the subsequent decryption process, when the code to be decrypted of the character to be decrypted is obtained, the code to be decrypted is the encrypted code mentioned above, and the storage position of the code to be decrypted can also be directly obtained. Therefore, the code to be decrypted can be decrypted according to the offset code obtained from the code to be decrypted and the storage position, and the character to be decrypted restored according to the decryption result is exactly the character to be encrypted mentioned above.

[0059] S230: Generate an encrypted code according to the intermediate encryption code and the offset code.

[0060] The technical solution of the embodiment of the present invention obtains the storage position of the code to be encrypted, and encrypts the code to be encrypted according to the randomly set offset code and the storage position corresponding to the character to be encrypted, thereby further improving the security of data encryption.

[0061] An optional technical solution, encrypting the code to be encrypted according to the offset code and the position to be stored, may specifically include: determining the first parity of the offset code and the second parity of the position to be stored; encrypting the code to be encrypted according to the first parity and the second parity. Wherein, the first parity may be the parity of the offset code, the parity of the calculation result of the offset code, etc.; similarly, the position to be stored is a numerical value, and the second parity may be the parity of the position to be stored, the parity of the calculation result of the position to be stored, etc., which are not specifically limited here. Further, the process of encrypting the code to be encrypted according to the first parity and the second parity may be, for example, selecting a target encryption strategy from each preset encryption strategy according to the two, and encrypting the code to be encrypted according to the target encryption strategy; for example, first selecting an intermediate encryption strategy from each preset encryption strategy according to the first parity, and then selecting a target encryption strategy from each intermediate encryption strategy according to the second parity; etc., which are not specifically limited here.

[0062] On this basis, after obtaining the to-be-encrypted code of the to-be-encrypted character corresponding to the encryption trigger event, the above-mentioned data encryption method may further include: obtaining a first preset value, and determining the code quotient of the to-be-encrypted code according to the first preset value, wherein the first preset value is the maximum value of the storable data at the storable position, the storable position is a position that can be used to store data, and the storable data is the data that can be stored at the storable position. In other words, the to-be-encrypted code can be split into a code quotient and a code remainder according to the first preset value, the code quotient is the quotient of (to-be-encrypted code ÷ first preset value), and the code remainder is the remainder of (to-be-encrypted code ÷ first preset value). Exemplarily, taking the to-be-encrypted code as 20320 and the first preset value as 128, the code quotient of the to-be-encrypted code is 79 and the code remainder is 175.

[0063] Correspondingly, the position to be stored includes the position to be stored of the code quotient, and determining the second parity of the position to be stored of the code quotient may specifically include: determining the position quotient and position remainder of the position to be stored of the code quotient according to the acquired second preset value, and determining the second quotient parity of the position quotient and the second remainder parity of the position remainder respectively, the second preset value is the total number of storage positions in each group of storable areas, the storage position may be a storable position or a non-storable position, the non-storable position may be a position that cannot be used to store data, and the storable area is an area that can be used to store data. That is, the position to be stored of the code quotient can be split into a position quotient and a position remainder according to the second preset value, the position quotient may be the quotient of (the position to be stored of the code quotient ÷ the second preset value), and the position remainder may be the remainder of (the position to be stored of the code quotient ÷ the second preset value).

[0064] Correspondingly, according to the first parity and the second parity, the encryption code to be encrypted is encrypted, which may specifically include: according to the first parity, the second quotient parity and the second remainder parity, the code quotient is encrypted, such as firstly selecting an intermediate encryption strategy from each preset encryption strategy according to the first parity, and then selecting a target encryption strategy from each intermediate encryption strategy according to the similarity and difference between the second quotient parity and the second remainder parity, and encrypting the code quotient according to the target encryption strategy. It should be noted that one of the code quotient and the code remainder of the code to be encrypted can be selected for encryption, or both can be encrypted. Optionally, the encryption process of the code remainder can be similar to or different from the encryption process of the above-mentioned code quotient, such as the code remainder can be encrypted according to the first parity, and the position quotient of the position to be stored of the code remainder and the parity of the position remainder; etc., which are not specifically limited here.

[0065] The above technical scheme splits the code to be encrypted into a code quotient and a code remainder. On the one hand, the code quotient and / or the code remainder are encrypted, thereby further improving the security of data encryption; on the other hand, since the maximum value of the data that can be stored in the storage position is limited, the existing storage scheme needs to be based on multiple storage positions to store the code to be encrypted, while the above technical scheme can store the code to be encrypted through only two storage positions, one storage position stores the code quotient, and the other storage position stores the code remainder, thereby reducing the data storage cost and improving the transmission efficiency during data transmission.

[0066] Embodiment 3

[0067] Figure 3 It is a flow chart of a data decryption method provided in the third embodiment of the present invention. This embodiment is optimized based on the various technical solutions in the above-mentioned second embodiment. In this embodiment, optionally, obtaining the to-be-encrypted code and the to-be-stored position of the to-be-encrypted character corresponding to the encryption trigger event may specifically include: obtaining the to-be-encrypted code of the to-be-encrypted character in the to-be-encrypted character string corresponding to the encryption trigger event; determining the number of area groups and the position within the group of the to-be-encrypted character in each storable area according to the subscript of the to-be-encrypted character in the to-be-encrypted character string, wherein the number of storable areas includes at least two groups, and each group of storable areas includes at least two storable positions; determining the to-be-stored position of the to-be-encrypted code according to the number of area groups and the position within the group, and the to-be-stored position is at least one of the storable positions. Among them, the explanations of the terms that are the same or corresponding to the above-mentioned embodiments are not repeated here.

[0068] See also Figure 3 The method of this embodiment may specifically include the following steps:

[0069] S310. When an encryption trigger event for character encryption is detected, obtain the encryption code to be encrypted of the character to be encrypted in the string to be encrypted corresponding to the encryption trigger event, and an offset code, where the offset code is a random number.

[0070] Wherein, the character to be encrypted is a character in the string to be encrypted that has an encryption requirement. In practical applications, optionally, each character in the string to be encrypted can be a character to be encrypted, that is, the encryption codes to be encrypted of each character to be encrypted can be encrypted separately, thereby achieving the encryption effect of the string to be encrypted.

[0071] S320. According to the subscript of the character to be encrypted in the string to be encrypted, determine the number of region groups and the position within the group of the encryption code to be encrypted in each storage area, where the number of storage areas includes at least two groups, and each group of storage areas includes at least two storage positions.

[0072] Wherein, the subscript is the position of the character to be encrypted in the string to be encrypted. Taking the first subscript being 0 as an example, the subscript of "你" in "你好吗" is 0, the subscript of "好" in "你好吗" is 1, and so on. The storage area is an area for storing data, the storage position is the position in its corresponding storage area for storing data, the number of region groups is the number of groups of the storage areas where the storage positions to store the encryption code to be encrypted are located among all storage areas, and the position within the group is the position of the storage position in all storage positions of its corresponding storage area.

[0073] There are various ways to determine the number of region groups and the position within the group of the encryption code to be encrypted in each storage area according to the subscript. Exemplarily, since the number of storage positions occupied by each encryption code in the string to be encrypted is the same, according to the subscript and the number of storage positions in each group of storage areas, the number of region groups and the position within the group of the encryption code to be encrypted in each storage area can be determined. Taking the number of storage positions occupied by the encryption code to be encrypted being two and each storage area including three storage positions as an example, the two storage positions corresponding to the encryption code corresponding to "好" in "你好吗" are respectively the second storage position in the 0th group of storage areas and the 0th storage position in the 1st group of storage areas. Another example is to first obtain the number of storage positions in each group of storage areas, use this number as a benchmark to determine the quotient and remainder of the subscript, and determine the number of region groups and the position within the group based on the two.

[0074] S330. According to the number of region groups and the position within the group, determine the storage position to store the encryption code to be encrypted, where the storage position is at least one of all storage positions.

[0075] Among them, the specific value of the position to be stored can be determined by taking all the storable positions as a whole, that is, the position to be stored is its position in all the storable positions. Continuing with the example in the previous step, "the second storable position in the 0th group of storable areas" is the second position in the whole, and "the 0th storable position in the 1st group of storable areas" is the third position in the whole; for another example, when the fourth position in each group of storable areas is a non-storable position, "the second storable position in the 0th group of storable areas" is the second position in the whole, and "the 0th storable position in the 1st group of storable areas" is the fourth position in the whole. On this basis, optionally, in the case of obtaining the number of regional groups and the position within the group according to the subscript quotient and the subscript remainder, the position to be stored to be encrypted can also be determined jointly according to the subscript, the number of regional groups and the position within the group, and so on, which is not specifically limited here.

[0076] In practical applications, optionally, if the code to be encrypted is split into a code quotient and a code remainder according to a first preset value, the position to be stored of the code quotient can be determined according to the subscript, the number of regional groups, and the position within the group; and then, the position to be stored of the code remainder can be determined according to the position within the group and the position to be stored of the code quotient. The reason for this setting is that, considering that some positions in the storable area are storable positions, and some positions are non-storable positions, when the code remainder is stored after the code quotient, it can be determined according to the position within the group whether its next position can be used to store data, and then the position to be stored of the code remainder can be determined according to the judgment result and the position to be stored of the code quotient. Exemplarily, assuming that the position to be stored of the code quotient is 2, and it is determined according to the judgment result that its next position can be used to store data, then the position to be stored of the code remainder is 3; otherwise, the position to be stored of the code remainder is 4.

[0077] S340, encrypt the code to be encrypted according to the offset code and the location to be stored to obtain an intermediate encrypted code, and generate an encrypted code according to the intermediate encrypted code and the offset code.

[0078] The technical solution of the embodiment of the present invention can determine the number of area groups and the position within the group of the encrypted code of the character to be encrypted in each storable area through the subscript of the character to be encrypted in the character string to be encrypted, so as to determine the storage position of the encrypted code based on the two.

[0079] Considering the application scenarios that may be involved in the embodiments of the present invention, the storage location can be presented in the form of a primitive, and the primitive is used to store the pixel information of the pixel points in the image drawn on the canvas. Since the length of the string to be encrypted directly affects the length of the corresponding code to be encrypted, and the encrypted code corresponding to the code to be encrypted can be stored in the primitive, the size of the canvas can be determined according to the length of the string to be encrypted. On this basis, the above data encryption method can also include: storing the encrypted code in the primitive. It should be noted that the canvas is an html5 tag, which draws an image on html5 through a script, and the primitive is a carrier for storing data. The base64 encoding of dataURL is generated with the primitive as the carrier. That is, the canvas can be used to store images, and the pixel information of each pixel in the image can be stored in the primitive, and the pixel information of each pixel can be represented by four channels of R, G, B and A, and the specific values ​​of each channel can be stored in a primitive respectively. In other words, every four primitives can constitute a group of primitives, and each group of primitives can be used to store one pixel information.

[0080] In order to better understand the specific implementation process of the above steps, the data encryption method of this embodiment is described below with reference to a specific example. For example, taking the string to be encrypted as "How are you?", each character in "How are you?" is a character to be encrypted. Figure 4a As shown:

[0081] 1) Get a random integer in the range of [0,127] and use it as the offset code K (assuming K = 50)

[0082] 2) Get the length L (L=3) of the string to be encrypted "How are you"

[0083] 3) Generate a canvas on the page, the width W of the canvas is L / 1.5 (rounded up) + 1 (W = 3) and the height H is 1. The reason for setting W in this way is that, in this example, every two primitives store a code to be encrypted, each group of primitives includes four primitives, and the last primitive in each group of primitives (i.e., channel A) cannot be used to store data, and it needs to be occupied by 255, which means that each group of primitives can store the encrypted code corresponding to 1.5 characters to be encrypted. Therefore, the size of the canvas set in this way can just store the encrypted code corresponding to the string to be encrypted.

[0084] 4) Create an image on the canvas with a width of W and a height of H

[0085] 5) Set K at the first 3 bits of the 0th group of graphic elements in the image (i.e., the positions with subscripts 0, 1, and 2, which are positions in the whole), and set the 4th bit (i.e., the position with subscript 3) to 255

[0086] 6) Obtain the Unicode encoding c of "你" (c = 20320), and c is the encoding to be encrypted

[0087] 7) c / 255 to obtain c0 and c1 (c0 = 79, c1 = 175). c0 is the encoding quotient and c1 is the encoding remainder. The reason for dividing by 255 is that the maximum value of data that can be stored in each graphic element is 255, and the value range of Unicode encoding is 0 - 65535 (65535 = 255 * 255). After dividing by 255, c0 and c1 each just occupy 1 graphic element

[0088] 8) Obtain the storage position p0 of c0 and the storage position p1 of c1 (p0 = 4, p1 = 5). The specific calculation process is as follows:

[0089] a) Obtain the subscript i of the character to be encrypted (the subscript of "你" is 0, and the subscript of "好" is 1)

[0090] b) Obtain the number of region groups g0 and the position within the group g1. Among them, g0 is the quotient of i / 3 and g1 is the remainder of i / 3. The reason for dividing by 3 is that the number of storable graphic elements that can be used to store data in each group of graphic elements is 3

[0091] c) If g1 is 0 or 1, then p0 = (i + g0) * 2 + 4; if g1 is 2, then p0 = (i + g0) * 2 + 5

[0092] d) If g1 is 0 or 2, then p1 = p0 + 1; if g1 is 1, then p1 = p0 + 2

[0093] 9) Respectively obtain the position quotient and position remainder of p0 / 4 and p1 / 4 (p0 / 4 = 1 remainder 0, p1 / 4 = 1 remainder 1), and encrypt c0 and c1 based on this (after encryption, c0 = 29 and c1 = 225, the intermediate encrypted encoding). The specific calculation process is as follows:

[0094] a) K is an even number: If both the position quotient and position remainder of p0 are even or odd, then the amplitude of c0 is c0 + K. If c0 > 255, then c0 is reassigned as c0 - 255; the same applies to c1. If one of the position quotient and position remainder of p0 is even and the other is odd, then c0 is assigned as c0 - K. If c0 < 0, then c0 is reassigned as c0 + 255; the same applies to c1

[0095] b) K is odd: If both the positional quotient and the positional remainder of p0 are even or odd, then c0 is assigned c0 – K. If c0 < 0, then c0 is reassigned c0 + 255; the same applies to c1. If one of the positional quotient and the positional remainder of p0 is even and the other is odd, then c0 is assigned c0 + K. If c0 > 255, then c0 is reassigned c0 – 255; the same applies to c1

[0096] 10) Place the encrypted c0 at the p0 position of the primitive, and place the encrypted c1 at the p1 position of the primitive

[0097] 11) If the position P of p0 + 1 or p1 + 1 is a multiple of 4 – 1, then P is set to 255

[0098] 12) Repeat steps 6 - 11 to encrypt "good" and "吗" respectively

[0099] 13) Set the last bit of the primitive to 255. At this time, the set primitive information is as Figure 5 shown

[0100] 14) Place the set primitive information into the canvas to generate the base64 encoding of the dataURL

[0101] It should be noted that, first, in practical applications, in addition to directly placing the offset code in the primitive as shown Figure 5 shown, the offset code can also be directly scrambled in the base64 encoding, that is, the first group of primitives directly stores the encrypted encoding corresponding to the string to be encrypted. This means that the initially generated base64 encoding does not contain the offset code. Subsequently, according to the negotiation result between the server and the client, the offset code can be added to the middle of the corresponding two groups of primitives in the base64 encoding. Second, the above encryption process can be executed by the client or the server. When it is executed by the client, the client can transmit the finally generated base64 encoding (i.e., the encrypted encoding) to the server, and the server can convert this base64 encoding into an image or directly store it in cloud storage. It should be noted that the value range of Unicode encoding is 0 - 65535, which means that at least three primitives are required to store one Unicode encoding. Plus a 255 placeholder primitive, that is, each group of primitives can only store one Unicode encoding. Correspondingly, in the above example, each group of primitives can store one and a half Unicode encodings. This shows that the processing scheme of the encoding quotient and the encoding remainder can effectively compress the encrypted encoding after encryption to 2 / 3 of the original encoding to be encrypted, thereby improving the data transmission efficiency and reducing the space cost of server storage. Third, the above encryption process effectively utilizes the randomness of the offset code and the position information of the storage position to encrypt the encoding to be encrypted, thereby realizing a highly secure data encryption process.

[0102] Embodiment 4

[0103] Figure 6 : is a flow chart of a data decryption method provided in Embodiment 4 of the present invention. This embodiment is applicable to the case of decrypting data encrypted based on a randomly generated offset code. The method can be executed by a data decryption device provided in an embodiment of the present invention, which can be implemented by software and / or hardware, and can be integrated in an electronic device, which can be a user terminal or a server.

[0104] See also Figure 6 The method of the embodiment of the present invention specifically includes the following steps:

[0105] S410: When a decryption triggering event of character decryption is detected, a to-be-decrypted code of the to-be-decrypted character corresponding to the decryption triggering event is obtained, and an offset code is obtained from the to-be-decrypted code.

[0106] Among them, the decryption trigger event can be an event triggered by the client or the server to decrypt the to-be-decrypted code corresponding to the to-be-decrypted character. According to the decryption trigger event, the to-be-decrypted code corresponding to the to-be-decrypted character can be obtained, and the offset code can be obtained from the to-be-decrypted code. The offset code is a random number involved in the encryption process for encrypting the to-be-decrypted character, and the to-be-decrypted code is the encrypted code described above. It should be noted that the to-be-decrypted character can be a character to be decrypted, which can be a character in a string that needs to be decrypted. The to-be-decrypted code is the encoding of the to-be-decrypted character, which can be a base64 encoding, etc.

[0107] S420, decrypt the code to be decrypted according to the offset code to obtain the decrypted code.

[0108] Among them, the process of decrypting the code to be decrypted according to the offset code is exactly the opposite of the process of encrypting the code to be encrypted according to the offset code, which will not be repeated here. It should be noted that the offset code obtained from the code to be decrypted is exactly the offset code in the data encryption process, which makes the decrypted code obtained after decrypting the code to be decrypted based on the offset code completely consistent with the original code to be encrypted, and the characters to be decrypted restored from the decrypted code are exactly the original characters to be encrypted, thereby achieving the reversibility between the encryption algorithm and the decryption algorithm.

[0109] S430, obtaining characters to be decrypted according to the decrypted code.

[0110] It should be noted that the optional technical solution involved in the data decryption process is the opposite of the implementation process of the technical solution described in the above data encryption process, and will not be repeated here. In addition, the stored location of the code to be decrypted does not need to be calculated, and it can be obtained together with the code to be decrypted.

[0111] The technical solution of the embodiment of the present invention obtains an offset code from the to-be-decrypted code of the to-be-decrypted character, decrypts the to-be-decrypted code according to the offset code, and obtains the decrypted code; then, the to-be-decrypted character is restored according to the decrypted code. The above technical solution decrypts the to-be-decrypted code by using the offset code obtained from the to-be-decrypted code, thereby achieving the reversibility between the encryption algorithm and the decryption algorithm.

[0112] In order to better understand the specific implementation process of the above steps, the data decryption method of this embodiment is exemplarily described below in combination with the above example "How are you?". For example, taking the string to be decrypted as "How are you?" as an example, each character in "How are you?" is a character to be decrypted. Figure 4b As shown:

[0113] 1) The client obtains the encrypted base64 encoding from the server

[0114] 2) Create a new image object (i.e., Image object), the src attribute of which is base64 encoded

[0115] 3) Get the width W and height H of the Image object

[0116] 4) Create a new canvas with a width of W and a height of H

[0117] 5) Draw the Image object on the canvas

[0118] 6) Get the image element information. Bits 0-2 are the offset code K. Bits 4 and above are the data information. The number of image element groups is W.

[0119] 7) Starting from the 4th bit, get the graphics element c0 and c1 every 2 bits. If you encounter a 255 placeholder graphics element, take one bit backward

[0120] 8) Decrypt c0 and c1. The specific calculation process is:

[0121] a) K is an even number: If the position quotient and position remainder of the storage location where c0 is located are both even or odd, c0 is assigned to c0-K. If c0<0, c0 is assigned to c0+255. The same is true for c1. If the position quotient and position remainder of the storage location where c0 is located are both even and odd, c0 is assigned to c0+K. If c0>255, c0 is assigned to c0-255. The same is true for c1.

[0122] b) K is an odd number: If the position quotient and position remainder of the storage location where c0 is located are both even or odd, c0 is assigned to c0+K. If c0>255, c0 is assigned to c0–255. The same is true for c1. If the position quotient and position remainder of the storage location where c0 is located are both even and odd, c0 is assigned to c0-K. If c0<0, c0 is assigned to c0+255. The same is true for c1 ("you" restore c0=79, c1=175)

[0123] 9) Get the Unicode code c based on c0*255+c1, and restore the character to be decrypted represented by c

[0124] 10) Repeat steps 7-9 to restore each character to be decrypted in the string to be decrypted to complete the decryption.

[0125] Embodiment 5

[0126] Figure 7 This is a structural block diagram of a data encryption device provided in Embodiment 5 of the present invention. The device is used to execute the data encryption method provided in any of the above embodiments. The device and the data encryption method of the above embodiments belong to the same inventive concept. For details not described in detail in the embodiments of the data encryption device, please refer to the embodiments of the above data encryption method. Figure 7 The device may specifically include: a data acquisition module 510, a data encryption module 520 and a data generation module 530.

[0127] Among them, the data acquisition module 510 is used to obtain the encrypted code and offset code of the character to be encrypted corresponding to the encryption trigger event when an encryption trigger event of character encryption is monitored, and the offset code is a random number; the data encryption module 520 is used to encrypt the encrypted code according to the offset code to obtain the intermediate encrypted code; the data generation module 530 is used to generate the encrypted code according to the intermediate encryption code and the offset code.

[0128] Optionally, the data acquisition module 510 may specifically include: a data acquisition submodule, used to acquire the to-be-encrypted code and the to-be-stored position of the to-be-encrypted character corresponding to the encryption trigger event;

[0129] Correspondingly, the data encryption module 520 may specifically include: a data encryption submodule, configured to encrypt the code to be encrypted according to the offset code and the location to be stored to obtain an intermediate encryption code.

[0130] Optionally, the data acquisition submodule may specifically include: an encrypted code acquisition unit, used to acquire the encrypted code of the character to be encrypted in the character string to be encrypted corresponding to the encryption trigger event; an intra-group position determination unit, used to determine the number of area groups and the intra-group position of the code to be encrypted in each storable area according to the subscript of the character to be encrypted in the character string to be encrypted, wherein the number of storable areas includes at least two groups, and each group of storable areas includes at least two storable positions; a to-be-stored position determination unit, used to determine the to-be-stored position of the code to be encrypted according to the number of area groups and the intra-group position, wherein the to-be-stored position is at least one of the storable positions.

[0131] Optionally, the data acquisition submodule may further include: a coding remainder determination unit, used to obtain a first preset value, and determine the coding quotient and coding remainder to be encrypted according to the first preset value, wherein the first preset value is the maximum value of data that can be stored in the storage location;

[0132] Correspondingly, the unit for determining the position to be stored can be specifically used to: determine the position to be stored of the code quotient according to the index, the number of area groups and the position within the group, and determine the position to be stored of the code remainder according to the position within the group and the position to be stored of the code quotient.

[0133] Optionally, the location to be stored includes a graphic element, which is used to store pixel information of pixels of an image drawn on a canvas. The size of the canvas is determined according to the length of the string to be encrypted. The above-mentioned device may also include: a storage module, which is used to store the encrypted code in the graphic element.

[0134] Optionally, the data encryption submodule may specifically include: a parity determination unit, used to determine a first parity of the offset code and a second parity of the position to be stored; and a data encryption unit, used to encrypt the code to be encrypted according to the first parity and the second parity.

[0135] Optionally, on this basis, the data acquisition submodule may further include: a code quotient determination unit, used to obtain a first preset value, and determine the code quotient to be encrypted according to the first preset value, wherein the first preset value is the maximum value of the storable data in the storable position;

[0136] Correspondingly, the parity determination unit may specifically include: a position quotient parity determination subunit, used to determine the position quotient and the position remainder of the to-be-stored position of the encoding quotient according to the acquired second preset value, and to determine the second quotient parity of the position quotient and the second remainder parity of the position remainder respectively, wherein the second preset value is the total number of storage positions in each group of storable areas;

[0137] Correspondingly, the data encryption unit can be specifically used to encrypt the code quotient according to the first parity, the second quotient parity and the second remainder parity.

[0138] Optionally, the offset code may be generated by an offset code generation module, and the offset code generation module may generate the offset code by any of the following methods:

[0139] Randomly set the offset code from a preset integer range;

[0140] Determine the offset code based on the random number sent by the server;

[0141] Determine the offset code based on the public key sent by the server and the private key generated by the client; and,

[0142] The offset code is determined according to the ASCII code corresponding to any lowercase letter or uppercase letter.

[0143] The data encryption device provided in the fifth embodiment of the present invention cooperates with the data acquisition module and the data encryption module. After obtaining the encrypted code of the character to be encrypted and the randomly generated offset code, the encrypted code is encrypted according to the offset code to obtain an intermediate encrypted code; the data generation module generates an encrypted code corresponding to the character to be encrypted according to the intermediate encrypted code and the offset code. The above device encrypts the encrypted code by utilizing the random characteristics of the offset code so that the encryption results of the same code to be encrypted at different times are different, thereby solving the problem that the encryption algorithm is easily reverse cracked due to its fixed nature, and achieving a data encryption effect with high security.

[0144] The data encryption device provided in the embodiment of the present invention can execute the data encryption method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.

[0145] It is worth noting that in the embodiment of the above-mentioned data encryption device, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of the present invention.

[0146] Embodiment 6

[0147] Figure 8 This is a structural block diagram of a data decryption device provided in Embodiment 6 of the present invention. The device is used to execute the data decryption method provided in any of the above embodiments. The device and the data decryption method of the above embodiments belong to the same inventive concept. For details not described in detail in the embodiments of the data decryption device, please refer to the embodiments of the above data decryption method. Figure 8The device may specifically include: a data obtaining module 610, a data decryption module 620 and a data restoration module 630.

[0148] Among them, the data acquisition module 610 is used to obtain the to-be-decrypted code of the to-be-decrypted character corresponding to the decryption trigger event when a decryption trigger event of character decryption is monitored, and obtain the offset code from the to-be-decrypted code; the data decryption module 620 is used to decrypt the to-be-decrypted code according to the offset code to obtain the decrypted code; the data restoration module 630 is used to obtain the to-be-decrypted character according to the decrypted code.

[0149] The data decryption device provided in the sixth embodiment of the present invention obtains an offset code from the to-be-decrypted code of the to-be-decrypted character through the cooperation between the data obtaining module and the data decryption module, decrypts the to-be-decrypted code according to the offset code, and obtains the decrypted code; then, the data restoration module restores the to-be-decrypted character according to the decrypted code. The above device decrypts the to-be-decrypted code by the offset code obtained from the to-be-decrypted code, thereby realizing the reversibility between the encryption algorithm and the decryption algorithm.

[0150] The data decryption device provided in the embodiment of the present invention can execute the data decryption method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.

[0151] It is worth noting that in the embodiment of the above-mentioned data decryption device, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of the present invention.

[0152] Embodiment 7

[0153] Fig. 9 A schematic diagram of the structure of an electronic device provided in Embodiment 7 of the present invention is shown in FIG. Fig. 9 As shown, the electronic device includes a memory 710, a processor 720, an input device 730, and an output device 740. The number of processors 720 in the electronic device can be one or more. Fig. 9 A processor 720 is taken as an example; the memory 710, the processor 720, the input device 730 and the output device 740 in the electronic device can be connected via a bus or other means. Fig. 9 The connection via bus 750 is taken as an example.

[0154] The memory 710, as a computer-readable storage medium, can be used to store software programs, computer executable programs and modules, such as program instructions / modules corresponding to the data encryption method in the embodiment of the present invention (for example, the data acquisition module 510, the data encryption module 520 and the data generation module 530 in the data encryption device), or, such as program instructions / modules corresponding to the data decryption method in the embodiment of the present invention (for example, the data acquisition module 610, the data decryption module 620 and the data restoration module 630 in the data decryption device). The processor 720 executes various functional applications and data processing of the electronic device by running the software programs, instructions and modules stored in the memory 710, that is, implements the above-mentioned data encryption method or data decryption method.

[0155] The memory 710 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the electronic device, etc. In addition, the memory 710 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some instances, the memory 710 may further include a memory remotely arranged relative to the processor 720, and these remote memories may be connected to the device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0156] The input device 730 may be used to receive input digital or character information and generate key signal input related to user settings and function control of the device. The output device 740 may include a display device such as a display screen.

[0157] Embodiment 8

[0158] Embodiment 8 of the present invention provides a storage medium including computer executable instructions, wherein the computer executable instructions are used to perform a data encryption method when executed by a computer processor, the method comprising:

[0159] When an encryption trigger event of character encryption is detected, the to-be-encrypted code and the offset code of the to-be-encrypted character corresponding to the encryption trigger event are obtained, wherein the offset code is a random number;

[0160] Encrypt the to-be-encrypted code according to the offset code to obtain an intermediate encrypted code;

[0161] Generate an encrypted code based on the intermediate encrypted code and the offset code.

[0162] Of course, the computer executable instructions of a storage medium including computer executable instructions provided by an embodiment of the present invention are not limited to the operations of the method described above, but can also execute related operations in the data encryption method provided by any embodiment of the present invention.

[0163] Embodiment 9

[0164] Embodiment 9 of the present invention provides a storage medium containing computer executable instructions, wherein the computer executable instructions are used to perform a data decryption method when executed by a computer processor, the method comprising:

[0165] When a decryption trigger event of character decryption is detected, the to-be-decrypted code of the to-be-decrypted character corresponding to the decryption trigger event is obtained, and an offset code is obtained from the to-be-decrypted code;

[0166] Decrypt the code to be decrypted according to the offset code to obtain the decrypted code;

[0167] According to the decrypted code, the character to be decrypted is obtained.

[0168] Through the above description of the implementation methods, the technicians in the relevant field can clearly understand that the present invention can be implemented by means of software and necessary general hardware, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as a computer floppy disk, read-only memory (ROM), random access memory (RAM), flash memory (FLASH), hard disk or optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, server, or network device, etc.) to execute the methods described in each embodiment of the present invention.

[0169] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims

1. A data encryption method, characterized in that: include: When an encryption trigger event of character encryption is detected, the to-be-encrypted code and the to-be-stored position and the offset code of the to-be-encrypted character corresponding to the encryption trigger event are obtained, wherein the offset code is a random number; Obtaining a first preset value, and determining the code quotient of the to-be-encrypted code according to the first preset value, wherein the first preset value is a maximum value of data that can be stored in a storage location; Determine a first parity of the offset code, and determine a position quotient and a position remainder of the to-be-stored position of the encoding quotient according to the acquired second preset value, and respectively determine a second quotient parity of the position quotient and a second remainder parity of the position remainder, wherein the second preset value is the total number of storage positions in each group of storable areas; encrypting the code quotient according to the first parity, the second quotient parity and the second remainder parity to obtain an intermediate encrypted code; An encrypted code is generated according to the intermediate encrypted code and the offset code.

2. The method according to claim 1, characterized in that The step of obtaining the to-be-encrypted code and the to-be-stored position of the to-be-encrypted character corresponding to the encryption triggering event includes: Obtaining the encrypted code of the character to be encrypted in the character string to be encrypted corresponding to the encryption triggering event; Determine the number of area groups and the position within the group of the to-be-encrypted code in each storable area according to the subscript of the to-be-encrypted character in the to-be-encrypted character string, wherein the number of the storable areas includes at least two groups, and each group of the storable areas includes at least two storable positions; The storage position of the to-be-encrypted code is determined according to the number of area groups and the position within the group, wherein the storage position is at least one position among the storable positions.

3. The method according to claim 2, characterized in that After obtaining the encrypted code of the character to be encrypted in the character string to be encrypted corresponding to the encryption triggering event, the method further includes: Obtaining a first preset value, and determining the code quotient and the code remainder of the to-be-encrypted code according to the first preset value, wherein the first preset value is the maximum value of the data that can be stored in the storable position; Correspondingly, determining the storage location of the to-be-encrypted code according to the number of area groups and the location within the group includes: The position to be stored of the code quotient is determined according to the subscript, the number of the area groups and the position within the group, and the position to be stored of the code remainder is determined according to the position within the group and the position to be stored of the code quotient.

4. The method according to claim 2, characterized in that: The location to be stored includes a graphic element, and the graphic element is used to store pixel information of a pixel point of an image drawn on a canvas, and the size of the canvas is determined according to the length of the string to be encrypted, and the method further includes: The encrypted code is stored in the primitive.

5. The method according to claim 1, characterized in that The offset code is generated by any of the following methods: Randomly setting the offset code from a preset integer range; Determine the offset code according to the random number sent by the server; Determine the offset code according to the public key issued by the server and the private key generated by the client; as well as, The offset code is determined according to the ASCII code corresponding to any one of the lowercase letters and the uppercase letters.

6. A data decryption method, characterized in that: include: When a decryption triggering event of character decryption is detected, the to-be-decrypted code of the to-be-decrypted character corresponding to the decryption triggering event is obtained, and an offset code is obtained from the to-be-decrypted code; Decrypting the code to be decrypted according to the offset code to obtain a decrypted code; According to the decrypted code, the character to be decrypted is obtained; The code to be decrypted is generated by the following steps: Obtaining the to-be-encrypted code and the to-be-stored position of the to-be-encrypted character and the offset code, wherein the offset code is a random number; Obtaining a first preset value, and determining the code quotient of the to-be-encrypted code according to the first preset value, wherein the first preset value is a maximum value of data that can be stored in a storage location; Determine a first parity of the offset code, and determine a position quotient and a position remainder of the to-be-stored position of the encoding quotient according to the acquired second preset value, and respectively determine a second quotient parity of the position quotient and a second remainder parity of the position remainder, wherein the second preset value is the total number of storage positions in each group of storable areas; encrypting the code quotient according to the first parity, the second quotient parity and the second remainder parity to obtain an intermediate encrypted code; The code to be decrypted is generated according to the intermediate encrypted code and the offset code.

7. A data encryption device, characterized in that: include: A data acquisition module, used for acquiring, when an encryption trigger event of character encryption is detected, the to-be-encrypted code and the to-be-stored position and the offset code of the to-be-encrypted character corresponding to the encryption trigger event, acquiring a first preset value, and determining the code quotient of the to-be-encrypted code according to the first preset value, wherein the first preset value is the maximum value of the storable data at the storable position, and the offset code is a random number; A data encryption module, used for encrypting the code to be encrypted according to the offset code to obtain an intermediate encrypted code; A data generation module, used for generating an encrypted code according to the intermediate encryption code and the offset code; Wherein, the data encryption module includes: a parity determination unit, configured to determine a first parity of the offset code, and determine a position quotient and a position remainder of the position to be stored of the encoding quotient according to the acquired second preset value, and respectively determine a second quotient parity of the position quotient and a second remainder parity of the position remainder, wherein the second preset value is the total number of storage positions in each group of storable areas; A data encryption unit is used to encrypt the code quotient according to the first parity, the second quotient parity and the second remainder parity to obtain an intermediate encryption code.

8. A data decryption device, characterized in that: include: A data acquisition module is used to acquire the to-be-decrypted code of the to-be-decrypted character corresponding to the decryption triggering event when a decryption triggering event of character decryption is detected, and to acquire the offset code from the to-be-decrypted code; A data decryption module, used for decrypting the code to be decrypted according to the offset code to obtain a decrypted code; A data restoration module, used to obtain the character to be decrypted according to the decrypted code; The code to be decrypted is generated in the following way: Obtaining the to-be-encrypted code and the to-be-stored position of the to-be-encrypted character and the offset code, wherein the offset code is a random number; Obtaining a first preset value, and determining the code quotient of the to-be-encrypted code according to the first preset value, wherein the first preset value is a maximum value of data that can be stored in a storage location; Determine a first parity of the offset code, and determine a position quotient and a position remainder of the to-be-stored position of the encoding quotient according to the acquired second preset value, and respectively determine a second quotient parity of the position quotient and a second remainder parity of the position remainder, wherein the second preset value is the total number of storage positions in each group of storable areas; encrypting the code quotient according to the first parity, the second quotient parity and the second remainder parity to obtain an intermediate encrypted code; The code to be decrypted is generated according to the intermediate encrypted code and the offset code.

9. An electronic device, characterized in that: include: one or more processors; A memory for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the data encryption method as described in any one of claims 1 to 5, or the data decryption method as described in claim 6.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the data encryption method according to any one of claims 1 to 5 or the data decryption method according to claim 6 is implemented.

Citation Information

Patent Citations

  • Compressing language models with Golomb coding

    CN101283349A

  • Input / output interface, memory controller, set-top box and ciphering / deciphering method

    CN101742200A

  • Data storage method based on RGB (red green blue) color coding

    CN103700120A