Maybe this sounds like a stupid question. I'm sorry for that.

I just wanted to know is it possible to encrypt a bitmap image file like *.BMP, and generate the ciphertext which is an obscure bitmap image where each pixel is random (The image maybe would looks like an analog TV without an antenna)?

  • $\begingroup$ You mean to only encrypt the raster, so that the entire file still remains a valid .BMP? $\endgroup$
    – Paul Uszak
    Jun 11, 2021 at 21:04
  • $\begingroup$ @Paul Uszak, yes exactly. $\endgroup$
    – akez
    Jun 12, 2021 at 0:50

1 Answer 1


Yes, it is possible to encrypt a BMP image with any stream cipher.

First of all, you need to cut the first 54-byte of the BMP image into another file. At this point, the data part begins. Then the rest can be encrypted with any stream cipher. After that prepend the header to the encrypted file.

Here the example with OpenSSL. I will use AES with CTR mode where CTR mode turns any block cipher into a stream cipher.

#original file is tux.bmp
head -c 54 tux.bmp > tux_head.part
tail -c +55 tux.bmp > tux_data.part
openssl enc -aes-128-ctr -e -in tux_data.part -out aes-ctr-enc-data.part -K "01234567890123450123456789012345" -iv "00000000000000010000000000000001"
cp tux_head.part encrypted_tux.bmp
cat aes-ctr-enc-data.part >> encrypted_tux.bmp

I've used AES-CTR since OpenSSL has ChaCha20-Poly1305 as a cipher suite that is an authenticated encryption. It will add tag, so it is not useful here.

The input image

enter image description here

The output image

enter image description here

  • $\begingroup$ Needs in to be -in. $\endgroup$
    – Paul Uszak
    Jun 11, 2021 at 21:36
  • $\begingroup$ And there's an oddness. Have you tried this? Mine appears with a green tinge. Is that a 'feature' of the BMP format? $\endgroup$
    – Paul Uszak
    Jun 11, 2021 at 21:39
  • $\begingroup$ @PaulUszak I've corrected, tested, and added the result into the answer, Could you check with your file? $\endgroup$
    – kelalaka
    Jun 11, 2021 at 22:19
  • $\begingroup$ Nope. Just did it on Tux and it comes out with the same green tinge, not the style you have :-( I suspect that it's compatibility options with GIMP as I used that to create my BMPs. Encryption works perfectly though :-) I'll leave it here. Good answer. $\endgroup$
    – Paul Uszak
    Jun 11, 2021 at 23:18
  • 2
    $\begingroup$ It will increase the file size to only 96-bit, nothing more. My example already displays the raster as an image, did your check? One can easily use programming to achieve this. $\endgroup$
    – kelalaka
    Jun 12, 2021 at 7:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.