用 Base64 写的加解密脚本

这只是个很简单的脚本,有时间再说说 Base64 的原理,先看看流程图:
fb2016f84bda3a58034f56c2.jpg
程序代码如下:

#!/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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值