user525146
user525146

Reputation: 3998

Encrypt an image using openssl

I have a .bmp image. I wanted to encrypt the image file using openssl command. The following is the command I have used to encrypt the image.

openssl enc -aes-128-cbc -e -in pic_original.bmp -out aes128cbc.bmp -K 00112233445566778889aabbccddeeff -iv 0102030405060708

As per ECB mode is concerned I should be able to view partial image when I encrypt the file using ECB mode however I cannot see the image at all. The image viewing software says there is bogus header data

Is there any thing wrong in the command I used for encrypting the file. Can someone help me with this please

Thanks

Upvotes: 2

Views: 10478

Answers (3)

anika
anika

Reputation: 11

You need to extract the header from the original image and use it to replace the header of the encrypted file. Generally for a bmp file, the first 54 bytes contain the header info.

to do this:

head -c 54 pic_og.bmp > header
tail -c +55 pic_cbc.bmp > body_cbc
cat header body_cbc > new_enc_cbc.bmp

Upvotes: 0

Not a chance
Not a chance

Reputation: 175

You can easily copy the header back on top of the image:

dd if=/path/oldfile.bmp of=newfile.bmp bs=54 count=1 conv=notrunc

To learn about dd:

man dd

You can search for examples of this on the web .E. Hugo's blog

Upvotes: 4

cababunga
cababunga

Reputation: 3114

That's because you encrypted everything, including header. You should extract bitmap data into a raw stream, encrypt that and attach header back to it.

Upvotes: 3

Related Questions