openssl加密解密文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
openssl enc --help

Usage: enc [options]
Valid options are:
-help Display this summary
-ciphers List ciphers
-in infile Input file
-out outfile Output file
-pass val Passphrase source
-e Encrypt
-d Decrypt
-p Print the iv/key
-P Print the iv/key and exit
-v Verbose output
-nopad Disable standard block padding
-salt Use salt in the KDF (default)
-nosalt Do not use salt in the KDF
-debug Print debug info
-a Base64 encode/decode, depending on encryption flag
-base64 Same as option -a
-A Used with -[base64|a] to specify base64 buffer as a single line
-bufsize val Buffer size
-k val Passphrase
-kfile infile Read passphrase from file
-K val Raw key, in hex
-S val Salt, in hex
-iv val IV in hex
-md val Use specified digest to create a key from the passphrase
-none Don't encrypt
-* Any supported cipher
-engine val Use engine, possibly a hardware device

例子:

加密一个文件

1
2

openssl enc -e -in test -out test.enc -p -k 123 -aes256

-e 指定为加密模式

-in 输入文件,要加密的文件

-out 输出文件,加密后的文件

-p 打印信息

-k 指定密码

-aes256 指定加密算法,这里使用 AES 256位加密, AES 高级加密标准(英语:Advanced Encryption Standard)

解密文件

1
openssl enc -d  -in test.enc -out test -aes256 -k 123