Split large file in smaller files

Split

# split -b300M bigfile.zip bigfile.zip.
# ls -al
total 3110156
drwxr-xr-x  2 root root       4096 Sep  6 21:02 .
drwx------ 19 root root       4096 Sep  6 21:01 ..
-rw-r--r--  1 root root 1592381288 Sep  6 21:01 bigfile.zip
-rw-r--r--  1 root root  314572800 Sep  6 21:01 bigfile.zip.aa
-rw-r--r--  1 root root  314572800 Sep  6 21:01 bigfile.zip.ab
-rw-r--r--  1 root root  314572800 Sep  6 21:01 bigfile.zip.ac
-rw-r--r--  1 root root  314572800 Sep  6 21:01 bigfile.zip.ad
-rw-r--r--  1 root root  314572800 Sep  6 21:01 bigfile.zip.ae
-rw-r--r--  1 root root   19517288 Sep  6 21:02 bigfile.zip.af

combine

# cat bigfile.zip.aa bigfile.zip.ab bigfile.zip.ac bigfile.zip.ad 
bigfile.zip.ae bigfile.zip.af > bigfile.zip

Encrypt or Decrypt files

encrypt.sh

#!/bin/bash

if [[ -z $1 ]]; then
  echo "You need to specify an input file"
  exit 1
else
  infile=$1
  outfile=${infile}.enc
  if [[ -f ${infile} ]]; then
    if [[ -f ${outfile} ]]; then
        echo "target file ${outfile} already exists"
        exit 1
    fi
    sha1sum ${infile} |awk '{print $1}' > ${infile}.sha1
    cat ${infile} |openssl enc -aes-256-cbc -md sha512 -pbkdf2 -iter 1000 -salt > ${outfile}
    if [[ $? -eq 0 ]]; then
      rm ${infile}
    else 
      rm ${outfile}
      exit 1
    fi
  fi
fi


decrypt.sh

#!/bin/bash

infile=$1
outfile=`echo ${infile} |sed 's/.enc//'`

if [[ -f ${infile} ]]; then
  if [[ -f ${outfile} ]]; then
    echo "target file ${outfile} already exists"
    exit 1
  fi

  cat ${infile} |openssl enc -d -aes-256-cbc -md sha512 -pbkdf2 -iter 1000 -salt > ${outfile}
  if [[ -f ${outfile}.sha1 ]]; then
    givensha1hash=`cat ${outfile}.sha1 |awk '{print $1}'`
    resultsha1hash=`sha1sum ${outfile} |awk '{print $1}'`
    if [[ ${givensha1hash} != ${resultsha1hash} ]]; then
      echo "Warning: SHA1 checksum does not match!"
      rm ${outfile}
      exit 1
    else
      rm ${infile}
    fi
  fi
fi