脚本内容:
#!/bin/bash
# key和iv为32位字母数字
key=""
iv=""
# 加密
encrypt(){
infile=$1
outfile=encrypt_$infile
openssl enc -e -aes-256-cbc -a -K ${key} -iv ${iv} -nosalt -in $infile -out $outfile && echo "--加密成功--$outfile" || echo "异常,请输入crypt.sh encrypt|decrypt 文件名"
}
# 解密
decrypt(){
infile=$1
outfile=decrypt_$infile
openssl enc -e -aes-256-cbc -a -K ${key} -iv ${iv} -nosalt -d -in $infile -out $outfile && echo "--解密成功--$outfile" || echo "异常,请输入crypt.sh encrypt|decrypt 文件名"
}
case $1 in
encrypt) encrypt $2
;;
decrypt) decrypt $2
;;
*) echo '请输入crypt.sh encrypt|decrypt 文件名'
;;
esac
评论区