Skip to content

Instantly share code, notes, and snippets.

@medina
Last active June 20, 2017 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save medina/d538e53c88c10b2cc8ae9b6398d72bdc to your computer and use it in GitHub Desktop.
Save medina/d538e53c88c10b2cc8ae9b6398d72bdc to your computer and use it in GitHub Desktop.
Playing with Encrypted Images
#!/bin/bash -x
### Uses curl, openssl, ImageMagick (convert, identify)
### Grab an image
URL=https://avatars0.githubusercontent.com/u/54688
IMAGE=medina
curl -L $URL -o$IMAGE.png
### Extract the "raw" image
SIZE=$(identify $IMAGE.png | awk '{print $3}')
convert -depth 32 $IMAGE.png $IMAGE.rgba
### Let's get encrypting!
### $ man enc
### $ openssl enc -h
PASSWORD=itsasecret
for cipher in \
'-des-cbc' '-des-ofb' '-des-cfb' '-des-ecb' \
'-aes-128-cbc' '-aes-128-ofb' '-aes-128-cfb' '-aes-128-ecb'
do
# Note that this "leaks" the password on the command-line!
openssl enc $cipher -in $IMAGE.rgba -out ${IMAGE}${cipher}.rgba -k $PASSWORD
# Put headers back on the raw encrypted images
convert -size $SIZE -depth 32 ${IMAGE}${cipher}.rgba ${IMAGE}${cipher}.png
done

What's going on with these image sizes?

What do the PNG images look like?

ls -lh ${IMAGE}*.png ${IMAGE}*.rgba | awk '{printf "%9s %s\n", $5,$9}'
     1.6M medina-aes-128-cbc.png
     3.2M medina-aes-128-cbc.rgba
     1.6M medina-aes-128-cfb.png
     3.2M medina-aes-128-cfb.rgba
     338K medina-aes-128-ecb.png
     3.2M medina-aes-128-ecb.rgba
     1.6M medina-aes-128-ofb.png
     3.2M medina-aes-128-ofb.rgba
     1.6M medina-des-cbc.png
     3.2M medina-des-cbc.rgba
     1.6M medina-des-cfb.png
     3.2M medina-des-cfb.rgba
     331K medina-des-ecb.png
     3.2M medina-des-ecb.rgba
     1.6M medina-des-ofb.png
     3.2M medina-des-ofb.rgba
     209K medina.png
     3.2M medina.rgba
     ```
@medina
Copy link
Author

medina commented Sep 27, 2016

ECB-mode:
medina-des-ecb

CBC-mode:
medina-des-cbc

@medina
Copy link
Author

medina commented Jun 20, 2017

Install ImageMagick using the instructions for "Mac OS X Binary Release" here: https://www.imagemagick.org/script/download.php

Do use the checksum validation!

$ curl -LO https://www.imagemagick.org/download/binaries/ImageMagick-x86_64-apple-darwin16.4.0.tar.gz
$ grep -A5 ImageMagick-x86_64-apple-darwin16.4.0.tar.gz digest.rdf
  <digest:Content rdf:about="ImageMagick-x86_64-apple-darwin16.4.0.tar.gz">
    <digest:timestamp>2017-06-11T14:46:36-04:00</digest:timestamp>
    <digest:modify-date>2017-03-02T20:10:40-05:00</digest:modify-date>
    <digest:create-date>2017-03-02T20:10:40-05:00</digest:create-date>
    <digest:extent>10774825</digest:extent>
    <digest:sha256>6c6922c3f76c6717c4d1c7a9fcccfd3c3de975eb2fd09402db3c8f1fcdf5c5ee</digest:sha256>
$ shasum -a 256 ImageMagick-x86_64-apple-darwin16.4.0.tar.gz
6c6922c3f76c6717c4d1c7a9fcccfd3c3de975eb2fd09402db3c8f1fcdf5c5ee  ImageMagick-x86_64-apple-darwin16.4.0.tar.gz
$ tar xzvf ImageMagick-x86_64-apple-darwin16.4.0.tar.gz

$ export MAGICK_HOME="$(pwd)/ImageMagick-7.0.6"
$ export PATH="$MAGICK_HOME/bin:$PATH"
$ export DYLD_LIBRARY_PATH="$MAGICK_HOME/lib/"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment