File: epic-crypt-gpg

package info (click to toggle)
epic5 3.0.3-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 5,328 kB
  • sloc: ansic: 75,810; makefile: 648; ruby: 227; python: 215; sh: 78; perl: 13
file content (32 lines) | stat: -rwxr-xr-x 831 bytes parent folder | download | duplicates (16)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
#
# This is a simplistic encryption demonstrating the principles
# of the protocol, while being quite usable.
#
# the first input line contains words, the first of which is the key,
# and additional arguments, which aren't used right now, so they are
# discarded.
#
# When the end of the line is reached, the rest of the input is to be
# read as binary input of the plaintext or cyphertext in _binary_ mode.
# What this means for plaintext is that the newline terminator won't
# be present.

function encrypt {
	( echo "$KEY" ; cat ) | gpg -c -z 9 --batch --passphrase-fd 0
}

function decrypt {
	( echo "$KEY" ; cat ) | gpg --batch --passphrase-fd 0
}

proto="$1"
shift 1

read KEY TRASH

case "$proto" in
encrypt) encrypt "$@" ;;
decrypt) decrypt "$@" ;;
*)	echo `basename $0` "{encrypt|decrypt} < text" 1>&2 ;;
esac