Skip to content

Instantly share code, notes, and snippets.

@Doridian
Last active December 6, 2020 17:22
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 Doridian/75e2566a6e94e305801d to your computer and use it in GitHub Desktop.
Save Doridian/75e2566a6e94e305801d to your computer and use it in GitHub Desktop.
#!/bin/bash
# Requires the following: dd, tr, sed, mktemp, openssl, perl (sadly gzip CLI can not operate on raw zlib data and most OpenSSL distros do not include zlib)
# However even git for windows (MSysGit) includes enough perl to make it fly :)
IV='B380E17A0C476E8A480B55253ABAE666'
KEY='DD1FBB7596D0D58BBF336ABA391366ED3ED7460849BB9EFAB9649C999863BF25'
ENCRYPT=1
if [ "$1" == "-d" ]; then
ENCRYPT=0
else
if [ "$1" != "-e" ]; then
echo "Usage: ./spcrypt.sh [-e / -d] [input] [output]"
exit 1
fi
fi
IN_FILE="$2"
OUT_FILE="$3"
if [ "$ENCRYPT" == "1" ]; then
# Make temp file and put GZip data in
TEMP_GZIP="$(mktemp)"
sed 's/\r\n/\n/g' "$IN_FILE" | sed 's/\r/\n/g' | perl -MCompress::Zlib -e 'undef $/; print compress(<>, 9)' > "$TEMP_GZIP"
# Calculate padding
INPUT_LEN="$(stat -c%s "$TEMP_GZIP")"
INPUT_PADLEN=$(( 16 - ($INPUT_LEN % 16) ))
# Zero-pad file
dd if=/dev/zero of="$TEMP_GZIP" bs=1 count="$INPUT_PADLEN" seek="$INPUT_LEN" status=none
# Encrypt
openssl enc -aes-256-cbc -nosalt -e -K "$KEY" -iv "$IV" -nopad -out "$OUT_FILE" -in "$TEMP_GZIP"
# Clean up temporary file
rm -f "$TEMP_GZIP"
else
# Decrypt, decompress, trim zero-bytes
openssl enc -aes-256-cbc -nosalt -d -in "$IN_FILE" -K "$KEY" -iv "$IV" -nopad | perl -MCompress::Zlib -e 'undef $/; print uncompress(<>)' | tr -d '\000' > "$OUT_FILE"
fi
@toleabivol
Copy link

For speedportpro doesn't work ?
bad decrypt
139985474696960:error:0606508A:digital envelope routines:EVP_DecryptFinal_ex:data not multiple of block length:../crypto/evp/evp_enc.c:551:

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