Last active
November 9, 2021 20:09
-
-
Save juanesarango/aaa10f37c86d642bb22bc2d743416572 to your computer and use it in GitHub Desktop.
π Decrypt shared data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /bin/bash | |
| KEYS_FILE=gpg_keys.txt | |
| MD5_FILE=md5.txt | |
| INDIR=`pwd` | |
| OUTDIR=`pwd`/outdir | |
| mkdir -p $OUTDIR | |
| # Decrypt and decompress | |
| while read -r SAMPLE KEY; do | |
| echo 'Decrypting' $SAMPLE'.tar.gz.gpg' | |
| echo $KEY | gpg2 --batch --passphrase-fd 0 --armor --decrypt $INDIR/$SAMPLE.tar.gz.gpg > $OUTDIR/$SAMPLE.tar.gz | |
| echo 'Decompressing' $SAMPLE'.tar.gz' | |
| mkdir -p $OUTDIR/$SAMPLE | |
| tar -xvzf $OUTDIR/$SAMPLE.tar.gz -C $OUTDIR/$SAMPLE | |
| done < $KEYS_FILE | |
| echo 'Checking data integrity with md5 checksum' | |
| RESULTS=$OUTDIR/md5_checks.txt | |
| cp $MD5_FILE $OUTDIR/$MD5_FILE | |
| cd $OUTDIR | |
| md5sum -c $MD5_FILE > $RESULTS | |
| # Check all files are OK | |
| if [ `cat $RESULTS | wc -l` -eq `cat $RESULTS | grep OK | wc -l` ]; then | |
| echo 'All files are OK'; | |
| else | |
| echo "" | |
| echo "The following files didn't pass the md5 checksum:" | |
| echo "" | |
| cat $RESULTS | grep -v OK; | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To share data through unsecure channels, these must be at encrypted (and compressed to be more efficient). And a basic integrity hash should be run to chek that the received data has not been corrupted during the process.
This script: Decrypts, Decompresses and Checks for file integrity.