Picture encryption transmission method
Through multi-level encryption processing of JPEG image files, the problems of insufficient security and increased data volume in image encryption transmission in the existing technology are solved, and efficient and safe image encryption transmission is achieved, which increases the difficulty of cracking and keeps the data volume stable. .
Patent Information
- Application Number
- CN202410459974.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-17
- Publication Date
- 2024-08-23
AI Technical Summary
The existing technology lacks effective multi-level encryption methods in image encryption and transmission, which is easy to be cracked. Base64-based conversion increases the data volume and transmission time, and reduces system throughput.
Through multi-level encryption of the SOI header information, SOF identification information and pixel blocks of JPEG image files, MD5 hash values, XOR operations and keys are used for encryption and decryption to ensure that the file format is not recognized and increase the difficulty of cracking. And keep the data volume basically unchanged.
It effectively improves the security and cracking difficulty of image encryption, ensures the integrity and consistency of data transmission, maintains the stability of data volume, and improves the throughput and efficiency of the system.
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of encrypted picture transmission, and in particular to a method for encrypted picture transmission. Background Art
[0002] Currently, the industry generally does not encrypt images transmitted over the network. In some scenarios, images are converted into base64 strings, which cannot effectively protect the privacy of the data contained in the images. In addition, the use of base64 conversion will increase the size of the data to be transmitted and increase the transmission time over the network. When a large number of images need to be transmitted, the system throughput will be reduced, resulting in low efficiency.
[0003] Some existing methods for encrypting and transmitting images have a relatively single encryption method for images. For example, an image encryption transmission method disclosed in Publication No. CN108513038A mainly performs scrambled transmission based on the pixel values of the three primary colors RGB. The single encryption method is relatively easy to crack, but is still easily cracked by brute force. Summary of the invention
[0004] The technical problem to be solved by the present invention is to overcome the deficiencies of the prior art and provide a method for encrypting and transmitting pictures.
[0005] The technical solution adopted by the present invention to solve the technical problem is:
[0006] The method for transmitting encrypted images includes the following steps:
[0007] Step 1: Read the original image;
[0008] Step 2: Obfuscate the image SOI header information;
[0009] Step 3: Obfuscate the image SOF identification information;
[0010] Step 4: Generate a key and encrypt based on the key;
[0011] Step 5: Encrypted transmission;
[0012] Step 6: Receive the encrypted image and decrypt it.
[0013] The step 2 includes the following sub-steps:
[0014] 2-1: Calculate the image based on the MD5 information digest algorithm to obtain a hash value;
[0015] 2-2: Place the MD5 hash summary in the image file header;
[0016] 2-3: Starting from the image SOI marker, a random byte is added to each file header byte, and the random byte is inserted before the real byte to construct a new, obfuscated byte stream.
[0017] 2-4: Perform an XOR operation on the real SOI byte and its corresponding random byte.
[0018] The identifier of the hash digest in 2-2 begins with a fixed sequence 0xFFE6, followed by 2 bytes indicating the length of the data.
[0019] After processing in step 2-3, the image header information becomes twice the original number of bytes, with two bytes in a group. The first byte of each group of bytes is randomly generated, and the second byte is the real byte information of the original image.
[0020] The step three includes the following sub-steps:
[0021] 3-1: Find the SOF0 marker (0xFFC0) of the JPEG file;
[0022] 3-2: Get the 5 bytes following the SOF0 marker, perform XOR operation on the upper four bits and the lower four bits of each byte, store the XOR result in the original upper four bits, and keep the lower four bits unchanged.
[0023] The 5 bytes in 3-2 represent the sample precision, image height and width respectively.
[0024] The step 4 includes the following sub-steps:
[0025] 4-1: Read the SOF module, obtain the color mode and bit depth of the image, and get the number of bytes per pixel;
[0026] 4-2: Calculate the number of bytes of each color component according to 4-1, and read the byte code stream of each pixel in turn;
[0027] 4-3: Read the original pixel data of the image, split the image into 64 pixels as a pixel block, put the byte code of each pixel block into a byte array, and form Mn arrays;
[0028] 4-4: Randomly generate a string of 256 ASCII codes as the key R;
[0029] 4-5: XOR Mn with Mn-1 to get Mn, XOR Mn-1 with Mn-2 to get Mn-1, and so on until the M1 array is processed, then XOR M1 with the key R to get M1. At this point, the data of all arrays are encrypted using XOR, and the original data used for XOR is also overwritten.
[0030] When the decryption is performed in step 6, the following sub-steps are included:
[0031] 6-1: Read the SOI file header, group the header data into two bytes, take the second byte in each group and perform XOR operation with the first byte to obtain the original data;
[0032] 6-2: Process each group of data in turn, and finally merge the second bytes in each group of data to restore the original file header;
[0033] 6-3: Read the SOF image identification parameter block, take out the 5 bytes after SOFT0, perform XOR operation on the lower four bits and the upper four bits of each byte, put the result into the upper four bits, and restore the sample precision, height, and width information of the original image;
[0034] 6-4: Read the image pixel data after the SOF block, split it into groups of 64 pixels, and process each group of pixel blocks Mn separately;
[0035] 6-5: Use the key R to perform XOR decryption on the pixel block M1 to obtain the original data of M1, and use the original data of M1 to perform XOR decryption on the pixel block M2... Use the pixel block Mn-1 to perform XOR decryption on the pixel block Mn, and so on, perform XOR decryption on each pixel block to restore the original pixel data;
[0036] 6-6: Use MD5 to calculate a hash value for the image again, and compare it with the hash value stored in the APP10 area of the SOI file header. If they are consistent, it means that the decryption is successful. Otherwise, it means that the received image is incomplete or the key is wrong, resulting in the inability to restore the original image. The image must be sent and received again.
[0037] Compared with the prior art, the present invention has the following beneficial effects:
[0038] 1. This application encrypts the file header SOI data, making it not conform to the standard image file format, so that the software cannot recognize the image and prompts a format error;
[0039] 2. This application encrypts the SOF identification block data to deal with the situation where the file header is skipped during brute force decoding. When directly reading the SOF module data to try to parse the image, because the correct image sample accuracy, height, width, and color mode cannot be obtained, it is impossible to determine how many bytes the original image uses to display one pixel of information, which increases the difficulty of cracking;
[0040] 3. The encryption of pixel blocks is the core step of this application. By splitting the file into multiple pixel blocks, chaining XOR encryption is performed on each pixel block, and finally encrypting it with a key, all pixel data is changed. Without the key, it is impossible to restore the original data. At this time, the picture file becomes a garbled file;
[0041] 4. This application is based on the internationally accepted image file format protocol, and encrypts different sections in the protocol separately, including the file header, file symbol information, and pixel data. The multi-level encryption process makes the image bytecode data more complex and the cracking difficulty is greatly increased. In addition, only a small amount of obfuscation bytecode is added to the SOI header during the encryption process, and the size of the entire file remains basically unchanged. DETAILED DESCRIPTION
[0042] The technical solutions in the embodiments of the present invention are described clearly and completely below. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0043] Currently, the JPEG image format consists of: SOI (file header) + APP0 (image identification information) + DQT (define quantization table) + SOF0 (basic image information) + DHT (define Huffman table) + DRI (define restart interval) + SOS (start of scan line) + EOI (end of file).
[0044] This application mainly improves the picture encryption based on the pictures in .jpg and / or .jpeg format. Specifically, the picture encryption transmission method includes the following steps:
[0045] Step 1: Read the original image;
[0046] Step 2: Obfuscate the image SOI header information;
[0047] The step 2 includes the following sub-steps:
[0048] 2-1: To ensure that the original data of the image is complete after encryption and decryption, the image is calculated based on the MD5 information digest algorithm to obtain a hash value generated based on the MD5 algorithm;
[0049] 2-2: Place this 16-byte MD5 hash digest in the APP10 area of the image file header;
[0050] The identifier of the hash summary in 2-2 begins with a fixed sequence 0xFFE6, followed by 2 bytes indicating the length of the data. Since the MD5 hash is a fixed length of 16 bytes, the parser can accurately identify and read this part of the content.
[0051] When decoding from the starting point SOI (Start of Image) of a JPEG file, once the 0xFFE6 marker is encountered, the system can automatically identify that this is the APP10 segment and extract the preset MD5 hash value accordingly. The receiving end calculates the new MD5 hash of the restored original image data and compares it with the hash embedded in APP10 to ensure the integrity and consistency of the data during the entire transmission and processing process.
[0052] 2-3: To further enhance security and prevent unauthorized direct parsing, we deeply obfuscate the underlying structure of the JPEG file. Specifically, starting from the image SOI marker, a random byte is added to each file header byte, which is inserted before the real byte to construct a new, obfuscated byte stream. After this processing, the image header information becomes twice the original number of bytes, with two bytes in a group. The first byte of each group of bytes is randomly generated, and the second byte is the real byte information of the original image.
[0053] 2-4: Perform a binary exclusive OR (XOR) operation on each set of real SOI bytes and its corresponding random bytes. By obfuscating the JPEG header information, it is possible to effectively prevent unauthorized users from directly reading and understanding the file structure, thereby reducing the possibility of tampering or copying.
[0054] Step 3: Obfuscate the image SOF identification information;
[0055] In the JPEG file format, the height and width information of the image is stored in the SOF (Start of Frame) marker segment. The first byte after the SOF0 marker is the sample precision, usually one byte representing the bit depth of each component. The next two bytes represent the height of the image, with the high-order byte in front and the low-order byte in the back. The next two bytes represent the width of the image, with the high-order byte in front. Therefore, after the SOF0 marker, starting from the third byte, it is the starting bit of the height information, and the fifth byte and the following byte are the starting bits of the width information. Step three includes the following sub-steps:
[0056] 3-1: Find the SOF0 marker (0xFFC0) of the JPEG file;
[0057] 3-2: Get the 5 bytes following the SOF0 marker. These 5 bytes represent the sample precision, image height, and width respectively. Perform an XOR operation on the high four bits and the low four bits of each byte, store the XOR result in the original high four bits, and keep the low four bits unchanged.
[0058] In this way, the original height and width values and sample precision information are obfuscated. Obfuscating important metadata such as height and width can not only prevent image size information from leaking sensitive information, such as resolution under specific devices or scenarios, but also prevent unauthorized image recipients from accurately reading data. The advantage of this method is that the XOR operation is a simple bit operation, which is easy to implement and has good reversibility. When decrypting, you only need to use the same XOR mask to restore the original data, because only the upper four bits of each byte are XORed and the original value of the lower four bits is retained. Therefore, if the original information is not restored, the decoder can still read and parse the information in the original format, but it can only read wrong data.
[0059] Step 4: Generate a key and encrypt based on the key;
[0060] The step 4 includes the following sub-steps:
[0061] 4-1: Read the SOF module, obtain the color mode and bit depth of the image, and get the number of bytes per pixel;
[0062] 4-2: Calculate the number of bytes of each color component according to 4-1, and read the byte code stream of each pixel in turn;
[0063] 4-3: Read the original pixel data of the image, split the image into 64 pixels as a pixel block, put the byte code of each pixel block into a byte array, and form Mn arrays;
[0064] 4-4: Randomly generate a string of 256 ASCII codes as the key R;
[0065] 4-5: XOR Mn with Mn-1 to get Mn, XOR Mn-1 with Mn-2 to get Mn-1, and so on until the M1 array is processed, XOR M1 with the key R to get M1, so far all the array data are encrypted using XOR, and the original data used for XOR is also overwritten. The data of each pixel block of the entire image is inconsistent with the original data, but the data volume does not increase, and the encryption is complete.
[0066] Step 5: Encrypted transmission;
[0067] Step 6: Receive the encrypted image and decrypt it.
[0068] When the decryption is performed in step 6, the following sub-steps are included:
[0069] 6-1: Read the SOI file header, group the header data into two bytes, take the second byte in each group and perform XOR operation with the first byte to obtain the original data;
[0070] 6-2: Process each group of data in turn, and finally merge the second bytes in each group of data to restore the original file header;
[0071] 6-3: Read the SOF image identification parameter block, take out the 5 bytes after SOFT0, perform XOR operation on the lower four bits and the upper four bits of each byte, put the result into the upper four bits, and restore the sample precision, height, and width information of the original image;
[0072] 6-4: Read the image pixel data after the SOF block, split it into groups of 64 pixels, and process each group of pixel blocks Mn separately;
[0073] 6-5: Use the key R to perform XOR decryption on the pixel block M1 to obtain the original data of M1, and use the original data of M1 to perform XOR decryption on the pixel block M2... Use the pixel block Mn-1 to perform XOR decryption on the pixel block Mn, and so on, perform XOR decryption on each pixel block to restore the original pixel data;
[0074] 6-6: Use MD5 to calculate a hash value for the image again, and compare it with the hash value stored in the APP10 area of the SOI file header. If they are consistent, it means that the decryption is successful. Otherwise, it means that the received image is incomplete or the key is wrong, resulting in the inability to restore the original image. The image must be sent and received again.
[0075] The system used in the above-mentioned picture encryption transmission method in the present application includes
[0076] Processing terminal: used to read the original image and perform encryption processing on the image;
[0077] Receiving terminal: used to receive the encrypted image and decrypt it;
[0078] The processing terminal is connected to the receiving terminal for communication to transmit the image.
[0079] The above descriptions are only optional embodiments of the present invention, and are not intended to limit the patent scope of the present invention. All equivalent structural changes made using the contents of the present invention specification under the inventive concept of the present invention, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present invention.
Claims
1. A method for encrypting and transmitting a picture, characterized in that: The following steps are involved: Step 1: Read the original image; Step 2: Obfuscate the image SOI header information; Step 3: Obfuscate the image SOF identification information; Step 4: Generate a key and encrypt based on the key; Step 5: Encrypted transmission; Step 6: Receive the encrypted image and decrypt it.
2. A method for encrypting and transmitting pictures according to claim 1, characterized in that: The step 2 includes the following sub-steps: 2-1: Calculate the image based on the MD5 information digest algorithm to obtain a hash value; 2-2: Place the MD5 hash summary in the image file header; 2-3: Starting from the image SOI marker, a random byte is added to each file header byte, and the random byte is inserted before the real byte to construct a new, obfuscated byte stream. 2-4: Perform an XOR operation on the real SOI byte and its corresponding random byte.
3. A method for encrypting and transmitting pictures according to claim 2, characterized in that: The identifier of the hash digest in 2-2 begins with a fixed sequence 0xFFE6, followed by 2 bytes indicating the length of the data.
4. The method for encrypting and transmitting pictures according to claim 2, characterized in that: After processing in step 2-3, the image header information becomes twice the original number of bytes, with two bytes in a group. The first byte of each group of bytes is randomly generated, and the second byte is the real byte information of the original image.
5. The method for encrypting and transmitting pictures according to claim 2, characterized in that: The step three includes the following sub-steps: 3-1: Find the SOF0 marker of the JPEG file as 0xFFC0; 3-2: Get the 5 bytes following the SOF0 marker, perform XOR operation on the upper four bits and the lower four bits of each byte, store the XOR result in the original upper four bits, and keep the lower four bits unchanged.
6. A method for encrypting and transmitting pictures according to claim 5, characterized in that: The 5 bytes in 3-2 represent the sample precision, image height and width respectively.
7. The method for encrypting and transmitting pictures according to claim 5, characterized in that: The step 4 includes the following sub-steps: 4-1: Read the SOF module, obtain the color mode and bit depth of the image, and get the number of bytes per pixel; 4-2: Calculate the number of bytes of each color component according to 4-1, and read the byte code stream of each pixel in turn; 4-3: Read the original pixel data of the image, split the image into 64 pixels as a pixel block, put the byte code of each pixel block into a byte array, and form Mn arrays; 4-4: Randomly generate a string of 256 ASCII codes as the key R; 4-5: XOR Mn with Mn-1 to get Mn, XOR Mn-1 with Mn-2 to get Mn-1, and so on until the M1 array is processed, then XOR M1 with the key R to get M1. At this point, the data of all arrays are encrypted using XOR, and the original data used for XOR is also overwritten.
8. A method for encrypting and transmitting pictures according to claim 7, characterized in that: When the decryption is performed in step 6, the following sub-steps are included: 6-1: Read the SOI file header, group the header data into two bytes, take the second byte in each group and perform XOR operation with the first byte to obtain the original data; 6-2: Process each group of data in turn, and finally merge the second bytes in each group of data to restore the original file header; 6-3: Read the SOF image identification parameter block, take out the 5 bytes after SOFT0, perform XOR operation on the lower four bits and the upper four bits of each byte, put the result into the upper four bits, and restore the sample precision, height, and width information of the original image; 6-4: Read the image pixel data after the SOF block, split it into groups of 64 pixels, and process each group of pixel blocks Mn separately; 6-5: Use the key R to perform XOR decryption on the pixel block M1 to obtain the original data of M1, and use the pixel block Mn-1 to perform XOR decryption on the pixel block Mn, and so on to perform XOR decryption on each pixel block to restore the original pixel data; 6-6: Use MD5 to calculate a hash value for the image again, and compare it with the hash value stored in the APP10 area of the SOI file header. If they are consistent, it means that the decryption is successful. If they are inconsistent, the image is sent and received again.
Citation Information
Patent Citations
Image encryption transmission method
CN108513038A
Cited By
Intelligent operation and maintenance traffic safety analysis working system
CN119172267A
Joint encryption method for avionics joint test data
CN121923820A
A joint encryption method for avionics test data
CN121923820B
