Data encryption method and device
By selecting pixel points from the target image to generate straight lines and converting the encrypted data, the problem of high equipment performance requirements in the prior art is solved, efficient data encryption on low-computing equipment is realized, and high security is ensured.
Patent Information
- Application Number
- CN202111463606.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-02
- Publication Date
- 2025-02-25
- Estimated Expiration
- 2041-12-02
AI Technical Summary
Existing data encryption technologies require high equipment performance. Many embedded devices or IoT devices are difficult to use these encryption methods due to insufficient computing power or difficult code migration.
By acquiring the target image, selecting n pixel points from the image, generating straight lines based on the color components of these pixel points, using these straight lines to convert the encrypted data, and generating encrypted data.
Reduces the requirements of data encryption methods on device performance and improves the efficiency of encryption on devices with low computing power. At the same time, due to the complexity of images, the encrypted data is high and the possibility of brute-force cracking is extremely small. High security.
Smart Images

Figure CN114139186B_ABST
Abstract
Description
Technical Field
[0001] One or more embodiments of the present specification relate to the computer field, and more particularly, to a data encryption method and device. Background Art
[0002] Data encryption is a reliable way for computer systems to protect information. It uses cryptographic technology to encrypt information and hide it, thereby protecting the security of information.
[0003] At present, data encryption technology mainly uses symmetric or asymmetric algorithms to encrypt data, such as DES, 3DES, AES, RSA and national secret algorithms, etc. The core of them is to encrypt data through key combination algorithms.
[0004] In the existing technical solutions, data encryption methods usually use complex algorithms and have high requirements on device performance. Many devices cannot use this data encryption method. For example, some embedded devices or IoT devices have insufficient computing power or difficult code portability.
[0005] Therefore, it is necessary to provide an improved solution that can reduce the requirements of the data encryption method on device performance and still have high security. Summary of the invention
[0006] One or more embodiments of this specification describe a data encryption method and apparatus, which can reduce the requirements of the data encryption method on device performance and still have high security.
[0007] In a first aspect, a data encryption method is provided, the method being executed by a first device, comprising:
[0008] Get the target image;
[0009] Selecting n first pixels from the pixels included in the target image; n is greater than or equal to 2;
[0010] For any first pixel, obtaining a first value based on a color component corresponding to the first pixel;
[0011] Taking the position index of any first pixel in the target image as the horizontal coordinate and the first value corresponding to the first pixel as the vertical coordinate, a coordinate point in the coordinate system is obtained; n first pixels correspond to n coordinate points;
[0012] Using n coordinate points, m straight lines are obtained according to a pre-set straight line generation rule; m is greater than or equal to 1;
[0013] According to a preset conversion rule, the data to be encrypted is converted into encrypted data according to a functional relationship between a horizontal coordinate and a vertical coordinate corresponding to at least one straight line among the m straight lines.
[0014] In a possible implementation manner, obtaining a first value for any first pixel based on a color component corresponding to the first pixel includes:
[0015] For any first pixel, obtain an RGBA value corresponding to the first pixel; the RGBA value includes an R color component, a G color component, a B color component, and an A color component;
[0016] The RGBA value is used as the first value, or the first value is obtained by performing an operation on the RGBA value.
[0017] In a possible implementation, using n coordinate points to obtain m straight lines according to a preset straight line generation rule includes:
[0018] Using n coordinate points and following the straight line generation rule of generating a straight line from two adjacent points, we can obtain n-1 straight lines, where m is equal to n-1.
[0019] In a possible implementation, converting the to-be-encrypted data into the encrypted data according to a preset conversion rule and a functional relationship between a horizontal coordinate and a vertical coordinate corresponding to at least one of the m straight lines includes:
[0020] Take each k bytes of the data to be encrypted as a unit data, and obtain a plurality of unit data; k is greater than or equal to 1;
[0021] For any unit data, determine the first straight line corresponding to the unit data among the m straight lines;
[0022] According to the functional relationship between the abscissa and the ordinate corresponding to the first straight line, the unit data is used as the abscissa, and the corresponding ordinate is determined as the data after the unit data is converted;
[0023] The converted data corresponding to each unit data are combined together to obtain encrypted data.
[0024] In a possible implementation, the method further includes:
[0025] The encrypted data is sent to a second device; the second device has the target image, the straight line generation rule and the conversion rule, so that the second device can decrypt the encrypted data.
[0026] In a possible implementation, the method further includes:
[0027] The encrypted data and the n coordinate points are sent to a second device; the second device has the straight line generation rule and the conversion rule, so that the second device can decrypt the encrypted data.
[0028] In a possible implementation manner, before selecting n first pixels from pixels included in the target image, the method further includes:
[0029] Receive a digital combination input by the user;
[0030] Calculate a first hash value corresponding to the digital combination;
[0031] The first Hash value is compared with a pre-stored second Hash value to obtain a comparison result that is consistent with the comparison.
[0032] Furthermore, the preset straight line generation rule includes p candidate rules, each candidate rule having a corresponding rule number;
[0033] The method of obtaining m straight lines by using n coordinate points according to a preset straight line generation rule includes:
[0034] Determine a first rule number corresponding to the digital combination;
[0035] Selecting a first candidate rule corresponding to the first rule number from the p candidate rules;
[0036] Using n coordinate points, m straight lines are obtained according to the first candidate rule.
[0037] Furthermore, the preset conversion rules include q optional rules, each optional rule having a corresponding rule number;
[0038] The converting the to-be-encrypted data into the encrypted data according to the preset conversion rule and the functional relationship between the abscissa and the ordinate corresponding to at least one of the m straight lines includes:
[0039] Determine a second rule number corresponding to the digital combination;
[0040] Selecting a second optional rule corresponding to the second rule number from the q optional rules;
[0041] According to the second optional rule, the data to be encrypted is converted into encrypted data according to the functional relationship between the horizontal coordinate and the vertical coordinate corresponding to at least one straight line among the m straight lines.
[0042] In a possible implementation manner, before selecting n first pixels from pixels included in the target image, the method further includes:
[0043] Receiving signature information obtained using a first private key; the first private key is generated based on a first click operation information performed by a user on the target image;
[0044] The signature information is verified based on a pre-stored first public key, and it is determined that the verification passes; the first public key is generated based on a second click operation information performed by the user on the target image.
[0045] Further, the target image is divided into a plurality of regions;
[0046] The click operation information includes at least one of the following information:
[0047] The content of the area corresponding to the click operation, the number of areas corresponding to the click operation, and the order of clicking multiple areas corresponding to the click operation.
[0048] In a second aspect, a data encryption device is provided, the device being arranged in a first device, comprising:
[0049] An acquisition unit, used for acquiring a target image;
[0050] A selection unit, configured to select n first pixels from the pixels included in the target image acquired by the acquisition unit; n is greater than or equal to 2;
[0051] a value determination unit, configured to obtain, for any first pixel selected by the selection unit, a first value based on a color component corresponding to the first pixel;
[0052] A coordinate point determination unit, used to use a position index of any first pixel in the target image as a horizontal coordinate and a first value corresponding to the first pixel obtained by the value determination unit as a vertical coordinate to obtain a coordinate point in a coordinate system; n first pixels correspond to n coordinate points;
[0053] A straight line generating unit, used to obtain m straight lines according to a preset straight line generating rule using the n coordinate points obtained by the coordinate point determining unit; m is greater than or equal to 1;
[0054] The conversion unit is used to convert the data to be encrypted into the encrypted data according to a preset conversion rule and the functional relationship between the horizontal coordinate and the vertical coordinate corresponding to at least one of the m straight lines obtained by the straight line generation unit.
[0055] According to a third aspect, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed in a computer, the computer is caused to execute the method of the first aspect.
[0056] According to a fourth aspect, a computing device is provided, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the method of the first aspect is implemented.
[0057] Through the method and device provided by the embodiment of this specification, first obtain the target image; then select n first pixels from each pixel included in the target image; n is greater than or equal to 2; then for any first pixel, a first value is obtained based on the color component corresponding to the first pixel; then the position index of any first pixel in the target image is used as the horizontal coordinate, and the first value corresponding to the first pixel is used as the vertical coordinate to obtain a coordinate point in the coordinate system; n first pixels correspond to n coordinate points; then use the n coordinate points to obtain m straight lines according to the pre-set straight line generation rule; m is greater than or equal to 1; finally, according to the pre-set conversion rule, according to the functional relationship between the horizontal coordinate and the vertical coordinate corresponding to at least one of the m straight lines, the data to be encrypted is converted into the encrypted data. As can be seen from the above, in the embodiment of this specification, on the one hand, the calculations involved in data encryption are simple algebraic calculations, which are efficient and can be completed on devices with low computing power; on the other hand, data encryption depends on the target image, and the complexity of the image makes the complexity of the encrypted data astronomical, and the possibility of brute force cracking is extremely small, thereby reducing the requirements of the data encryption method on the performance of the device, and still has high security. BRIEF DESCRIPTION OF THE DRAWINGS
[0058] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.
[0059] Figure 1 A schematic diagram of an implementation scenario of an embodiment disclosed in this specification;
[0060] Figure 2 A flow chart of a data encryption method according to an embodiment is shown;
[0061] Figure 3 A schematic diagram showing pixels in an image according to one embodiment;
[0062] Figure 4 A schematic diagram of coordinate point determination according to an embodiment is shown;
[0063] Figure 5 A schematic block diagram of a data encryption device according to an embodiment is shown. DETAILED DESCRIPTION
[0064] The solution provided in this specification is described below in conjunction with the accompanying drawings.
[0065] Figure 1 This is a schematic diagram of an implementation scenario of an embodiment disclosed in this specification. This implementation scenario involves data encryption. It can be understood that through data encryption, the original data can be changed and converted into encrypted data.
[0066] Reference Figure 1 , the original data is data a, after data encryption, the encrypted data is data b, data a and data b are usually different, for example, data a is the binary number 0110, data b is the binary number 1010. Data decryption is the reverse process of data encryption, that is, through data decryption, the encrypted data can be changed and converted into the original data.
[0067] The embodiments of this specification provide a data encryption method with a simple algorithm, which can reduce the requirements of the data encryption method on device performance and still have high security.
[0068] Figure 2 A flow chart of a data encryption method according to an embodiment is shown. The method can be based on Figure 1 The implementation scenario shown in Figure 1 is as follows. Figure 2 As shown, in this embodiment, the data encryption method is executed by the first device, and includes the following steps: Step 21, acquiring a target image; Step 22, selecting n first pixels from each pixel included in the target image; n is greater than or equal to 2; Step 23, for any first pixel, obtaining a first value based on the color component corresponding to the first pixel; Step 24, taking the position index of any first pixel in the target image as the horizontal coordinate, and the first value corresponding to the first pixel as the vertical coordinate, to obtain a coordinate point in the coordinate system; n first pixels correspond to n coordinate points; Step 25, using n coordinate points, according to a pre-set straight line generation rule to obtain m straight lines; m is greater than or equal to 1; Step 26, according to a pre-set conversion rule, according to the functional relationship between the horizontal coordinate and the vertical coordinate corresponding to at least one of the m straight lines, the data to be encrypted is converted into the encrypted data. The specific execution method of each of the above steps is described below.
[0069] First, in step 21, a target image is acquired. It is understandable that the target image may be any image, such as a card surface image.
[0070] In the embodiments of this specification, the target image may be an image that has been stored in the first device, or may be an image that is captured in real time by a camera of the first device.
[0071] Then in step 22, n first pixels are selected from the pixels included in the target image; n is greater than or equal to 2. It can be understood that data encryption can be performed based on all pixels in the target image, or based on part of the pixels in the target image.
[0072] Among them, pixels can be regarded as indivisible units or elements in the entire image. Indivisible means that it cannot be cut into smaller units or elements, and it exists as a small grid. Each image contains a certain number of pixels, and these pixels have a clear position and assigned color values. The color and position of the pixels determine the appearance of the image.
[0073] Figure 3 FIG. 1 is a schematic diagram showing pixels in an image according to an embodiment. Figure 3 , the image includes 12 pixels, each small square represents a pixel, the value in the small square represents the position index of the pixel, and each pixel also has its corresponding RGBA value, which is used to represent the color value of the pixel, including multiple color components. All pixels of an image can form a pixel array, and the index of the pixel in the array can be used as the aforementioned position index.
[0074] In the embodiment of the present specification, n first pixels can be randomly selected from the pixels included in the target image, or n first pixels can be selected according to a certain rule. The above rule can be set to select n first pixels whose position indexes start from 0 and increase by 1 in sequence.
[0075] Next, in step 23, for any first pixel, a first value is obtained based on the color component corresponding to the first pixel. It is understandable that the first value may be obtained based on all color components corresponding to the first pixel, or based on part of the color components corresponding to the first pixel.
[0076] In one example, for any first pixel, obtaining a first value based on a color component corresponding to the first pixel includes:
[0077] For any first pixel, obtain an RGBA value corresponding to the first pixel; the RGBA value includes an R color component, a G color component, a B color component, and an A color component;
[0078] The RGBA value is used as the first value, or the first value is obtained by performing an operation on the RGBA value.
[0079] It can be understood that the above R color component corresponds to red, the G color component corresponds to green, the B color component corresponds to blue, and the A color component corresponds to opacity.
[0080] Usually, the binary representation of RGBA value is 4 bytes, each byte has 8 bits. For example, px[3]=0x12AC0D35(RGBA), which means the pixel with position index 3 has an RGBA value of 0x12AC0D35, and the first two digits of the RGBA value represent the hexadecimal representation.
[0081] Then in step 24, the position index of any first pixel in the target image is used as the horizontal coordinate, and the first value corresponding to the first pixel is used as the vertical coordinate to obtain a coordinate point in the coordinate system; n first pixels correspond to n coordinate points. It can be understood that the value range of the horizontal coordinate depends on the possible value of the position index, and the value range of the vertical coordinate depends on the possible value of the aforementioned first value. When the first value is the RGBA value of the pixel, the value range of the vertical coordinate depends on the possible value of the RGBA value.
[0082] Figure 4 FIG. 2 shows a schematic diagram of determining coordinate points according to an embodiment. Figure 4 , the X coordinate axis is established with the pixel position index (Index), and the Y coordinate axis is established with the RGBA value, where the RGBA value has 4 bytes, each byte has 8 bits, that is, a total of 32 bits, which is converted to an integer of 2 to the power of 32, that is, this is the maximum value of the ordinate. The index of the pixel in the array and the integer corresponding to the pixel are used as (X, Y) to establish the coordinate point in the coordinate system.
[0083] For example, px[3]=0x12AC0D35 (RGBA), then the corresponding coordinate point is (3, 0x12AC0D35).
[0084] Then in step 25, m straight lines are obtained by using n coordinate points according to a preset straight line generation rule; m is greater than or equal to 1. It can be understood that every two points in the coordinate system can confirm a unique straight line, and at most n*(n-1) / 2 straight lines can be constructed by n coordinate points.
[0085] In one example, using n coordinate points to obtain m straight lines according to a preset straight line generation rule includes:
[0086] Using n coordinate points and following the straight line generation rule of generating a straight line from two adjacent points, we can obtain n-1 straight lines, where m is equal to n-1.
[0087] In this example, the meaning of two adjacent points can be defined as: two points closest to each other on the horizontal axis, or two points closest to each other on the vertical axis, or two points closest to each other in a straight line, or two points corresponding to two adjacent pixels in an image.
[0088] In the embodiments of this specification, the line generation rule is not limited to the above examples. For example, a line can be generated every first number of points. The above interval can be set in the horizontal axis direction or the vertical axis direction, and the above first number can be set to 1, 2 or 3, etc.
[0089] Finally, in step 26, according to a preset conversion rule, the data to be encrypted is converted into encrypted data according to the functional relationship between the horizontal coordinate and the vertical coordinate corresponding to at least one of the m straight lines. It can be understood that when m is greater than 1, all straight lines or selected straight lines can be used to convert the data to be encrypted into encrypted data.
[0090] In one example, converting the to-be-encrypted data into the encrypted data according to a preset conversion rule and a functional relationship between a horizontal coordinate and a vertical coordinate corresponding to at least one of the m straight lines includes:
[0091] Take each k bytes of the data to be encrypted as a unit data, and obtain a plurality of unit data; k is greater than or equal to 1;
[0092] For any unit data, determine the first straight line corresponding to the unit data among the m straight lines;
[0093] According to the functional relationship between the abscissa and the ordinate corresponding to the first straight line, the unit data is used as the abscissa, and the corresponding ordinate is determined as the data after the unit data is converted;
[0094] The converted data corresponding to each unit data are combined together to obtain encrypted data.
[0095] In the embodiments of this specification, the unit data and the straight line are not limited to a one-to-one correspondence. A straight line can be used to convert multiple unit data. It is only necessary to clarify the correspondence rules between the unit data and the straight line to facilitate decryption of the encrypted data according to the rules.
[0096] For example, the data to be converted has 5 bytes {127, 16, 8, 255, 100}, and the insufficient bits are filled with 0. According to the rule of confirming a straight line with two adjacent coordinate points, the straight line in the coordinate system is generated. For example, the generated linear equations of two variables are:
[0097] y=x+1
[0098] y=2x
[0099] y=x-2
[0100] y=x+10
[0101] y=3x+5
[0102] Then the data to be converted for each byte is x, and the converted y is as follows:
[0103] y=127+1=128
[0104] y=2*16=32
[0105] y = 8 – 2 = 6
[0106] y = 255 + 10 = 265
[0107] y = 3 * 100 + 5 = 305
[0108] The relationship between x and y is determined by the image, the rules for selecting coordinate points, and the rules for generating straight lines, so it is impossible to restore the original data without the image and the rules.
[0109] The conversion rules in the embodiments of this specification may be in a customized form, for example, the first byte of the data to be converted is applied to the second straight line, the second byte is applied to the third straight line, and so on.
[0110] It should be noted that the rules involved in the embodiments of this specification can be flexibly set, and it is only necessary for the encryption device and the decryption device to have the same rules.
[0111] In one example, the method further includes:
[0112] The encrypted data is sent to a second device; the second device has the target image, the straight line generation rule and the conversion rule, so that the second device can decrypt the encrypted data.
[0113] It can be understood that, in this example, the second device needs to select n first pixels from the pixels included in the target image; for any first pixel, obtain a first value based on the color component corresponding to the first pixel; use the position index of any first pixel in the target image as the horizontal coordinate, and the first value corresponding to the first pixel as the vertical coordinate to obtain a coordinate point in the coordinate system; use the n coordinate points to obtain m straight lines according to a pre-set straight line generation rule; according to a pre-set conversion rule, convert the encrypted data into original data according to the functional relationship between the horizontal coordinate and the vertical coordinate corresponding to at least one of the m straight lines.
[0114] In another example, the method further includes:
[0115] The encrypted data and the n coordinate points are sent to a second device; the second device has the straight line generation rule and the conversion rule, so that the second device can decrypt the encrypted data.
[0116] It can be understood that in this example, the second device uses n coordinate points to obtain m straight lines according to a pre-set straight line generation rule; according to a pre-set conversion rule, based on the functional relationship between the horizontal coordinate and the vertical coordinate corresponding to at least one of the m straight lines, the encrypted data is converted into the original data.
[0117] In the embodiments of this specification, the first device may be a terminal device held by a user, and the second device may be a server. The server may decrypt the encrypted data received from the terminal device to obtain the original data, and perform identity authentication on the terminal device based on the original data.
[0118] In one example, in the initial state, the terminal device has transmitted the image, the array of all pixel points of the image or the selected coordinate points, and the line generation rules and conversion rules to the server, or shared the corresponding data with the server in other ways, and these data can be replaced. The server can decrypt the encrypted data received by multiple devices, that is, the server stores different decryption-related data and rules for each device. The server identifies the device according to the device's ID or other information, thereby determining the decryption-related data and rules corresponding to it, and then decrypts the data.
[0119] For example, the encrypted data received by the server is {128, 32, 6, 265, 305}. After decrypting the encrypted data, the five vertical coordinates that need to be decrypted are 128, 32, 6, 265, 305. According to the decryption-related data and rules, the equation of the line is determined, and the corresponding horizontal coordinates {127, 16, 8, 255, 100} are solved.
[0120] It should be noted that since the number of bytes of each vertical coordinate in the encrypted data may be inconsistent, in order to facilitate the decomposition of the encrypted data, a flag indicating the byte length of each vertical coordinate can be added to the encrypted data, or the number of bytes of each vertical coordinate can be made consistent by padding the shorter vertical coordinates with 0.
[0121] In the embodiments of this specification, the straight line generation rules can be set to multiple types (N11, N12...), and the conversion rules can also be set to multiple types (N21, N22...). The terminal device can determine in advance with the server which rule to use, or transmit rule data when transmitting encrypted data, and specify the use rules according to the rule data. For example, rule data (N11, N22) indicates that the straight line generation rule adopts N11 and the conversion rule adopts N22.
[0122] In the initial state, all pixel arrays of the image do not need to be transmitted, and the server automatically extracts the pixel array of the image based on the image. At this time, the data transmitted by the device also needs to include the coordinate point set selected during encryption. In this case, it is supported to use a different coordinate point set each time the data is encrypted, and the same plaintext corresponds to different ciphertexts for different transmission processes.
[0123] In one example, if the number of bytes of the data to be converted is greater than the number of straight lines, the excess bytes can be cyclically converted again starting from the first straight line.
[0124] According to the method provided in the embodiment of this specification, a target image is first acquired; then n first pixels are selected from each pixel included in the target image; n is greater than or equal to 2; then for any first pixel, a first value is obtained based on the color component corresponding to the first pixel; then the position index of any first pixel in the target image is used as the horizontal coordinate, and the first value corresponding to the first pixel is used as the vertical coordinate to obtain a coordinate point in the coordinate system; n first pixels correspond to n coordinate points; then, using the n coordinate points, m straight lines are obtained according to a pre-set straight line generation rule; m is greater than or equal to 1; finally, according to a pre-set conversion rule, the data to be encrypted is converted into encrypted data according to the functional relationship between the horizontal coordinate and the vertical coordinate corresponding to at least one of the m straight lines. As can be seen from the above, in the embodiment of this specification, on the one hand, the calculations involved in data encryption are simple algebraic calculations, which are efficient and can be completed on devices with low computing power; on the other hand, data encryption depends on the target image, and the complexity of the image makes the complexity of the encrypted data astronomical, and the possibility of brute force cracking is extremely small, thereby reducing the requirements of the data encryption method on device performance and still having high security.
[0125] The embodiments of this specification are highly dependent on the target image. If the target image is lost, it may be used by a third party. The above-mentioned use includes using the target image to encrypt data and also includes using the target image to decrypt data. In order to prevent the target image from being used by a third party, it is also necessary to authenticate the user of the target image to ensure that the target image will not be used by a third party. The above-mentioned identity authentication can be performed before each use of the target image, or it can be performed only under preset risk conditions. For example, when the above-mentioned user uses a certain device or a certain network protocol IP address for the first time, it is determined that there is a risk and the user needs to be authenticated.
[0126] In one example, before selecting n first pixels from pixels included in the target image, the method further includes:
[0127] Receive a digital combination input by the user;
[0128] Calculate a first hash value corresponding to the digital combination;
[0129] The first Hash value is compared with a pre-stored second Hash value to obtain a comparison result that is consistent with the comparison.
[0130] Furthermore, the preset straight line generation rule includes p candidate rules, each candidate rule having a corresponding rule number;
[0131] The method of obtaining m straight lines by using n coordinate points according to a preset straight line generation rule includes:
[0132] Determine a first rule number corresponding to the digital combination;
[0133] Selecting a first candidate rule corresponding to the first rule number from the p candidate rules;
[0134] Using n coordinate points, m straight lines are obtained according to the first candidate rule.
[0135] Furthermore, the preset conversion rules include q optional rules, each optional rule having a corresponding rule number;
[0136] The converting the to-be-encrypted data into the encrypted data according to the preset conversion rule and the functional relationship between the abscissa and the ordinate corresponding to at least one of the m straight lines includes:
[0137] Determine a second rule number corresponding to the digital combination;
[0138] Selecting a second optional rule corresponding to the second rule number from the q optional rules;
[0139] According to the second optional rule, the data to be encrypted is converted into encrypted data according to the functional relationship between the horizontal coordinate and the vertical coordinate corresponding to at least one straight line among the m straight lines.
[0140] For example, users can set a 6-digit number, and the hash value of the 6-digit number is stored in the encryption device and / or decryption device. When encrypting data, the 6-digit number can be used as a rule number to select encryption rules. The above encryption rules include straight line generation rules and conversion rules. Further, when the straight line generation rule includes the operation of straight line rotation, the 6-digit number can be used to determine the rotation angle. When decrypting data, you first need to provide a 6-digit number. The decryption device will calculate the hash value of the 6-digit number. If it is inconsistent with the pre-stored hash value, it will not be decrypted. If it is consistent, the corresponding rule or rotation angle is selected through the 6-digit number to decrypt the data. In addition, to solve the problem of low strength of 6-digit numbers, salt can be added to enhance the complexity.
[0141] The 6-digit number set by the user is encrypted and transmitted to the encryption device or decryption device in ciphertext form. The encryption device or decryption device decrypts the ciphertext to obtain a 6-digit number, adds salt to the 6-digit number to calculate the hash value, and stores the hash value and the corresponding salt. When the 6-digit number needs to be verified, the encrypted 6-digit number is first received, the hash value is calculated after decryption and salt is added, and compared with the pre-stored hash value. If they are equal, the verification is passed.
[0142] In one example, before selecting n first pixels from pixels included in the target image, the method further includes:
[0143] Receiving signature information obtained using a first private key; the first private key is generated based on a first click operation information performed by a user on the target image;
[0144] The signature information is verified based on a pre-stored first public key, and it is determined that the verification passes; the first public key is generated based on a second click operation information performed by the user on the target image.
[0145] Further, the target image is divided into a plurality of regions;
[0146] The click operation information includes at least one of the following information:
[0147] The content of the area corresponding to the click operation, the number of areas corresponding to the click operation, and the order of clicking multiple areas corresponding to the click operation.
[0148] It is understandable that the above-mentioned area can be a regular geometric shape, such as a square, a rectangle, a triangle, a trapezoid, etc., or an irregular geometric shape.
[0149] For example, the above area is a square, and each area corresponds to a grid. In an interactive verification scenario, it is specifically divided into an initial stage and a verification stage. In the initial stage, the target image is divided into several grids, and the user needs to select one or several grids, including the content, quantity and order of clicking each grid. Then, an asymmetric public-private key is generated through the above image data of the grid selected by the user, and the public key is transmitted to the encryption device and / or decryption device for storage, and the private key is discarded. In the verification stage, the encryption device and / or decryption device can send a random number to the user and require the user to select a grid to sign the random number. After the user selects a grid in the form preset in the initial stage, an asymmetric public-private key is generated through the image data of the selected grid content, quantity and order of clicking each grid, and the random number is signed with the private key and sent to the encryption device and / or decryption device. The encryption device and / or decryption device uses the previously stored public key to verify the signature. If the signature verification passes, it proves that the user is the owner of the image and data encryption or decryption processing can be performed. Otherwise, subsequent data encryption or decryption processing will not be performed. It can be understood that the encryption device, namely the aforementioned first device, and the decryption device, namely the aforementioned second device, and the data encryption processing and data decryption processing based on the target image can be performed after the user's identity is authenticated. If the identity authentication fails, no corresponding processing will be performed.
[0150] The two authentication methods in the previous example can be used separately or in combination. When the two authentication methods are used in combination, the two authentication methods can be used in sequence to authenticate the user. After the first authentication method successfully authenticates the user, the second authentication method is used to authenticate the user. After the second authentication method successfully authenticates the user, it is finally determined that the user authentication has passed, and data encryption or decryption processing can be performed based on the target image.
[0151] According to another aspect of the embodiment, there is also provided a data encryption device, which is used to execute the data encryption method provided in the embodiment of this specification and is arranged in a first device. Figure 5 FIG. 1 is a schematic block diagram of a data encryption device according to an embodiment. Figure 5 As shown, the device 500 includes:
[0152] An acquisition unit 51, used for acquiring a target image;
[0153] A selection unit 52 is used to select n first pixels from the pixels included in the target image acquired by the acquisition unit 51; n is greater than or equal to 2;
[0154] a value determination unit 53, configured to obtain a first value for any first pixel selected by the selection unit 52 based on a color component corresponding to the first pixel;
[0155] A coordinate point determination unit 54 is used to use the position index of any first pixel in the target image as a horizontal coordinate and the first value corresponding to the first pixel obtained by the value determination unit 53 as a vertical coordinate to obtain a coordinate point in the coordinate system; n first pixels correspond to n coordinate points;
[0156] A straight line generating unit 55, configured to use the n coordinate points obtained by the coordinate point determining unit 54 to obtain m straight lines according to a preset straight line generating rule; m is greater than or equal to 1;
[0157] The conversion unit 56 is used to convert the data to be encrypted into encrypted data according to a preset conversion rule and the functional relationship between the horizontal coordinate and the vertical coordinate corresponding to at least one of the m straight lines obtained by the straight line generation unit 55.
[0158] Optionally, as an embodiment, the value determination unit 53 includes:
[0159] An acquisition subunit, configured to acquire, for any first pixel, an RGBA value corresponding to the first pixel; the RGBA value includes an R color component, a G color component, a B color component, and an A color component;
[0160] The determining subunit is configured to use the RGBA value obtained by the obtaining subunit as the first value, or to obtain the first value after performing an operation on the RGBA value.
[0161] Optionally, as an embodiment, the straight line generating unit 55 is specifically configured to use n coordinate points and generate a straight line according to a straight line generating rule of generating a straight line from two adjacent points to obtain n-1 straight lines, where m is equal to n-1.
[0162] Optionally, as an embodiment, the conversion unit 56 includes:
[0163] Dividing sub-units, for treating every k bytes of the data to be encrypted as a unit data, to obtain a plurality of unit data; k is greater than or equal to 1;
[0164] A corresponding subunit, for determining, for any unit data obtained by dividing the subunits, a first straight line corresponding to the unit data among the m straight lines;
[0165] a conversion subunit, for determining the corresponding ordinate as data after the conversion of the unit data, using the unit data as the ordinate and determining the corresponding ordinate according to the functional relationship between the ordinate and the ordinate corresponding to the first straight line determined by the corresponding subunit;
[0166] The combining subunit is used to combine the converted data corresponding to each unit data obtained by the converting subunit to obtain encrypted data.
[0167] Through the device provided by the embodiment of this specification, first, the acquisition unit 51 acquires the target image; then the selection unit 52 selects n first pixels from the pixels included in the target image; n is greater than or equal to 2; then the value determination unit 53 obtains a first value for any first pixel based on the color component corresponding to the first pixel; the coordinate point determination unit 54 then uses the position index of any first pixel in the target image as the horizontal coordinate and the first value corresponding to the first pixel as the vertical coordinate to obtain a coordinate point in the coordinate system; n first pixels correspond to n coordinate points; the straight line generation unit 55 then uses the n coordinate points to obtain m straight lines according to a pre-set straight line generation rule; m is greater than or equal to 1; finally, the conversion unit 56 converts the to-be-encrypted data into the encrypted data according to the pre-set conversion rule and the functional relationship between the horizontal coordinate and the vertical coordinate corresponding to at least one of the m straight lines. As can be seen from the above, in the embodiments of this specification, on the one hand, the calculations involved in data encryption are all simple algebraic calculations, which are highly efficient and can be completed on devices with low computing power; on the other hand, data encryption depends on the target image, and the complexity of the image makes the complexity of the encrypted data astronomical, and the possibility of brute force cracking is extremely small, thereby reducing the requirements of the data encryption method on device performance and still having a high degree of security.
[0168] According to another embodiment, there is also provided a computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to execute a combination of Figure 2 The method described.
[0169] According to another embodiment of the present invention, a computing device is provided, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the Figure 2 The method described.
[0170] Those skilled in the art should be aware that in one or more of the above examples, the functions described in the present invention can be implemented by hardware, software, firmware or any combination thereof. When implemented by software, these functions can be stored in a computer-readable medium or transmitted as one or more instructions or codes on a computer-readable medium.
[0171] The specific implementation methods described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific implementation method of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made on the basis of the technical solution of the present invention should be included in the scope of protection of the present invention.
Claims
1. A data encryption method, the method being executed by a first device, comprising: Get the target image; Selecting n first pixels from the pixels included in the target image; n is greater than or equal to 2; For any first pixel, obtaining a first value based on a color component corresponding to the first pixel; Taking the position index of any first pixel in the target image as the horizontal coordinate and the first value corresponding to the first pixel as the vertical coordinate, a coordinate point in the coordinate system is obtained; n first pixels correspond to n coordinate points; Using n coordinate points, m straight lines are obtained according to a pre-set straight line generation rule; m is greater than or equal to 1; According to a preset conversion rule, and according to a functional relationship between a horizontal coordinate and a vertical coordinate corresponding to at least one of the m straight lines, the data to be encrypted is converted into encrypted data; The converting of the to-be-encrypted data into the encrypted data according to a preset conversion rule and a functional relationship between a horizontal coordinate and a vertical coordinate corresponding to at least one of the m straight lines comprises: Take each k bytes of the data to be encrypted as a unit data, and obtain a plurality of unit data; k is greater than or equal to 1; For any unit data, determine the first straight line corresponding to the unit data among the m straight lines; According to the functional relationship between the abscissa and the ordinate corresponding to the first straight line, the unit data is used as the abscissa, and the corresponding ordinate is determined as the data after the unit data is converted; The converted data corresponding to each unit data are combined together to obtain encrypted data.
2. The method of claim 1, wherein: The step of obtaining a first value for any first pixel based on a color component corresponding to the first pixel includes: For any first pixel, obtain an RGBA value corresponding to the first pixel; the RGBA value includes an R color component, a G color component, a B color component, and an A color component; The RGBA value is used as the first value, or the first value is obtained by performing an operation on the RGBA value.
3. The method of claim 1, wherein: The method of obtaining m straight lines by using n coordinate points according to a preset straight line generation rule includes: Using n coordinate points and following the straight line generation rule of generating a straight line from two adjacent points, we can obtain n-1 straight lines, where m is equal to n-1.
4. The method of claim 1, wherein: The method further comprises: The encrypted data is sent to a second device; the second device has the target image, the straight line generation rule and the conversion rule, so that the second device can decrypt the encrypted data.
5. The method of claim 1, wherein: The method further comprises: The encrypted data and the n coordinate points are sent to a second device; the second device has the straight line generation rule and the conversion rule, so that the second device can decrypt the encrypted data.
6. The method of claim 1, wherein: Before selecting n first pixels from the pixels included in the target image, the method further includes: Receive a digital combination input by the user; Calculate a first hash value corresponding to the digital combination; The first Hash value is compared with a pre-stored second Hash value to obtain a comparison result that is consistent with the comparison.
7. The method of claim 6, wherein: The preset straight line generation rule includes p candidate rules, each candidate rule having a corresponding rule number; The method of obtaining m straight lines by using n coordinate points according to a preset straight line generation rule includes: Determine a first rule number corresponding to the digital combination; Selecting a first candidate rule corresponding to the first rule number from the p candidate rules; Using n coordinate points, m straight lines are obtained according to the first candidate rule.
8. The method of claim 6, wherein: The pre-set conversion rules include q optional rules, each optional rule having a corresponding rule number; The method of converting the to-be-encrypted data into encrypted data according to a preset conversion rule and a functional relationship between a horizontal coordinate and a vertical coordinate corresponding to at least one of the m straight lines includes: Determine a second rule number corresponding to the digital combination; Selecting a second optional rule corresponding to the second rule number from the q optional rules; According to the second optional rule, the data to be encrypted is converted into encrypted data according to the functional relationship between the horizontal coordinate and the vertical coordinate corresponding to at least one straight line among the m straight lines.
9. The method of claim 1, wherein: Before selecting n first pixels from the pixels included in the target image, the method further includes: Receiving signature information obtained using a first private key; the first private key is generated based on a first click operation information performed by a user on the target image; The signature information is verified based on a pre-stored first public key, and it is determined that the verification passes; the first public key is generated based on a second click operation information performed by the user on the target image.
10. The method of claim 9, wherein: The target image is divided into a plurality of regions; The click operation information includes at least one of the following information: The content of the area corresponding to the click operation, the number of areas corresponding to the click operation, and the order of clicking multiple areas corresponding to the click operation.
11. A data encryption device, the device being arranged in a first device, comprising: An acquisition unit, used for acquiring a target image; A selection unit, configured to select n first pixels from the pixels included in the target image acquired by the acquisition unit; n is greater than or equal to 2; a value determination unit, configured to obtain, for any first pixel selected by the selection unit, a first value based on a color component corresponding to the first pixel; A coordinate point determination unit, used to use a position index of any first pixel in the target image as a horizontal coordinate and a first value corresponding to the first pixel obtained by the value determination unit as a vertical coordinate to obtain a coordinate point in a coordinate system; n first pixels correspond to n coordinate points; A straight line generating unit, used to obtain m straight lines according to a preset straight line generating rule using the n coordinate points obtained by the coordinate point determining unit; m is greater than or equal to 1; a conversion unit, configured to convert the data to be encrypted into encrypted data according to a pre-set conversion rule and a functional relationship between a horizontal coordinate and a vertical coordinate corresponding to at least one of the m straight lines obtained by the straight line generation unit; Wherein, the conversion unit comprises: Dividing sub-units, for treating every k bytes of the data to be encrypted as a unit data, to obtain a plurality of unit data; k is greater than or equal to 1; A corresponding subunit, for determining, for any unit data obtained by dividing the subunits, a first straight line corresponding to the unit data among the m straight lines; a conversion subunit, for determining the corresponding ordinate as data after the conversion of the unit data, using the unit data as the ordinate and determining the corresponding ordinate according to the functional relationship between the ordinate and the ordinate corresponding to the first straight line determined by the corresponding subunit; The combining subunit is used to combine the converted data corresponding to each unit data obtained by the converting subunit to obtain encrypted data.
12. The device of claim 11, wherein: The value determination unit comprises: An acquisition subunit, configured to acquire, for any first pixel, an RGBA value corresponding to the first pixel; the RGBA value includes an R color component, a G color component, a B color component, and an A color component; The determining subunit is configured to use the RGBA value obtained by the obtaining subunit as the first value, or to obtain the first value after performing an operation on the RGBA value.
13. The device of claim 11, wherein: The straight line generation unit is specifically used to use n coordinate points and generate a straight line according to a straight line generation rule of generating a straight line from two adjacent points to obtain n-1 straight lines, where m is equal to n-1.
14. A computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to execute the method according to any one of claims 1 to 10.
15. A computing device, comprising a memory and a processor, wherein the memory stores executable codes, and when the processor executes the executable codes, the method according to any one of claims 1 to 10 is implemented.
Citation Information
Patent Citations
Chinese character password encoding method based on image pixel coordinates
CN104468090A
Two-dimensional code color encryption method and device
CN105069498A