├── Dockerfile ├── README.md └── asc-to-gif.sh /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:trusty 2 | 3 | RUN apt-get update 4 | RUN apt-get install -y imagemagick bash qrencode zbar-tools 5 | 6 | ADD asc-to-gif.sh ./ 7 | 8 | CMD ./asc-to-gif.sh $SRC $DST 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # asc-key-to-qr-code-gif 2 | 3 | A script that converts ASCII-armored PGP keys (or any texts) to a series of QR codes. 4 | 5 | This allows to transfer texts from a PC to other devices that can scan and 6 | decode QR codes. The script was originally made for transfering keys into [Pass for iOS](https://github.com/mssun/passforios). 7 | 8 | ## Dependencies 9 | 10 | 1. [libqrencode](http://fukuchi.org/works/qrencode/): Generate QR codes. 11 | 2. [imagemagick](https://www.imagemagick.org/script/index.php): Convert PNGs to GIF. 12 | 3. (Optional) [zbar](http://zbar.sourceforge.net): Read and test QR codes. 13 | 14 | ## Usage 15 | 16 | Execute `./asc-to-gif.sh input.txt output.gif`. 17 | 18 | An example of exporting ASCII-armored PGP keys and generate QR codes. 19 | 20 | gpg --export -a "Key ID" > public.asc 21 | gpg --export-secret-keys -a "Key ID" > private.asc 22 | ./asc-to-gif.sh public.asc public.gif 23 | ./asc-to-gif.sh private.asc private.gif 24 | 25 | ### Docker 26 | 27 | You can use [docker](https://docs.docker.com/) to perform the conversions: 28 | 29 | ``` 30 | docker build . -t asc-key-to-qr-code-gif 31 | docker run --rm -v $(pwd):/data -e "SRC=/data/public.asc" -e "DST=/data/public.gif" asc-key-to-qr-code-gif 32 | docker run --rm -v $(pwd):/data -e "SRC=/data/private.asc" -e "DST=/data/private.gif" asc-key-to-qr-code-gif 33 | ``` 34 | -------------------------------------------------------------------------------- /asc-to-gif.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Check requirements 4 | hash qrencode 2>/dev/null || { echo >&2 "Aborting: qrencode not installed"; exit 1; } 5 | 6 | # Check argument 7 | if [ $# -ne 2 ]; then 8 | echo "Usage: $0 " 9 | exit 1 10 | fi 11 | asc_filename=$1 12 | if [ ! -f ${asc_filename} ]; then 13 | echo "Error: ${asc_filename} not found" 14 | exit 1 15 | fi 16 | 17 | # Settings 18 | gif_filename=$2 19 | gif_delay=100 20 | qrcode_size=1732 21 | qrcode_version=30 22 | 23 | # Split the file 24 | rm -f ${asc_filename}.split* 25 | split -b ${qrcode_size} ${asc_filename} ${asc_filename}.split 26 | 27 | # Generate png 28 | for f in ${asc_filename}.split*; do 29 | qrencode -v ${qrcode_version} -o $f.png < $f 30 | rm $f 31 | done 32 | 33 | if hash zbarimg 2>/dev/null; then 34 | # Check png 35 | > ${asc_filename}.scanned 36 | for f in ${asc_filename}.split*; do 37 | printf %s "$(zbarimg --raw -q $f)" >> ${asc_filename}.scanned 38 | done 39 | printf %s "$(cat ${asc_filename})" | diff ${asc_filename}.scanned - 40 | rm ${asc_filename}.scanned 41 | else 42 | echo "Skip testing: zbarimg not installed" 43 | fi 44 | 45 | # Convert to gif 46 | convert -delay ${gif_delay} ${asc_filename}.split* ${gif_filename} 47 | echo "Generated: ${gif_filename}" 48 | 49 | # Clean up png 50 | rm ${asc_filename}.split* 51 | 52 | --------------------------------------------------------------------------------