CHAPTER 6Using Cryptography with Images

At this point, you should be feeling confident in your ability to encrypt and decrypt messages. In this chapter, you will expand on what you know to include the cryptography of images. Through exercises in this chapter, you will be able to identify problems with different modes of encryption and learn alternative ways to get results. To complete our study of image cryptography, we will close the chapter with steganography. Through this chapter, you will do the following:

  • Gain an understanding of image and cryptography libraries
  • Learn about AES modes of operations
  • Explore various cryptography methods for images
  • Hide and read media within an image using Python

Simple Image Cryptography

Before we get into various libraries that can be used for image cryptography, I wanted to share a simple method that will allow you to encrypt and decrypt a file. The entire process relies on looping through the bits of an image and then bitwise exclusive (XOR) them with the bit and the key. To decrypt the image, we simply reverse the XOR operation.

In the following example and the subsequent ones in this chapter, we will be encrypting the original image and then saving it with an e in front of the name. When we decrypt the image, we save it with a d in front of the name. The reason we're doing this is to be able to compare the original image with the decrypted image to see if there is any apparent data loss.

Figure 6.1 shows the original image we will ...

Get Implementing Cryptography Using Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.