openssl批量给tar.gz文件加解密
#!/bin/bash # 密码 password="your_password_here" # 加密函数 encrypt() { input_file="$1" output_file="$input_file.enc" openssl enc -aes-256-cbc -salt -in "$input_file" -out "$output_file" -pass pass:$password } # 解密函数 decrypt() { input_file="$1" output_file="${input_file%.enc}" openssl enc -d -aes-256-cbc -in "$input_file" -out "$output_file" -pass pass:$password } # 加密文件夹中的所有文件 encrypt_folder() { folder="$1" for file in "$folder"/*.tar.gz; do encrypt "$file" done } # 解密文件夹中的所有文件 decrypt_folder() { folder="$1" for file in "$folder"/*.tar.gz.enc; do decrypt "$file" done } # 根据参数选择执行加密或解密 if [ "$1" = "encrypt" ]; then encrypt_folder "/path/to/your/folder" elif [ "$1" = "decrypt" ]; then decrypt_folder "/path/to/your/folder" else echo "Usage: $0 [encrypt|decrypt]" exit 1 fi