CN113810189A - Method and device for generating key picture - Google Patents

Method and device for generating key picture Download PDF

Info

Publication number
CN113810189A
CN113810189A CN202111254202.5A CN202111254202A CN113810189A CN 113810189 A CN113810189 A CN 113810189A CN 202111254202 A CN202111254202 A CN 202111254202A CN 113810189 A CN113810189 A CN 113810189A
Authority
CN
China
Prior art keywords
picture
key
length
encryption key
width
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202111254202.5A
Other languages
Chinese (zh)
Other versions
CN113810189B (en
Inventor
王瀚
苏景博
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhongdian Jinxin Software Co Ltd
Original Assignee
Zhongdian Jinxin Software Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhongdian Jinxin Software Co Ltd filed Critical Zhongdian Jinxin Software Co Ltd
Priority to CN202111254202.5A priority Critical patent/CN113810189B/en
Publication of CN113810189A publication Critical patent/CN113810189A/en
Application granted granted Critical
Publication of CN113810189B publication Critical patent/CN113810189B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/08Key distribution or management, e.g. generation, sharing or updating, of cryptographic keys or passwords
    • H04L9/0894Escrow, recovery or storing of secret information, e.g. secret key escrow or cryptographic key storage
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T11/002D [Two Dimensional] image generation
    • G06T11/001Texturing; Colouring; Generation of texture or colour
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T11/002D [Two Dimensional] image generation
    • G06T11/40Filling a planar surface by adding surface attributes, e.g. colour or texture
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/06Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols the encryption apparatus using shift registers or memories for block-wise or stream coding, e.g. DES systems or RC4; Hash functions; Pseudorandom sequence generators
    • H04L9/0618Block ciphers, i.e. encrypting groups of characters of a plain text message using fixed encryption transformation
    • H04L9/0631Substitution permutation network [SPN], i.e. cipher composed of a number of stages or rounds each involving linear and nonlinear transformations, e.g. AES algorithms

Abstract

The embodiment of the application provides a method and a device for generating a key picture, which relate to the field of data encryption, and the method for generating the key picture comprises the following steps: calculating according to the character string length value of the encryption key and a preset picture size calculation formula to obtain the picture length and the picture width; obtaining a conventional picture according to the size determined by the length and the width of the picture; respectively determining target three primary colors from the three primary colors corresponding to each pixel in the conventional picture; determining a target value from binary values corresponding to target three primary colors; and sequentially replacing the target values with binary values corresponding to the encryption key and the character string length value respectively to obtain a key picture. Therefore, by implementing the embodiment, a new encryption key storage mode can be created, so that the safety of information is guaranteed.

Description

Method and device for generating key picture
Technical Field
The present application relates to the field of data encryption, and in particular, to a method and an apparatus for generating a key picture.
Background
In order to ensure information security between the client and the server, the security of the information is generally enhanced by using an encryption method. However, the use of such encryption inevitably results in an encryption key. This entails that the encryption key has to be stored carefully by the client in order to avoid leakage.
However, in practice, it is found that the current encryption key storage mode is generally a storage mode such as code plaintext storage and application configuration file storage. The storage modes can be acquired by others through a code query means or a decompilation means. As can be seen, the above encryption key storage method greatly reduces the security of information, and thus cannot achieve the technical effect of guaranteeing the security of information.
Disclosure of Invention
An object of the embodiments of the present application is to provide a method and an apparatus for generating a key picture, which can create a new encryption key storage manner, thereby ensuring information security.
A first aspect of the embodiments of the present application provides a method for generating a key picture, including:
calculating according to the character string length value of the encryption key and a preset picture size calculation formula to obtain the picture length and the picture width;
obtaining a conventional picture according to the sizes determined by the picture length and the picture width;
respectively determining target three primary colors from the three primary colors corresponding to each pixel in the conventional picture;
determining a target value from binary values corresponding to the target three primary colors;
and sequentially replacing the target value with binary values respectively corresponding to the encryption key and the character string length value to obtain a key picture.
In the implementation process, the method can encrypt the file to be encrypted according to the actual encryption requirement to obtain the encryption key, then match the corresponding conventional picture according to the encryption key, and finally write the key length of the encryption key and the encryption key into the conventional picture, so that the picture storage process of the encryption key is implemented, and a key picture comprising key information is obtained. Therefore, by implementing the embodiment, the encryption key can be hidden in the picture, so that the key can be prevented from being directly acquired; on the other hand, by implementing the embodiment, the picture can be used as a key carrier, so that the possibility of identifying the key is reduced, and the information security is effectively guaranteed.
Further, the step of calculating according to the character string length value of the encryption key and a preset picture size calculation formula to obtain the picture length and the picture width includes:
calculating according to the length value of the character string of the encryption key, the preset number of storage digits of the character and the preset number of storage digits of the length value to obtain the length and the width of the picture; the character storage digit is used for expressing the number of pixels required for storing a single character; and the length value storage digit is used for expressing the number of pixels required for storing the length value of the sub-character string.
Further, the step of calculating according to the character string length value of the encryption key and a preset picture size calculation formula to obtain the picture length and the picture width includes:
calculating according to the length value of the character string of the encryption key, the preset number of character storage digits and the preset number of length value storage digits to obtain an initial length and an initial width;
taking the sum of the initial length and a preset first pixel number as the picture length; and taking the sum of the initial width and the preset number of second pixels as the picture width.
Further, the preset picture size calculation formula is as follows:
Figure BDA0003323488690000021
Figure BDA0003323488690000022
wherein px is a pixel unit;
said 8(px) is said number of character deposited bits;
said 32(px) is the number of length value storage bits;
the a (px) is the first number of pixels;
the b (px) is the second number of pixels.
Further, the step of obtaining a conventional picture according to the size determined by the picture length and the picture width includes:
and obtaining a conventional picture according to a preset color basic tone and the size determined by the length and the width of the picture.
Further, the step of determining the target value from binary values corresponding to the target three primary colors includes:
and taking one bit with the lowest bit number in binary values corresponding to the target three primary colors as a target value.
Further, the step of sequentially replacing the binary values corresponding to the encryption key and the character string length value with the target value to obtain the key picture includes:
determining a current value from binary values respectively corresponding to the encryption key and the length of the character string;
determining a current pixel from the conventional picture according to the sequence from left to right and from top to bottom;
and replacing the target value in the current pixel with the current value to obtain a key picture.
Further, the picture length is equal to the picture width.
A second aspect of the embodiments of the present application provides a device for generating a key picture, where the device for generating a key picture includes:
the calculation unit is used for calculating according to the character string length value of the encryption key and a preset picture size calculation formula to obtain the picture length and the picture width;
the acquisition unit is used for obtaining a conventional picture according to the picture length and the size determined by the picture width;
the determining unit is used for respectively determining target three primary colors from the three primary colors corresponding to each pixel in the conventional picture;
the determining unit is further configured to determine a target value from binary values corresponding to the target three primary colors;
and the replacing unit is used for sequentially replacing the target value with the binary values respectively corresponding to the encryption key and the character string length value to obtain a key picture.
In the implementation process, the device can hide the encryption key in the picture, so that the key can be prevented from being directly acquired; on the other hand, the device can also take the picture as a key carrier, thereby reducing the possibility of identifying the key and effectively ensuring the information security.
A third aspect of the embodiments of the present application provides an electronic device, including a memory and a processor, where the memory is used to store a computer program, and the processor runs the computer program to enable the electronic device to execute the method for generating a key picture according to any one of the first aspect of the embodiments of the present application.
A fourth aspect of the present embodiment provides a computer-readable storage medium, which stores computer program instructions, where the computer program instructions, when read and executed by a processor, perform the method for generating a key picture according to any one of the first aspect of the present embodiment.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are required to be used in the embodiments of the present application will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present application and therefore should not be considered as limiting the scope, and that those skilled in the art can also obtain other related drawings based on the drawings without inventive efforts.
Fig. 1 is a schematic flowchart of a method for generating a key picture according to an embodiment of the present application;
fig. 2 is a schematic flowchart of another key picture generation method according to an embodiment of the present disclosure;
fig. 3 is a schematic structural diagram of a key picture generation apparatus according to an embodiment of the present disclosure;
fig. 4 is a schematic structural diagram of another key picture generation apparatus according to an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be described below with reference to the drawings in the embodiments of the present application.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures. Meanwhile, in the description of the present application, the terms "first", "second", and the like are used only for distinguishing the description, and are not to be construed as indicating or implying relative importance.
Example 1
Referring to fig. 1, fig. 1 is a schematic flowchart illustrating a method for generating a key picture according to an embodiment of the present application. The generation method of the key picture comprises the following steps:
s101, calculating according to the character string length value of the encryption key and a preset picture size calculation formula to obtain the picture length and the picture width.
As an optional implementation manner, before the step of calculating according to the string length value of the encryption key and the preset picture size calculation formula to obtain the picture length and the picture width, the method further includes:
an encryption key is generated.
In this embodiment, the method may preferentially detect the project requirements, and encrypt the requirement points to obtain the encryption key when detecting that the project requirements include the security requirements.
In this embodiment, the method may encrypt data to be encrypted according to a preset encryption algorithm to obtain an encryption key; the encryption algorithm at least comprises one or more of DES, AES, 3DES, RSA, DSA and ECC.
In this embodiment, the picture length may be equal to the picture width. It can be seen that this arrangement facilitates the calculation of the picture length and/or the picture width.
In this embodiment, both the picture length and the picture width may be the picture size. Therefore, the picture size calculation formula is a calculation formula for calculating the picture length or the picture width.
And S102, obtaining a conventional picture according to the size determined by the picture length and the picture width.
In this embodiment, the method generates a conventional picture matched with the picture length and/or the picture width by using a JAVA language image API.
In this embodiment, a regular picture is used to hold the encryption key.
In this embodiment, the normal picture may be a PNG format picture, a JPG format picture, or a JPEG format picture. Such a conventional picture should also typically have the property of being lossless in compression.
S103, respectively determining target three primary colors from the three primary colors corresponding to each pixel in the conventional picture.
In this embodiment, the three primary colors are RGB.
In this embodiment, the target three primary colors are one of the three primary colors RGB, which may be red, green, and blue.
And S104, determining a target value from binary values corresponding to the target three primary colors.
In this embodiment, the RGB three primary colors of each pixel have a value of 0 to 255, the value corresponds to an 8-bit binary system, and the target value is a single digit in the 8-bit binary system.
In this embodiment, the target value is preferably the least significant bit of the 8-bit binary.
And S105, sequentially replacing the target values with binary values corresponding to the encryption key and the character string length value respectively to obtain a key picture.
Implementing this embodiment, a key picture can be generated such that the key picture stores the encryption key. When the encryption key is stored in the conventional picture, the method can modify the least significant bits of the pixels of the conventional picture, so that the encryption key is stored in the key picture in a hidden mode. The hiding process of the encryption key in the method can not destroy the conventional picture. Therefore, when the key picture is placed anywhere in the client or the background, the key picture can not be obtained by guessing easily. When it is desired to read the encryption key, it is also only necessary to read the encryption key in the same read-write order as the encryption order. The writing sequence of the encryption key is independently controllable, and the key picture can be prevented from being guessed and obtained by people, so that the application safety of the encryption key can be improved by the method.
In this embodiment, the placing of the key picture to the client or anywhere in the background means that the picture is manually placed under a resource directory that can be stored in a mobile terminal development project, for example: assets, res, etc. The only limitation of the storage directory is that key pictures can be loaded into the program and read during the program run.
In this embodiment, according to an actual situation, usually, the server side encrypts data, and the client side receives the encrypted data and decrypts the encrypted data according to the encryption key. Therefore, the execution subject of the method is the server.
In this embodiment, the client places the generated key picture on the client, and reads the encryption key from the key picture in the reverse direction to the generation manner of the key picture when the client starts.
In the embodiment of the present application, the execution subject of the method may be a computing device such as a computer and a server, and is not limited in this embodiment.
In this embodiment, an execution subject of the method may also be an intelligent device such as a smart phone and a tablet computer, which is not limited in this embodiment.
It can be seen that, by implementing the method for generating a key picture described in this embodiment, an encryption key can be obtained by encrypting a file to be encrypted according to actual encryption requirements, then a corresponding conventional picture is matched according to the encryption key, and finally, the key length of the encryption key and the encryption key are written into the conventional picture, so that a picture storage process of the encryption key is realized, and a key picture including key information is obtained. Therefore, by implementing the embodiment, the encryption key can be hidden in the picture, so that the key can be prevented from being directly acquired; on the other hand, by implementing the embodiment, the picture can be used as a key carrier, so that the possibility of identifying the key is reduced, and the information security is effectively guaranteed.
Example 2
Referring to fig. 2, fig. 2 is a schematic flowchart illustrating a method for generating a key picture according to an embodiment of the present application. As shown in fig. 2, the method for generating a key picture includes:
s201, encrypting data to be encrypted according to a preset encryption algorithm to obtain an encryption key.
In this embodiment, the data to be encrypted is data that needs to be encrypted.
In this embodiment, the encryption key is generated by the server according to an encryption algorithm. In general, the server has an API for generating a random key. The presentation form of the encryption key is generally a string of text, and functions like a codebook.
If DES algorithm is adopted, symmetric key is generated by adopting relevant API of DES, and the key is generated randomly
In this embodiment, the encryption algorithm at least includes one or more of DES, AES, 3DES, RSA, DSA, and ECC.
In this embodiment, the encryption algorithm may be a symmetric encryption algorithm or an asymmetric encryption algorithm, and this embodiment is not limited in any way.
S202, calculating according to the length value of the character string of the encryption key, a preset character storage digit and a preset length value storage digit to obtain the length and the width of the picture; the character storage digit is used for expressing the number of pixels required for storing a single character; the length value storage digit is used for expressing the number of pixels required for storing the length value of the sub-character string.
S203, calculating according to the length value of the character string, the preset number of character storage digits and the preset number of length value storage digits to obtain the initial length and the initial width.
In this embodiment, the initial length and the initial width may constitute a key storage area. The key storage area is the minimum area required to store the key.
For example, storing five characters of hello requires 5 × 8 to 40 pixels, plus 32 pixels for storing the string key length value "5", resulting in 40+32 to 72 pixels, with v 72 being the initial length and v 72 also being the initial width. Here, the initial length is equal to the initial width.
S204, taking the sum of the initial length and the preset first pixel number as the picture length; and taking the sum of the initial width and the preset number of second pixels as the picture width.
In this embodiment, the preset picture size calculation formula is as follows:
Figure BDA0003323488690000081
Figure BDA0003323488690000091
wherein px is a pixel unit;
8(px) is the number of digits stored for a character;
32(px) is the number of length value bits stored;
a (px) is the number of the first pixels;
and b (px) represents the number of the second pixels.
In this embodiment, the steps S202 to S204 may be calculated by the formula.
In this embodiment, the first pixel number and the second pixel number may be the same, i.e., a-b.
In this embodiment, when a and/or b is not zero, it is stated that the picture length and/or the picture width is not the minimum length and/or the minimum width. Therefore, the calculation result can enable the finally obtained picture to have an additional expansion area, so that the encryption key and the length value of the character string can be effectively stored. Meanwhile, the generation of the extended area can avoid the adjustment of all pixels, thereby ensuring that the encrypted picture has the adjusted pixels and the pixels which are not adjusted, and further improving the reliability of the encrypted picture.
In this embodiment, the first number of pixels and/or the second number of pixels are/is an expanded pixel value. For a picture, the expanded pixel values exist in both the horizontal and vertical directions of the picture. For example, when the first number of pixels and the second number of pixels are both 10 pixels, at least 100 pixels are used as the expansion area. Therefore, the problem of overflow caused by insufficient picture pixel space when data is written can be effectively prevented, and the situation that the encryption key is failed to be written is avoided.
In this embodiment, assuming that the length of the conventional picture without the first pixel number and the second pixel number is x pixels, and the width is y pixels, the area of the expansion area should be [ (10 × x) + (10 × y) +100] pixels.
For example, when the encryption key is "hello", the string length value is 5. At this time, the picture size of
Figure BDA0003323488690000092
Figure BDA0003323488690000101
(this calculation employs rounded-down calculation logic). It can be seen that both the picture length and the picture width can be calculated to be 18px in this process. Accordingly, the regular picture should be a picture of 18px by 18px, and the format may be a PNG format.
In this embodiment, the reason why the length value storage bit number adopts 32 pixels is as follows:
a. the reading of 32 pixels in the reading link is convenient, and the reading of the number of pixels needed to be read subsequently, namely the length of the subsequent reading, can be known;
b. the 32 pixels are adopted because the length is int type at java, 4 bytes (byte) are occupied, and conversion is carried out according to 8 bits (bit) occupied by each byte, so that 32 bits are needed, and considering that the invention modifies one channel, modifying one effective bit is equivalent to modifying one pixel, such as length 5 of 'hello'.
c. The options 64 and 128 are not necessary, which results in wasted picture space, the picture becomes larger, the larger the picture at the mobile terminal is, the larger the memory required for loading the picture into the device during the operation period is, and therefore 32 is sufficient
And S205, obtaining a conventional picture according to the preset color basic tone and the size determined by the length and the width of the picture.
In this embodiment, the color tones include gray, red, blue, green, and the like.
In this embodiment, when the method uses gray, brown, black, or other colors, the color of the picture is darker, so the picture is difficult for the viewer to see. Therefore, the security of the key picture can be considered to be higher when the viewer is not looking clearly.
On the other hand, when the method uses red, green and blue, because each pixel is composed of three colors of RGB, when a specific color channel corresponding to the color tone is selected, the change of the least significant bit of the pixel becomes more subtle, thereby effectively improving the confidentiality of the key picture.
In this embodiment, the format of the regular picture may be a PNG format, a JPG format, or the like.
In this embodiment, a picture with a size corresponding to a color key, a picture length, and a picture width is generated by using a Java image API.
For example, the method may generate a PNG picture of 18 x 18 gray tones.
S206, respectively determining the target three primary colors from the three primary colors corresponding to each pixel in the conventional picture.
And S207, taking one bit with the lowest digit in binary values corresponding to the target three primary colors as a target value.
And S208, sequentially replacing the target values with binary values corresponding to the encryption key and the character string length value respectively to obtain a key picture.
S209, determining the current value from binary values respectively corresponding to the encryption key and the character string length.
And S210, determining the current pixel from the conventional picture according to the sequence from left to right and from top to bottom.
In this embodiment, the picture generally includes a plurality of pixels, and the arrangement of the pixels is generally regular, i.e., how many rows and columns are arranged.
In this embodiment, the key writing sequence may be from left to right, and then from top to bottom among the plurality of pixels. The writing sequence is not limited in this embodiment.
In this embodiment, the method uses the horizontal axis of the conventional picture as the width direction and the vertical axis as the height direction. The "horizontal axis direction, left-to-right, and top-to-bottom order" refers to a manner of horizontal axis and vertical axis, and when the horizontal axis is written with a full line (the boundary is the picture width pixel size), writing is continued from the second line, and when the horizontal axis is written with a full line, the writing is automatically continued from the next line until all data is written.
And S211, replacing the target value in the current pixel with the current value to obtain the key picture.
In this embodiment, the color of each pixel is composed of three primary colors (red, green, and blue), so each pixel color in the computer has three color channels, each channel occupies 8 bits, and has a value in the range of 0x00 to 0xFF (i.e., each channel can represent 0 to 256 colors), and the three channels can represent 256 × 256 colors.
For example, RGB of "a 64d 79" wine red is (166, 77, 121), which is actually represented in the computer in the form of:
RED: 10100110 (from left to right, the number of bits goes from high to low, where the least significant bit is 0);
GREEN: 01001101 (from left to right, the number of bits goes from high to low, where the least significant bit is 1);
BLUE: 01111001 (from left to right, the number of bits goes from high to low, where the least significant bit is 1);
namely: 10100110, 01001101, 01111001 has three least significant bits which are 0, 1, 1 respectively, and the method adopts a mode of modifying the least significant bit of one channel (blue channel).
In this embodiment, the method may write the encryption key to the least significant bit of the blue channel in each pixel, so that the least significant bits of the blue channels of 8 pixels may form a character.
In this embodiment, the modification of the least significant bit is invisible to the naked eye, so that the purpose of hiding data can be achieved. For example, in a red picture, i modify the least significant bit of one pixel point, but the whole feeling of people is red and is not easy to perceive. The reason for the non-selection of other significant bits is similar to that described above, because the high bits with stable modification are more easily detected and the low bits with stable modification are less easily detected.
For example, when the encryption key is "hello", the binary representation of the data actually written to the picture is: the string length value of the encryption key is:
[0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
the encryption key is:
[0,1,1,0,1,0,0,0,0,1,1,0,0,1,0,1,0,1,1,0,1,1,0,0,0,1,1,0,1,1,0,0,0,1,1,0,1,1,1,1]。
specifically, for example, when the writing sequence is horizontal axis direction, writing is started from the first pixel from left to right, the first 32 pixels are written with the key length of the encryption key, and then writing of the encryption key data is started from 32 pixels later until the data writing is completed, wherein each full line of each line is automatically written from the next line from left to right again. Such as: when "hello" is written as an encryption key into an 18 x 18 picture (the size of the picture is calculated in the above example), the pixel boundaries are:
width w ═ 0-18] px, height h ═ 0-18] px;
the conversion of the string length value 5 into binary data is:
0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;
then, row 1 of the picture:
line 1: px (0, 0) ═ w. (0), h (0) to px (17, 0) ═ w. (17), the data inserted during h (0) are:
0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0;
line 2: px (0, 1) ═ w. (0), h (1) to px (17, 1) ═ w. (17), the data inserted during h (1) are:
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, x, x, x, x (where x represents a subsequent position);
the text data is converted into binary data:
0,1,1,0,1,0,0,0,0,1,1,0,0,1,0,1,0,1,1,0,1,1,0,0,0,1,1,0,1,1,0,0,0,1,1,0,1,1,1,1;
the writing of text data may be continued from px (14, 1), i.e., the above-mentioned x position, to the subsequent data.
It can be seen that, by implementing the method for generating a key picture described in this embodiment, a manner of storing an encryption key in the key picture can be provided, so that the application security of the key picture is improved. Specifically, the method writes the encryption key into the least significant bit of the conventional image, and sequentially writes the encryption key into the image in the order of writing from left to right and then from top to bottom in the direction of the transverse axis of the image. The first 32 pixels are used as a storage area of the key length, and the subsequent pixels are used as an encryption key storage area, so that all key information is stored in the picture. During reading, the key length can be read first only by selecting the reading sequence consistent with the writing sequence, and then the encryption key is read according to the key length, so that the extraction operation of the encryption key is completed.
Example 3
Referring to fig. 3, fig. 3 is a schematic structural diagram of a key picture generation apparatus according to an embodiment of the present application. As shown in fig. 3, the key picture generation device includes:
the calculating unit 310 is configured to calculate according to a string length value of the encryption key and a preset picture size calculation formula, so as to obtain a picture length and a picture width;
an obtaining unit 320, configured to obtain a conventional picture according to the size determined by the picture length and the picture width;
the determining unit 330 is configured to determine target three primary colors from the three primary colors corresponding to each pixel in the conventional picture;
the determining unit 330 is further configured to determine a target value from binary values corresponding to the target three primary colors;
the replacing unit 340 is configured to sequentially replace the target values with binary values corresponding to the encryption key and the character string length value, so as to obtain a key picture.
In the embodiment of the present application, for explanation of a key picture generation apparatus, reference may be made to the description in embodiment 1 or embodiment 2, and details are not repeated in this embodiment.
It can be seen that, by implementing the key picture generation apparatus described in this embodiment, the encryption key can be hidden in the picture, so that the key can be prevented from being directly obtained; on the other hand, the device can also take the picture as a key carrier, thereby reducing the possibility of identifying the key and effectively ensuring the information security.
Example 4
Referring to fig. 4, fig. 4 is a schematic structural diagram of a key picture generating device according to an embodiment of the present disclosure. The key picture generation apparatus shown in fig. 4 is optimized by the key picture generation apparatus shown in fig. 3. As shown in fig. 4, the calculating unit 310 is specifically configured to calculate according to the length value of the character string of the encryption key, the preset number of storage bits of the character, and the preset number of storage bits of the length value, so as to obtain the length of the picture and the width of the picture; the character storage digit is used for expressing the number of pixels required for storing a single character; the length value storage digit is used for expressing the number of pixels required for storing the length value of the sub-character string.
As an optional implementation manner, the calculating unit 310 is further specifically configured to calculate according to the length value of the character string of the encryption key, the preset number of storage bits of the character, and the preset number of storage bits of the length value, so as to obtain an initial length and an initial width; taking the sum of the initial length and the preset number of first pixels as the length of the picture; and taking the sum of the initial width and the preset number of second pixels as the picture width.
As an optional implementation, the preset picture size calculation formula is:
Figure BDA0003323488690000151
Figure BDA0003323488690000152
wherein px is a pixel unit;
8(px) is the number of digits stored for a character;
32(px) is the number of length value bits stored;
a (px) is the number of the first pixels;
and b (px) represents the number of the second pixels.
As an alternative embodiment, the obtaining unit 320 is specifically configured to obtain the regular picture according to the preset color basic tone and the size determined by the picture length and the picture width.
As an alternative embodiment, the determining unit 330 is specifically configured to use one bit with the lowest number of bits in the binary values corresponding to the target three primary colors as the target value.
As an alternative embodiment, the replacement unit 340 includes:
a determining subunit 341, configured to determine a current value from binary values corresponding to the encryption key and the length of the character string, respectively;
the determining subunit 341 is further configured to determine, from the conventional picture, a current pixel in an order from left to right and from top to bottom;
a replacing subunit 342, configured to replace the target value in the current pixel with the current value, resulting in a key picture.
In this embodiment, the encryption key may be obtained by encrypting data to be encrypted according to a preset encryption algorithm; the encryption algorithm at least comprises one or more of DES, AES, 3DES, RSA, DSA and ECC.
As an alternative embodiment, the picture length is equal to the picture width.
In the embodiment of the present application, for explanation of a key picture generation apparatus, reference may be made to the description in embodiment 1 or embodiment 2, and details are not repeated in this embodiment.
It can be seen that, by implementing the key picture generation apparatus described in this embodiment, the encryption key can be hidden in the picture, so that the key can be prevented from being directly obtained; on the other hand, the device can also take the picture as a key carrier, thereby reducing the possibility of identifying the key and effectively ensuring the information security.
An embodiment of the present application provides an electronic device, which includes a memory and a processor, where the memory is used to store a computer program, and the processor runs the computer program to enable the electronic device to execute the method for generating a key picture in any one of embodiment 1 or embodiment 2 of the present application.
An embodiment of the present application provides a computer-readable storage medium, which stores computer program instructions, and when the computer program instructions are read and executed by a processor, the method for generating a key picture according to any one of embodiment 1 or embodiment 2 of the present application is executed.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method can be implemented in other ways. The apparatus embodiments described above are merely illustrative, and for example, the flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
In addition, functional modules in the embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
The functions, if implemented in the form of software functional modules and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present application or portions thereof that substantially contribute to the prior art may be embodied in the form of a software product stored in a storage medium and including instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
The above description is only an example of the present application and is not intended to limit the scope of the present application, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, improvement and the like made within the spirit and principle of the present application shall be included in the protection scope of the present application. It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures.
The above description is only for the specific embodiments of the present application, but the scope of the present application is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present application, and shall be covered by the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.
It is noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.

Claims (10)

1. A method for generating a key picture, comprising:
calculating according to the character string length value of the encryption key and a preset picture size calculation formula to obtain the picture length and the picture width;
obtaining a conventional picture according to the sizes determined by the picture length and the picture width;
respectively determining target three primary colors from the three primary colors corresponding to each pixel in the conventional picture;
determining a target value from binary values corresponding to the target three primary colors;
and sequentially replacing the target value with binary values respectively corresponding to the encryption key and the character string length value to obtain a key picture.
2. The method for generating the key picture according to claim 1, wherein the step of calculating according to the length value of the character string of the encryption key and a preset picture size calculation formula to obtain the picture length and the picture width comprises:
calculating according to the length value of the character string of the encryption key, the preset number of storage digits of the character and the preset number of storage digits of the length value to obtain the length and the width of the picture; the character storage digit is used for expressing the number of pixels required for storing a single character; and the length value storage digit is used for expressing the number of pixels required for storing the length value of the sub-character string.
3. The method for generating the key picture according to claim 1, wherein the step of calculating according to the character string length value of the encryption key and a preset picture size calculation formula to obtain the picture length and the picture width comprises:
calculating according to the length value of the character string of the encryption key, the preset number of character storage digits and the preset number of length value storage digits to obtain an initial length and an initial width;
taking the sum of the initial length and a preset first pixel number as the picture length; and taking the sum of the initial width and the preset number of second pixels as the picture width.
4. The method according to claim 3, wherein the preset picture size calculation formula is:
Figure FDA0003323488680000021
Figure FDA0003323488680000022
wherein px is a pixel unit;
said 8(px) is said number of character deposited bits;
said 32(px) is the number of length value storage bits;
the a (px) is the first number of pixels;
the b (px) is the second number of pixels.
5. The method for generating a key picture according to claim 1, wherein the step of obtaining a regular picture according to the size determined by the picture length and the picture width comprises:
and obtaining a conventional picture according to a preset color basic tone and the size determined by the length and the width of the picture.
6. The method for generating a key picture according to claim 1, wherein the step of determining the target value from binary values corresponding to the target three primary colors comprises:
and taking one bit with the lowest bit number in binary values corresponding to the target three primary colors as a target value.
7. The method of claim 6, wherein the step of sequentially replacing the target value with binary values corresponding to the encryption key and the string length value to obtain the key picture comprises:
determining a current value from binary values respectively corresponding to the encryption key and the length of the character string;
determining a current pixel from the conventional picture according to the sequence from left to right and from top to bottom;
and replacing the target value in the current pixel with the current value to obtain a key picture.
8. A key picture generation apparatus, comprising:
the calculation unit is used for calculating according to the character string length value of the encryption key and a preset picture size calculation formula to obtain the picture length and the picture width;
the acquisition unit is used for obtaining a conventional picture according to the picture length and the size determined by the picture width;
the determining unit is used for respectively determining target three primary colors from the three primary colors corresponding to each pixel in the conventional picture;
the determining unit is further configured to determine a target value from binary values corresponding to the target three primary colors;
and the replacing unit is used for sequentially replacing the target value with the binary values respectively corresponding to the encryption key and the character string length value to obtain a key picture.
9. An electronic device, characterized in that the electronic device comprises a memory for storing a computer program and a processor for executing the computer program to cause the electronic device to perform the method of generating a key picture of any one of claims 1 to 7.
10. A readable storage medium, in which computer program instructions are stored, which, when read and executed by a processor, perform the key picture generation method according to any one of claims 1 to 7.
CN202111254202.5A 2021-10-27 2021-10-27 Method and device for generating key picture Active CN113810189B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111254202.5A CN113810189B (en) 2021-10-27 2021-10-27 Method and device for generating key picture

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111254202.5A CN113810189B (en) 2021-10-27 2021-10-27 Method and device for generating key picture

Publications (2)

Publication Number Publication Date
CN113810189A true CN113810189A (en) 2021-12-17
CN113810189B CN113810189B (en) 2024-01-09

Family

ID=78937876

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111254202.5A Active CN113810189B (en) 2021-10-27 2021-10-27 Method and device for generating key picture

Country Status (1)

Country Link
CN (1) CN113810189B (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114448687A (en) * 2022-01-18 2022-05-06 徐工汉云技术股份有限公司 Image file encryption method and system based on RSA

Citations (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2013258488A (en) * 2012-06-11 2013-12-26 Osaka Gas Co Ltd Encryption key generation system and authentication system
WO2017124940A1 (en) * 2016-01-21 2017-07-27 腾讯科技(深圳)有限公司 Method and device for recognizing whether image comprises watermark
CN107481181A (en) * 2017-07-27 2017-12-15 银江股份有限公司 A kind of picture hidden method, restoring method and picture for being used to protect individual privacy hides system
CN110321673A (en) * 2018-03-28 2019-10-11 北京京东尚科信息技术有限公司 Information ciphering method and device, information decryption method and device, security system
CN110516462A (en) * 2019-08-30 2019-11-29 京东数字科技控股有限公司 Method and apparatus for encryption data
CN111079189A (en) * 2019-12-30 2020-04-28 联想(北京)有限公司 Information processing method, electronic equipment and computer readable storage medium
CN111898142A (en) * 2020-07-16 2020-11-06 常州工学院 Password hiding and inquiring method based on picture
WO2020237868A1 (en) * 2019-05-24 2020-12-03 平安科技(深圳)有限公司 Data transmission method, electronic device, server and storage medium
CN112184841A (en) * 2020-09-27 2021-01-05 陕西师范大学 Block replacement generating type information hiding and recovering method, device and medium
CN112634119A (en) * 2020-12-24 2021-04-09 深圳壹账通智能科技有限公司 Watermark adding method, watermark adding device, computer equipment and storage medium
CN113240431A (en) * 2021-06-16 2021-08-10 中国银行股份有限公司 Payment verification method and system based on three primary colors of picture pixels
CN113535164A (en) * 2021-06-11 2021-10-22 中电金信软件有限公司 Front-end interface generation method and device, electronic equipment and storage medium

Patent Citations (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2013258488A (en) * 2012-06-11 2013-12-26 Osaka Gas Co Ltd Encryption key generation system and authentication system
WO2017124940A1 (en) * 2016-01-21 2017-07-27 腾讯科技(深圳)有限公司 Method and device for recognizing whether image comprises watermark
CN107481181A (en) * 2017-07-27 2017-12-15 银江股份有限公司 A kind of picture hidden method, restoring method and picture for being used to protect individual privacy hides system
CN110321673A (en) * 2018-03-28 2019-10-11 北京京东尚科信息技术有限公司 Information ciphering method and device, information decryption method and device, security system
WO2020237868A1 (en) * 2019-05-24 2020-12-03 平安科技(深圳)有限公司 Data transmission method, electronic device, server and storage medium
CN110516462A (en) * 2019-08-30 2019-11-29 京东数字科技控股有限公司 Method and apparatus for encryption data
CN111079189A (en) * 2019-12-30 2020-04-28 联想(北京)有限公司 Information processing method, electronic equipment and computer readable storage medium
CN111898142A (en) * 2020-07-16 2020-11-06 常州工学院 Password hiding and inquiring method based on picture
CN112184841A (en) * 2020-09-27 2021-01-05 陕西师范大学 Block replacement generating type information hiding and recovering method, device and medium
CN112634119A (en) * 2020-12-24 2021-04-09 深圳壹账通智能科技有限公司 Watermark adding method, watermark adding device, computer equipment and storage medium
CN113535164A (en) * 2021-06-11 2021-10-22 中电金信软件有限公司 Front-end interface generation method and device, electronic equipment and storage medium
CN113240431A (en) * 2021-06-16 2021-08-10 中国银行股份有限公司 Payment verification method and system based on three primary colors of picture pixels

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
高华玲;: "基于图像分割和随机LSB的信息隐藏算法", 现代计算机(专业版), no. 15 *

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114448687A (en) * 2022-01-18 2022-05-06 徐工汉云技术股份有限公司 Image file encryption method and system based on RSA

Also Published As

Publication number Publication date
CN113810189B (en) 2024-01-09

Similar Documents

Publication Publication Date Title
US20230360165A1 (en) Method and apparatus for protecting digital photos from alteration
US7324662B2 (en) Method, software, and device for hiding data in binary image, while preserving image quality
US10970804B2 (en) Image processing device and image processing method for selecting regions based on gradiation for embedding a watermark
US20060045309A1 (en) Systems and methods for digital content security
Rejani et al. Pixel pattern based steganography on images
CN110189384B (en) Image compression method, device, computer equipment and storage medium based on Unity3D
CN110634096B (en) Self-adaptive multi-mode information hiding method and device
CN113810189B (en) Method and device for generating key picture
WO2018010118A1 (en) Digital video content security authentication method and system thereof
Ye et al. Noise-free thumbnail-preserving image encryption based on MSB prediction
Ye et al. PRA-TPE: Perfectly recoverable approximate thumbnail-preserving image encryption
US6023511A (en) Cryptosystem for encrypting digital image or voice file
CN111026583B (en) Backup recovery method for multi-private key of blockchain wallet and computer readable storage medium
US11276138B2 (en) Image data encryption and rendering system
CN110955889A (en) Electronic document tracing method based on digital fingerprints
CN115511030A (en) Anti-counterfeiting verification method and device and electronic equipment
CN111092721B (en) Method and device for setting access password
Angel et al. Security Key-Based Steganography for Images
CN111402117A (en) Picture processing method and device, storage medium and client device
CN111030819A (en) Authentication method, system, terminal and storage medium based on encryption and decryption algorithm
US11954756B1 (en) Anti-leak digital document marking system and method using distributed ledger
CN116257868A (en) Data protection method and device based on image steganography, storage medium and terminal
CN115134473B (en) Image encryption method and device
JP5422948B2 (en) Video data transmission server, video data transmission system, and video data transmission method
CN111901120B (en) Steganography method and verification method for anti-counterfeiting information based on electronic official seal text content

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant