xref: /onnv-gate/usr/src/common/openssl/doc/apps/enc.pod (revision 2175:b0b2f052a486)
1*2175Sjp161948=pod
2*2175Sjp161948
3*2175Sjp161948=head1 NAME
4*2175Sjp161948
5*2175Sjp161948enc - symmetric cipher routines
6*2175Sjp161948
7*2175Sjp161948=head1 SYNOPSIS
8*2175Sjp161948
9*2175Sjp161948B<openssl enc -ciphername>
10*2175Sjp161948[B<-in filename>]
11*2175Sjp161948[B<-out filename>]
12*2175Sjp161948[B<-pass arg>]
13*2175Sjp161948[B<-e>]
14*2175Sjp161948[B<-d>]
15*2175Sjp161948[B<-a>]
16*2175Sjp161948[B<-A>]
17*2175Sjp161948[B<-k password>]
18*2175Sjp161948[B<-kfile filename>]
19*2175Sjp161948[B<-K key>]
20*2175Sjp161948[B<-iv IV>]
21*2175Sjp161948[B<-p>]
22*2175Sjp161948[B<-P>]
23*2175Sjp161948[B<-bufsize number>]
24*2175Sjp161948[B<-nopad>]
25*2175Sjp161948[B<-debug>]
26*2175Sjp161948
27*2175Sjp161948=head1 DESCRIPTION
28*2175Sjp161948
29*2175Sjp161948The symmetric cipher commands allow data to be encrypted or decrypted
30*2175Sjp161948using various block and stream ciphers using keys based on passwords
31*2175Sjp161948or explicitly provided. Base64 encoding or decoding can also be performed
32*2175Sjp161948either by itself or in addition to the encryption or decryption.
33*2175Sjp161948
34*2175Sjp161948=head1 OPTIONS
35*2175Sjp161948
36*2175Sjp161948=over 4
37*2175Sjp161948
38*2175Sjp161948=item B<-in filename>
39*2175Sjp161948
40*2175Sjp161948the input filename, standard input by default.
41*2175Sjp161948
42*2175Sjp161948=item B<-out filename>
43*2175Sjp161948
44*2175Sjp161948the output filename, standard output by default.
45*2175Sjp161948
46*2175Sjp161948=item B<-pass arg>
47*2175Sjp161948
48*2175Sjp161948the password source. For more information about the format of B<arg>
49*2175Sjp161948see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
50*2175Sjp161948
51*2175Sjp161948=item B<-salt>
52*2175Sjp161948
53*2175Sjp161948use a salt in the key derivation routines. This option should B<ALWAYS>
54*2175Sjp161948be used unless compatibility with previous versions of OpenSSL or SSLeay
55*2175Sjp161948is required. This option is only present on OpenSSL versions 0.9.5 or
56*2175Sjp161948above.
57*2175Sjp161948
58*2175Sjp161948=item B<-nosalt>
59*2175Sjp161948
60*2175Sjp161948don't use a salt in the key derivation routines. This is the default for
61*2175Sjp161948compatibility with previous versions of OpenSSL and SSLeay.
62*2175Sjp161948
63*2175Sjp161948=item B<-e>
64*2175Sjp161948
65*2175Sjp161948encrypt the input data: this is the default.
66*2175Sjp161948
67*2175Sjp161948=item B<-d>
68*2175Sjp161948
69*2175Sjp161948decrypt the input data.
70*2175Sjp161948
71*2175Sjp161948=item B<-a>
72*2175Sjp161948
73*2175Sjp161948base64 process the data. This means that if encryption is taking place
74*2175Sjp161948the data is base64 encoded after encryption. If decryption is set then
75*2175Sjp161948the input data is base64 decoded before being decrypted.
76*2175Sjp161948
77*2175Sjp161948=item B<-A>
78*2175Sjp161948
79*2175Sjp161948if the B<-a> option is set then base64 process the data on one line.
80*2175Sjp161948
81*2175Sjp161948=item B<-k password>
82*2175Sjp161948
83*2175Sjp161948the password to derive the key from. This is for compatibility with previous
84*2175Sjp161948versions of OpenSSL. Superseded by the B<-pass> argument.
85*2175Sjp161948
86*2175Sjp161948=item B<-kfile filename>
87*2175Sjp161948
88*2175Sjp161948read the password to derive the key from the first line of B<filename>.
89*2175Sjp161948This is for compatibility with previous versions of OpenSSL. Superseded by
90*2175Sjp161948the B<-pass> argument.
91*2175Sjp161948
92*2175Sjp161948=item B<-S salt>
93*2175Sjp161948
94*2175Sjp161948the actual salt to use: this must be represented as a string comprised only
95*2175Sjp161948of hex digits.
96*2175Sjp161948
97*2175Sjp161948=item B<-K key>
98*2175Sjp161948
99*2175Sjp161948the actual key to use: this must be represented as a string comprised only
100*2175Sjp161948of hex digits. If only the key is specified, the IV must additionally specified
101*2175Sjp161948using the B<-iv> option. When both a key and a password are specified, the
102*2175Sjp161948key given with the B<-K> option will be used and the IV generated from the
103*2175Sjp161948password will be taken. It probably does not make much sense to specify
104*2175Sjp161948both key and password.
105*2175Sjp161948
106*2175Sjp161948=item B<-iv IV>
107*2175Sjp161948
108*2175Sjp161948the actual IV to use: this must be represented as a string comprised only
109*2175Sjp161948of hex digits. When only the key is specified using the B<-K> option, the
110*2175Sjp161948IV must explicitly be defined. When a password is being specified using
111*2175Sjp161948one of the other options, the IV is generated from this password.
112*2175Sjp161948
113*2175Sjp161948=item B<-p>
114*2175Sjp161948
115*2175Sjp161948print out the key and IV used.
116*2175Sjp161948
117*2175Sjp161948=item B<-P>
118*2175Sjp161948
119*2175Sjp161948print out the key and IV used then immediately exit: don't do any encryption
120*2175Sjp161948or decryption.
121*2175Sjp161948
122*2175Sjp161948=item B<-bufsize number>
123*2175Sjp161948
124*2175Sjp161948set the buffer size for I/O
125*2175Sjp161948
126*2175Sjp161948=item B<-nopad>
127*2175Sjp161948
128*2175Sjp161948disable standard block padding
129*2175Sjp161948
130*2175Sjp161948=item B<-debug>
131*2175Sjp161948
132*2175Sjp161948debug the BIOs used for I/O.
133*2175Sjp161948
134*2175Sjp161948=back
135*2175Sjp161948
136*2175Sjp161948=head1 NOTES
137*2175Sjp161948
138*2175Sjp161948The program can be called either as B<openssl ciphername> or
139*2175Sjp161948B<openssl enc -ciphername>.
140*2175Sjp161948
141*2175Sjp161948A password will be prompted for to derive the key and IV if necessary.
142*2175Sjp161948
143*2175Sjp161948The B<-salt> option should B<ALWAYS> be used if the key is being derived
144*2175Sjp161948from a password unless you want compatibility with previous versions of
145*2175Sjp161948OpenSSL and SSLeay.
146*2175Sjp161948
147*2175Sjp161948Without the B<-salt> option it is possible to perform efficient dictionary
148*2175Sjp161948attacks on the password and to attack stream cipher encrypted data. The reason
149*2175Sjp161948for this is that without the salt the same password always generates the same
150*2175Sjp161948encryption key. When the salt is being used the first eight bytes of the
151*2175Sjp161948encrypted data are reserved for the salt: it is generated at random when
152*2175Sjp161948encrypting a file and read from the encrypted file when it is decrypted.
153*2175Sjp161948
154*2175Sjp161948Some of the ciphers do not have large keys and others have security
155*2175Sjp161948implications if not used correctly. A beginner is advised to just use
156*2175Sjp161948a strong block cipher in CBC mode such as bf or des3.
157*2175Sjp161948
158*2175Sjp161948All the block ciphers normally use PKCS#5 padding also known as standard block
159*2175Sjp161948padding: this allows a rudimentary integrity or password check to be
160*2175Sjp161948performed. However since the chance of random data passing the test is
161*2175Sjp161948better than 1 in 256 it isn't a very good test.
162*2175Sjp161948
163*2175Sjp161948If padding is disabled then the input data must be a multiple of the cipher
164*2175Sjp161948block length.
165*2175Sjp161948
166*2175Sjp161948All RC2 ciphers have the same key and effective key length.
167*2175Sjp161948
168*2175Sjp161948Blowfish and RC5 algorithms use a 128 bit key.
169*2175Sjp161948
170*2175Sjp161948=head1 SUPPORTED CIPHERS
171*2175Sjp161948
172*2175Sjp161948 base64             Base 64
173*2175Sjp161948
174*2175Sjp161948 bf-cbc             Blowfish in CBC mode
175*2175Sjp161948 bf                 Alias for bf-cbc
176*2175Sjp161948 bf-cfb             Blowfish in CFB mode
177*2175Sjp161948 bf-ecb             Blowfish in ECB mode
178*2175Sjp161948 bf-ofb             Blowfish in OFB mode
179*2175Sjp161948
180*2175Sjp161948 cast-cbc           CAST in CBC mode
181*2175Sjp161948 cast               Alias for cast-cbc
182*2175Sjp161948 cast5-cbc          CAST5 in CBC mode
183*2175Sjp161948 cast5-cfb          CAST5 in CFB mode
184*2175Sjp161948 cast5-ecb          CAST5 in ECB mode
185*2175Sjp161948 cast5-ofb          CAST5 in OFB mode
186*2175Sjp161948
187*2175Sjp161948 des-cbc            DES in CBC mode
188*2175Sjp161948 des                Alias for des-cbc
189*2175Sjp161948 des-cfb            DES in CBC mode
190*2175Sjp161948 des-ofb            DES in OFB mode
191*2175Sjp161948 des-ecb            DES in ECB mode
192*2175Sjp161948
193*2175Sjp161948 des-ede-cbc        Two key triple DES EDE in CBC mode
194*2175Sjp161948 des-ede            Two key triple DES EDE in ECB mode
195*2175Sjp161948 des-ede-cfb        Two key triple DES EDE in CFB mode
196*2175Sjp161948 des-ede-ofb        Two key triple DES EDE in OFB mode
197*2175Sjp161948
198*2175Sjp161948 des-ede3-cbc       Three key triple DES EDE in CBC mode
199*2175Sjp161948 des-ede3           Three key triple DES EDE in ECB mode
200*2175Sjp161948 des3               Alias for des-ede3-cbc
201*2175Sjp161948 des-ede3-cfb       Three key triple DES EDE CFB mode
202*2175Sjp161948 des-ede3-ofb       Three key triple DES EDE in OFB mode
203*2175Sjp161948
204*2175Sjp161948 desx               DESX algorithm.
205*2175Sjp161948
206*2175Sjp161948 idea-cbc           IDEA algorithm in CBC mode
207*2175Sjp161948 idea               same as idea-cbc
208*2175Sjp161948 idea-cfb           IDEA in CFB mode
209*2175Sjp161948 idea-ecb           IDEA in ECB mode
210*2175Sjp161948 idea-ofb           IDEA in OFB mode
211*2175Sjp161948
212*2175Sjp161948 rc2-cbc            128 bit RC2 in CBC mode
213*2175Sjp161948 rc2                Alias for rc2-cbc
214*2175Sjp161948 rc2-cfb            128 bit RC2 in CFB mode
215*2175Sjp161948 rc2-ecb            128 bit RC2 in ECB mode
216*2175Sjp161948 rc2-ofb            128 bit RC2 in OFB mode
217*2175Sjp161948 rc2-64-cbc         64 bit RC2 in CBC mode
218*2175Sjp161948 rc2-40-cbc         40 bit RC2 in CBC mode
219*2175Sjp161948
220*2175Sjp161948 rc4                128 bit RC4
221*2175Sjp161948 rc4-64             64 bit RC4
222*2175Sjp161948 rc4-40             40 bit RC4
223*2175Sjp161948
224*2175Sjp161948 rc5-cbc            RC5 cipher in CBC mode
225*2175Sjp161948 rc5                Alias for rc5-cbc
226*2175Sjp161948 rc5-cfb            RC5 cipher in CFB mode
227*2175Sjp161948 rc5-ecb            RC5 cipher in ECB mode
228*2175Sjp161948 rc5-ofb            RC5 cipher in OFB mode
229*2175Sjp161948
230*2175Sjp161948=head1 EXAMPLES
231*2175Sjp161948
232*2175Sjp161948Just base64 encode a binary file:
233*2175Sjp161948
234*2175Sjp161948 openssl base64 -in file.bin -out file.b64
235*2175Sjp161948
236*2175Sjp161948Decode the same file
237*2175Sjp161948
238*2175Sjp161948 openssl base64 -d -in file.b64 -out file.bin
239*2175Sjp161948
240*2175Sjp161948Encrypt a file using triple DES in CBC mode using a prompted password:
241*2175Sjp161948
242*2175Sjp161948 openssl des3 -salt -in file.txt -out file.des3
243*2175Sjp161948
244*2175Sjp161948Decrypt a file using a supplied password:
245*2175Sjp161948
246*2175Sjp161948 openssl des3 -d -salt -in file.des3 -out file.txt -k mypassword
247*2175Sjp161948
248*2175Sjp161948Encrypt a file then base64 encode it (so it can be sent via mail for example)
249*2175Sjp161948using Blowfish in CBC mode:
250*2175Sjp161948
251*2175Sjp161948 openssl bf -a -salt -in file.txt -out file.bf
252*2175Sjp161948
253*2175Sjp161948Base64 decode a file then decrypt it:
254*2175Sjp161948
255*2175Sjp161948 openssl bf -d -salt -a -in file.bf -out file.txt
256*2175Sjp161948
257*2175Sjp161948Decrypt some data using a supplied 40 bit RC4 key:
258*2175Sjp161948
259*2175Sjp161948 openssl rc4-40 -in file.rc4 -out file.txt -K 0102030405
260*2175Sjp161948
261*2175Sjp161948=head1 BUGS
262*2175Sjp161948
263*2175Sjp161948The B<-A> option when used with large files doesn't work properly.
264*2175Sjp161948
265*2175Sjp161948There should be an option to allow an iteration count to be included.
266*2175Sjp161948
267*2175Sjp161948The B<enc> program only supports a fixed number of algorithms with
268*2175Sjp161948certain parameters. So if, for example, you want to use RC2 with a
269*2175Sjp16194876 bit key or RC4 with an 84 bit key you can't use this program.
270*2175Sjp161948
271*2175Sjp161948=cut
272