用 Base64 写的加解密脚本

这只是个很简单的脚本,有时间再说说 Base64 的原理,先看看流程图:

程序代码如下:

#!/bin/bash

#project deen.sh by vzomik
#description:     encrypt & decrypt text file,
#                       it can auto check the file encrypted or not.

if [ -n $1 ]; then
    filename=$1
else
    echo "You have no input filename to process yet!"
    exit 1
fi


function vz_decrypt
{
unset clear_text && unset cipher_text
cipher_text=`zcat $filename`
echo "$cipher_text" |base64 -d >$filename && cat $filename
echo -e "\n\t file $filename had been decrypted!"
exit 0
}


function vz_encrypt
{
unset clear_text && unset cipher_text
clear_text=`cat $filename`
echo "$clear_text" |base64 -i >$filename && gzip $filename
mv `echo $filename.gz` $filename && zcat $filename
echo -e "\n\t file $filename had been encrypted!"
exit 0
}


if [ -n "$(file $filename |grep 'text')" ]; then
    vz_encrypt
elif [ -n "$(file $filename |grep 'gzip')" ]; then
    vz_decrypt
else
    echo -e "\n\t file $filename can not be authenticated,"
    echo -e "\t so $filename will not encrypt or decrypt!\n"
    exit 1
fi
阅读全文
类别: 默认分类  查看评论

转载于:https://my.oschina.net/vzomik/blog/5403

你可能感兴趣的:(用 Base64 写的加解密脚本)