对称加密技术
对称加密使用单一密钥进行加密与解密,操作简单且效率高,适合加密单个文件或小批量数据。常见工具包括:
gpg --symmetric --cipher-algo AES256 file.txt(生成file.txt.gpg);解密命令:gpg --decrypt file.txt.gpg > file.txt(需输入密码)。openssl enc -aes-256-cbc -salt -in file.txt -out file.txt.enc(提示输入密码);解密命令:openssl enc -d -aes-256-cbc -in file.txt.enc -out file.txt(需输入相同密码)。ccrypt file.txt(生成file.txt.cpt);解密命令:ccrypt -d file.txt.cpt(需输入密码)。7z a -t7z -mhe=on -pYourPassword archive.7z file.txt(生成加密的archive.7z);解密命令:7z x -pYourPassword archive.7z。非对称加密技术
非对称加密使用公钥(加密)与私钥(解密)配对,安全性更高,适合需要安全传输或签名的场景。主要工具为GnuPG(GPG):
gpg --full-generate-key(按提示选择密钥类型、长度及有效期);gpg --export -a "Your Name" > public.key(发送给他人用于加密);gpg --encrypt --recipient "Recipient Name" file.txt(生成file.txt.gpg,仅私钥持有者可解密);gpg --decrypt file.txt.gpg > file.txt(需输入私钥密码)。文件系统级加密技术
文件系统级加密将加密层集成到文件系统中,实现透明加密(用户无需手动操作),适合保护整个目录或分区。常见方案包括:
sudo apt-get install ecryptfs-utils;挂载加密目录:sudo mount -t ecryptfs ~/encrypted ~/decrypted(按提示设置加密算法及密码);卸载命令:fusermount -u ~/decrypted。sudo cryptsetup luksFormat /dev/sdX(替换sdX为目标分区);打开加密分区:sudo cryptsetup open /dev/sdX my_encrypted_partition;格式化并挂载:sudo mkfs.ext4 /dev/mapper/my_encrypted_partition,sudo mount /dev/mapper/my_encrypted_partition /mnt/encrypted;关闭分区:sudo umount /mnt/encrypted,sudo cryptsetup close my_encrypted_partition。veracrypt --create /path/to/encrypted_volume --encryption aes --hash sha512 --filesystem ext4 --size 10G(生成10GB加密卷);挂载命令:veracrypt /path/to/encrypted_volume /mnt/encrypted --password YourPassword;卸载命令:veracrypt -d /mnt/encrypted。其他加密工具
rar a -hp archive.rar file.txt(-hp表示加密文件内容和头部,提高安全性);解密命令:rar x archive.rar(提示输入密码)。