# Encryption Method for JPEG Bitstreams for Partially Disclosing Visual Information

^{1}

^{2}

^{3}

^{*}

## Abstract

**:**

## 1. Introduction

## 2. Related Work

#### 2.1. Combined Use of Encryption with Image Compression

- Type 1:
- Compression-then-encryption with standard cryptography.For Type 1, images are compressed and then encrypted with a standard cryptography such as AES (advanced encryption standard) (see Figure 1a) [20,21,22]. However, the format of the encrypted data is different from that of compressed data, such as in the case of the JPEG format, so the data cannot be uploaded to most cloud services such as Google Photos.
- Type 2:
- Encryption-then-compression.For Type 2, the visual information of images is protected by using a perceptual encryption method, called a compressible encryption method, and then the encrypted images are compressed with a compression method [1,2,3,23,24] (see Figure 1b). When using the JPEG compression method, the compressed data can maintain the JPEG format [1,2,3]. In addition, this type of encryption has various applications including privacy-preserving deep learning [25,26]. However, given JPEG images prior to encryption, the JPEG images must be decompressed before carrying out encryption. This restriction causes the quality of images to degrade in addition to incurring additional computational costs.
- Type 3:
- Joint encryption and compression.For Type 3, encryption and compression are simultaneously carried out (see Figure 1c) [10,11,12,13,14,15]. For example, the value and position of DCT coefficients are randomly permuted to generate encrypted JPEG images in the middle of encoding. Thus, given JPEG images prior to encryption, the JPEG images must be decompressed before carrying out encryption as well. In addition, a non-standard encoder has to be prepared.
- Type 4:
- Compression-then-encryption with a bitstream-level encryption method.For Type 4, images are compressed and then encrypted with a bitstream-level encryption method [4,5,6,7,8,9,16,17], where bitstream-level encryption is carried out with a stream cipher in many cases (see Figure 1d). Type 4 encryption allows us not only to maintain the JPEG format but to also generate encrypted JPEG images with the same size as that of JPEG images without encryption under some requirements. Type 4 encryption also does not require any modification of encoders and decoders. Encrypted data can be decoded by using a standard JPEG decoder. In addition, the feature of the file size not changing makes it possible to implement an encryption system using mitmproxy [27,28], which is an open-source interactive HTTPS proxy, on a proxy server [17].

#### 2.2. JPEG Bitstreams

#### 2.3. Bitstream-Level-Encryption Considering Marker Code Generation

- Step1:
- Generate a pseudo-random binary number (PRN) sequence consisting of 0 and 1 by using a secret key, K1.
- Step2:
- Analyze an input bitstream and extract bytes that satisfy the encryption requirements from the bitstrem.
- Step3:
- Carry out exclusive-or (XOR) operations between the additional bits of the extracted bytes and the PRN sequence.
- Step4:
- Replace the additional bits with the XOR results.

- Case 1:
- It consists of only Huffman codes.
- Case 2:
- It consists of only additional bits.
- Case 3:
- It consists of Huffman codes and additional bits, and every bit in the Huffman code is 1.
- Case 4:
- It consists of Huffman codes and additional bits, and the Huffman code includes 0.
- Case 5:
- It consists of 0 only, and the byte is located following ${\mathrm{FF}}_{\left(16\right)}$.

## 3. Proposed Method

#### 3.1. Encryption Using Extended-Block Permutation

- Step1:
- Select extended blocks to be encrypted and those to be encrypted and position-shuffled from an original image.
- Step2:
- Extract bytes that satisfy the encryption conditions described in Section 2.3 from the extended blocks selected in Step 1.
- Step3:
- Generate a PRN binary sequence by using secret key K1. Carry out an exclusive-or (XOR) operation between the PRN sequence and additional bits of the extracted bytes.
- Step4:
- Replace the additional bits with the XOR results.
- Step5:
- Permute the positions of the extended blocks selected in Step 1 by using secret key K2.

#### 3.1.1. Selection of Encrypted Regions

#### 3.1.2. Position Scrambling of Extended Blocks

#### 3.1.3. Selection of Visibility Modes

- (a)
- We can divide an image into encrypted and unencrypted regions.
- (b)
- We can freely choose whether to permute extended blocks in each encrypted region.
- (c)
- We can freely choose whether to encrypt AC and DC coefficients in each extended block, respectively.
- (d)
- We can choose a restart interval ($RI$) value.

#### 3.2. Decryption Process

- Step1:
- Select encrypted extended blocks from the encrypted image.
- Step2:
- Restore the position of the permuted extended blocks by using secret key K2.
- Step3:
- Extract bytes that satisfy the encryption conditions described in Section 2.3 from the extended blocks to be decrypted.
- Step4:
- Generate a PRN binary sequence by using secret key K1. Carry out an exclusive-or (XOR) operation between the PRN sequence and additional bits of the extracted bytes.
- Step5:
- Replace the additional bits with the XOR results.

#### 3.3. Threat Model

## 4. Experimental Results and Discussion

#### 4.1. Experimental Setup

#### 4.2. Effects of Block Permutation

#### 4.3. Generating Partially Encrypted Images

#### 4.4. File Size Preserving

#### 4.5. Security Analysis

## 5. Conclusions

## Author Contributions

## Funding

## Data Availability Statement

## Conflicts of Interest

## References

- Kurihara, K.; Kikuchi, M.; Imaizumi, S.; Shiota, S.; Kiya, H. An encryption-then-compression system for JPEG/Motion JPEG standard. IEICE Trans. Fundam.
**2015**, E98-A, 2238–2245. [Google Scholar] [CrossRef] - Ahmad, I.; Shin, S. IIB–CPE: Inter and Intra Block Processing-Based Compressible Perceptual Encryption Method for Privacy- Preserving Deep Learning. Sensors
**2022**, 22, 8074. [Google Scholar] [CrossRef] [PubMed] - Ahmad, I.; Shin, S. A Perceptual Encryption-Based Image Communication System for Deep Learning-Based Tuberculosis Diagnosis Using Healthcare Cloud Services. Electronics
**2022**, 11, 2514. [Google Scholar] [CrossRef] - Niu, X.; Zhou, C.; Ding, J.; Yang, B. JPEG encryption with file size preservation. In Proceedings of the International Conference on Intelligent Information Hiding and Multimedia Signal Processing (IIH-MSP), Harbin, China, 15–17 August 2008; pp. 308–311. [Google Scholar]
- Cheng, H.; Zhang, X.; Yu, J.; Zhang, Y. Encrypted JPEG image retrieval using block-wise feature comparison. J. Vis. Comun. Image Represent.
**2016**, 40, 111–117. [Google Scholar] [CrossRef] - He, J.; Huang, S.; Tang, S.; Huang, J. JPEG Image Encryption with Improved Format Compatibility and File Size Preservation. IEEE Trans. Multimed.
**2018**, 20, 2645–2658. [Google Scholar] [CrossRef] - Qin, C.; Hu, J.; Li, F.; Qian, Z.; Zhang, X. JPEG Image Encryption with Adaptive DC Coefficient Prediction and RS Pair Permutation. IEEE Trans. Multimed.
**2023**, 25, 2528–2542. [Google Scholar] [CrossRef] - Yuan, Y.; He, H.; Yang, Y.; Mao, N.; Chen, F.; Ali, M. JPEG image encryption with grouping coefficients based on entropy coding. J. Vis. Commun. Image Represent.
**2023**, 97, 103975. [Google Scholar] [CrossRef] - Unterweger, A.; Uhl, A. Length-preserving Bit-stream-based JPEG Encryption. In Proceedings of the on Multimedia and security (MM&Sec), New York, NY, USA, 6–7 September 2012; pp. 85–90. [Google Scholar]
- Khan, M.I.; Jeoti, V.; Khan, M.A. Perceptual encryption of JPEG compressed images using DCT coefficients and splitting of DC coefficients into bitplanes. In Proceedings of the International Conference on Intelligent and Advanced Systems (ICIAS), Kuala Lumpur, Malaysia, 15–17 June 2010; pp. 1–6. [Google Scholar]
- Peng, Y.; Fu, C.; Cao, G.; Song, W.; Chen, J.; Sham, C.W. JPEG-compatible Joint Image Compression and Encryption Algorithm with File Size Preservation. ACM Trans. Multimed. Comput. Commun. Appl.
**2024**, 20, 105. [Google Scholar] [CrossRef] - Shimizu, K.; Suzuki, T. Finely Tunable Bitcuboid-Based Encryption With Exception-Free Signed Binarization for JPEG Standard. IEEE Trans. Inf. Forensics Secur.
**2021**, 16, 4895–4908. [Google Scholar] [CrossRef] - Li, P.; Lo, K.T. Joint image encryption and compression schemes based on 16 × 16 DCT. J. Vis. Commun. Image Represent.
**2019**, 58, 12–24. [Google Scholar] [CrossRef] - Li, P.; Sun, Z.; Situ, Z.; He, M.; Song, T. Joint JPEG Compression and Encryption Scheme Based on Order-8-16 Block Transform. IEEE Trans. Intell. Transp. Syst.
**2023**, 24, 7687–7696. [Google Scholar] [CrossRef] - Cao, W.; Leng, X.; Yu, T.; Gu, X.; Liu, Q. A Joint Encryption and Compression Algorithm for Multiband Remote Sensing Image Transmission. Sensors
**2023**, 23, 7600. [Google Scholar] [CrossRef] [PubMed] - Kobayashi, H.; Kiya, H. Bitstream-based jpeg image encryption with file-size preserving. In Proceedings of the IEEE Global Conference on Consumer Electronics (GCCE), Nara, Japan, 9–12 October 2018; pp. 384–387. [Google Scholar]
- Kobayashi, H.; Kiya, H. File-Size Preserving Encryption of JPEG Images in the Bitstream Domain. IEICE Trans. Inf. Syst. Jpn. Ed.
**2019**, J102-D, 787–795. [Google Scholar] - Ra, M.-R.; Govindan, R.; Ortega, A. P3: Toward privacy-preserving photo sharing. In Proceedings of the USENIX Symposium on Networked Systems Design and Implementation (NSDI), Lombard, IL, USA, 2–5 April 2013; pp. 515–528. [Google Scholar]
- Lee, T.H.; Hsu, H.H.; Chang, P.C. Restart marker regulation technique for progressive JPEG image coding in mobile communications. IEEE Commun. Lett.
**2000**, 4, 411–413. [Google Scholar] - Hafsa, A.; Sghaier, A.; Malek, J.; Machhout, M. Image encryption method based on improved ECC and modified AES algorithm. Multimed. Tools Appl.
**2021**, 80, 19769–19801. [Google Scholar] [CrossRef] - Lin, C.-H.; Hu, G.-H.; Chan, C.-Y.; Yan, J.-J. Chaos-Based Synchronized Dynamic Keys and Their Application to Image Encryption with an Improved AES Algorithm. Appl. Sci.
**2021**, 11, 1329. [Google Scholar] [CrossRef] - Yu, P.; Tang, J.; Xia, Z.; Li, Z.; Weng, J. A Privacy-Preserving JPEG Image Retrieval Scheme Using the Local Markov Feature and Bag-of-Words Model in Cloud Computing. IEEE Trans. Cloud Comput.
**2023**, 11, 2885–2896. [Google Scholar] [CrossRef] - Zhou, J.; Liu, X.; Au, O.C.; Tang, Y.Y. Designing an efficient image encryption-then-compression system via prediction error clustering and random permutation. IEEE Trans. Inf. Forensics Secur.
**2014**, 9, 39–50. [Google Scholar] [CrossRef] - Puchala, D.; Stokfiszewski, K.; Yatsymirskyy, M. Encryption before compression coding scheme for JPEG image compression standard. In Proceedings of the Data Compression Conference (DCC), Snowbird, UT, USA, 24–27 March 2020; pp. 313–322. [Google Scholar]
- Kiya, H.; Maung, A.P.M.; Kinoshita, Y.; Imaizumi, S.; Shiota, S. An overview of compressible and learnable image transformation with secret key and its applications. APSIPA Trans. Signal Inf. Process.
**2022**, 11, e11. [Google Scholar] [CrossRef] - Hamano, G.; Imaizumi, S.; Kiya, H. Effects of JPEG Compression on Vision Transformer Image Classification for Encryption-then-Compression Images. Sensors
**2023**, 23, 3400. [Google Scholar] [CrossRef] [PubMed] - Mitmproxy. Available online: https://mitmproxy.org (accessed on 7 March 2024).
- Google Photos. Available online: https://photos.google.com/ (accessed on 7 March 2024).
- ISO/IEC IS-10918-1; International Organization for Standardization. Information technology—Digital Compression and Coding of Continuous-Tone still Images:Requirements and Guidelines. International Organization for Standardization: Geneva, Switzerland, 1994.
- Yan, K.; Wang, X.; Lu, L.; Summers, R.M. DeepLesion: Automated Mining of Large-Scale Lesion Annotations and Universal Lesion Detection with Deep Learning. J. Med. Imaging
**2018**, 5, 036501. [Google Scholar] [CrossRef] [PubMed] - Kodak Lossless True Color Image Suite. Available online: https://www.math.purdue.edu/~lucier/PHOTO_CD/BMP_IMAGES/ (accessed on 7 March 2024).
- Chang, A.H.; Case, B.M. Attacks on image encryption schemes for privacy-preserving deep neural networks. arXiv
**2020**, arXiv:2004.13263. [Google Scholar] - Independent JPEG Group. Available online: https://www.ijg.org (accessed on 7 March 2024).
- Barker, E.B.; Kelsey, J.M. SP 800-90A. Recommendation for Random Number Generation Using Deterministic Random Bit Generators; NIST: Gaithersburg, MD, USA, 2012. [Google Scholar]

**Figure 5.**Five patterns of divided bytes. White, blue, and red regions represent Huffman codes, additional bits, and byte inserted by byte stuffing, respectively.

**Figure 8.**Example of encrypted images. (

**a**) Medical image (768 × 768 pixels). (

**b**) Encrypted medical image. (

**c**) Image with face (2048 × 3072 pixels). (

**d**) Encrypted image with face.

**Figure 9.**Example of encrypted images. (

**a**) Original image. (

**b**) Previous method. (

**c**) Proposed method with block permutation. (

**d**) Proposed method with only AC coefficients. (

**e**) Proposed method with partial encryption and block permutation. (

**f**) Proposed method with partial encryption for only AC coefficients and block permutation.

**Figure 10.**Example of encrypted and unencrypted regions. Red and blue regions represent RST markers and encrypted regions, respectively ($RI$ = 2).

**Figure 12.**Effects of block permutation (kodim03 and kodim23). (

**a**) Original image; (

**b**) Encrypted image without block permutation ($RI$ = 4); (

**c**) Encrypted image with block permutation ($RI$ = 4).

**Figure 13.**Partially encrypted images without block permutation (kodim03). (

**a**) Target area for encryption; (

**b**) Partially encrypted image ($RI$ = 4); (

**c**) Partially encrypted image ($RI$ = 8).

**Figure 14.**Partially encrypted images with block permutation. (

**a**) Partially encrypted image ($RI$ = 4); (

**b**) Partially encrypted image ($RI$ = 8).

**Figure 15.**Partially encrypted images with encryption of only AC coefficients (kodim03, RI = 4). Zoom-in of the boxed region is shown in bottom of each image. (

**a**) Target area for encryption; (

**b**) Partially encrypted image without block permutation; (

**c**) Partially encrypted image with block permutation.

**Figure 18.**Key sensitivity. (

**a**) Original image; (

**b**) Encrypted image ($RI$ = 4, PSNR = 9.28 dB, SSIM = 0.3410); (

**c**) Decrypted image with incorrect keys ($RI$ = 4, PSNR = 9.25 dB, SSIM = 0.3414).

Image | Before Encryption [Bytes] | After Encryption [Bytes] |
---|---|---|

kodim03 | 570,731 | 570,731 |

kodim04 | 738,287 | 738,287 |

kodim10 | 843,457 | 843,457 |

kodim12 | 529,742 | 529,742 |

kodim14 | 841,642 | 841,642 |

kodim18 | 1,259,498 | 1,259,498 |

kodim23 | 592,913 | 592,913 |

kodim24 | 749,104 | 749,104 |

Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |

© 2024 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).

## Share and Cite

**MDPI and ACS Style**

Hirose, M.; Imaizumi, S.; Kiya, H.
Encryption Method for JPEG Bitstreams for Partially Disclosing Visual Information. *Electronics* **2024**, *13*, 2016.
https://doi.org/10.3390/electronics13112016

**AMA Style**

Hirose M, Imaizumi S, Kiya H.
Encryption Method for JPEG Bitstreams for Partially Disclosing Visual Information. *Electronics*. 2024; 13(11):2016.
https://doi.org/10.3390/electronics13112016

**Chicago/Turabian Style**

Hirose, Mare, Shoko Imaizumi, and Hitoshi Kiya.
2024. "Encryption Method for JPEG Bitstreams for Partially Disclosing Visual Information" *Electronics* 13, no. 11: 2016.
https://doi.org/10.3390/electronics13112016