用 openssl enc 加密文件(AES-256 + PBKDF2)
上传或发送前,一条命令给文件加上密码保护。
用 openssl enc -aes-256-cbc -pbkdf2 -in secret.txt -out secret.txt.enc 加密,解密时加上 -d 参数即可。
01命令
命令
$ openssl enc -aes-256-cbc -pbkdf2 -in secret.txt -out secret.txt.enc02作用说明
openssl enc 直接对文件做对称加密:-aes-256-cbc 指定 AES-256 CBC 模式,-pbkdf2 会把口令拉伸成安全密钥,大幅提高暴力破解成本。不加 -pbkdf2 会退回过时的旧派生方式——旧文件可能兼容,新文件不应再使用。如果密文要通过邮件或纯文本传输,加上 -a 输出 base64。
03风险
!注意: openssl enc 默认不带完整性校验,更严谨可改用 -aes-256-gcm 或另行签名;忘记口令数据就彻底无法恢复。命令行里不会暴露口令本身,但会留下所用算法,注意 shell 历史记录。
04撤销
撤销
$ openssl enc -d -aes-256-cbc -pbkdf2 -in secret.txt.enc -out secret.txt05来源
- openssl-enc(1ssl) — Debian bookworm依据: Documents 'openssl enc' with cipher names like aes-256-cbc, the -pbkdf2 key-derivation option and -d for decryption, with matching encrypt/decrypt examples.
- openssl-enc(1) — Arch Manual Pages依据: Same enc command documented, warning that the default digest/key derivation is deprecated and recommending -pbkdf2.
最后验证: 2026-09-19 · 分类: 安全与隐私