enc.pod 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. =pod
  2. =head1 NAME
  3. openssl-enc,
  4. enc - symmetric cipher routines
  5. =head1 SYNOPSIS
  6. B<openssl enc -I<cipher>>
  7. [B<-help>]
  8. [B<-ciphers>]
  9. [B<-in filename>]
  10. [B<-out filename>]
  11. [B<-pass arg>]
  12. [B<-e>]
  13. [B<-d>]
  14. [B<-a>]
  15. [B<-base64>]
  16. [B<-A>]
  17. [B<-k password>]
  18. [B<-kfile filename>]
  19. [B<-K key>]
  20. [B<-iv IV>]
  21. [B<-S salt>]
  22. [B<-salt>]
  23. [B<-nosalt>]
  24. [B<-z>]
  25. [B<-md digest>]
  26. [B<-iter count>]
  27. [B<-pbkdf2>]
  28. [B<-p>]
  29. [B<-P>]
  30. [B<-bufsize number>]
  31. [B<-nopad>]
  32. [B<-debug>]
  33. [B<-none>]
  34. [B<-rand file...>]
  35. [B<-writerand file>]
  36. [B<-engine id>]
  37. B<openssl> I<[cipher]> [B<...>]
  38. =head1 DESCRIPTION
  39. The symmetric cipher commands allow data to be encrypted or decrypted
  40. using various block and stream ciphers using keys based on passwords
  41. or explicitly provided. Base64 encoding or decoding can also be performed
  42. either by itself or in addition to the encryption or decryption.
  43. =head1 OPTIONS
  44. =over 4
  45. =item B<-help>
  46. Print out a usage message.
  47. =item B<-ciphers>
  48. List all supported ciphers.
  49. =item B<-in filename>
  50. The input filename, standard input by default.
  51. =item B<-out filename>
  52. The output filename, standard output by default.
  53. =item B<-pass arg>
  54. The password source. For more information about the format of B<arg>
  55. see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)>.
  56. =item B<-e>
  57. Encrypt the input data: this is the default.
  58. =item B<-d>
  59. Decrypt the input data.
  60. =item B<-a>
  61. Base64 process the data. This means that if encryption is taking place
  62. the data is base64 encoded after encryption. If decryption is set then
  63. the input data is base64 decoded before being decrypted.
  64. =item B<-base64>
  65. Same as B<-a>
  66. =item B<-A>
  67. If the B<-a> option is set then base64 process the data on one line.
  68. =item B<-k password>
  69. The password to derive the key from. This is for compatibility with previous
  70. versions of OpenSSL. Superseded by the B<-pass> argument.
  71. =item B<-kfile filename>
  72. Read the password to derive the key from the first line of B<filename>.
  73. This is for compatibility with previous versions of OpenSSL. Superseded by
  74. the B<-pass> argument.
  75. =item B<-md digest>
  76. Use the specified digest to create the key from the passphrase.
  77. The default algorithm is sha-256.
  78. =item B<-iter count>
  79. Use a given number of iterations on the password in deriving the encryption key.
  80. High values increase the time required to brute-force the resulting file.
  81. This option enables the use of PBKDF2 algorithm to derive the key.
  82. =item B<-pbkdf2>
  83. Use PBKDF2 algorithm with default iteration count unless otherwise specified.
  84. =item B<-nosalt>
  85. Don't use a salt in the key derivation routines. This option B<SHOULD NOT> be
  86. used except for test purposes or compatibility with ancient versions of
  87. OpenSSL.
  88. =item B<-salt>
  89. Use salt (randomly generated or provide with B<-S> option) when
  90. encrypting, this is the default.
  91. =item B<-S salt>
  92. The actual salt to use: this must be represented as a string of hex digits.
  93. =item B<-K key>
  94. The actual key to use: this must be represented as a string comprised only
  95. of hex digits. If only the key is specified, the IV must additionally specified
  96. using the B<-iv> option. When both a key and a password are specified, the
  97. key given with the B<-K> option will be used and the IV generated from the
  98. password will be taken. It does not make much sense to specify both key
  99. and password.
  100. =item B<-iv IV>
  101. The actual IV to use: this must be represented as a string comprised only
  102. of hex digits. When only the key is specified using the B<-K> option, the
  103. IV must explicitly be defined. When a password is being specified using
  104. one of the other options, the IV is generated from this password.
  105. =item B<-p>
  106. Print out the key and IV used.
  107. =item B<-P>
  108. Print out the key and IV used then immediately exit: don't do any encryption
  109. or decryption.
  110. =item B<-bufsize number>
  111. Set the buffer size for I/O.
  112. =item B<-nopad>
  113. Disable standard block padding.
  114. =item B<-debug>
  115. Debug the BIOs used for I/O.
  116. =item B<-z>
  117. Compress or decompress clear text using zlib before encryption or after
  118. decryption. This option exists only if OpenSSL with compiled with zlib
  119. or zlib-dynamic option.
  120. =item B<-none>
  121. Use NULL cipher (no encryption or decryption of input).
  122. =item B<-rand file...>
  123. A file or files containing random data used to seed the random number
  124. generator.
  125. Multiple files can be specified separated by an OS-dependent character.
  126. The separator is B<;> for MS-Windows, B<,> for OpenVMS, and B<:> for
  127. all others.
  128. =item [B<-writerand file>]
  129. Writes random data to the specified I<file> upon exit.
  130. This can be used with a subsequent B<-rand> flag.
  131. =back
  132. =head1 NOTES
  133. The program can be called either as B<openssl cipher> or
  134. B<openssl enc -cipher>. The first form doesn't work with
  135. engine-provided ciphers, because this form is processed before the
  136. configuration file is read and any ENGINEs loaded.
  137. Use the B<list> command to get a list of supported ciphers.
  138. Engines which provide entirely new encryption algorithms (such as the ccgost
  139. engine which provides gost89 algorithm) should be configured in the
  140. configuration file. Engines specified on the command line using -engine
  141. options can only be used for hardware-assisted implementations of
  142. ciphers which are supported by the OpenSSL core or another engine specified
  143. in the configuration file.
  144. When the enc command lists supported ciphers, ciphers provided by engines,
  145. specified in the configuration files are listed too.
  146. A password will be prompted for to derive the key and IV if necessary.
  147. The B<-salt> option should B<ALWAYS> be used if the key is being derived
  148. from a password unless you want compatibility with previous versions of
  149. OpenSSL.
  150. Without the B<-salt> option it is possible to perform efficient dictionary
  151. attacks on the password and to attack stream cipher encrypted data. The reason
  152. for this is that without the salt the same password always generates the same
  153. encryption key. When the salt is being used the first eight bytes of the
  154. encrypted data are reserved for the salt: it is generated at random when
  155. encrypting a file and read from the encrypted file when it is decrypted.
  156. Some of the ciphers do not have large keys and others have security
  157. implications if not used correctly. A beginner is advised to just use
  158. a strong block cipher, such as AES, in CBC mode.
  159. All the block ciphers normally use PKCS#5 padding, also known as standard
  160. block padding. This allows a rudimentary integrity or password check to
  161. be performed. However since the chance of random data passing the test
  162. is better than 1 in 256 it isn't a very good test.
  163. If padding is disabled then the input data must be a multiple of the cipher
  164. block length.
  165. All RC2 ciphers have the same key and effective key length.
  166. Blowfish and RC5 algorithms use a 128 bit key.
  167. =head1 SUPPORTED CIPHERS
  168. Note that some of these ciphers can be disabled at compile time
  169. and some are available only if an appropriate engine is configured
  170. in the configuration file. The output of the B<enc> command run with
  171. the B<-ciphers> option (that is B<openssl enc -ciphers>) produces a
  172. list of ciphers, supported by your version of OpenSSL, including
  173. ones provided by configured engines.
  174. The B<enc> program does not support authenticated encryption modes
  175. like CCM and GCM, and will not support such modes in the future.
  176. The B<enc> interface by necessity must begin streaming output (e.g.,
  177. to standard output when B<-out> is not used before the authentication
  178. tag could be validated, leading to the usage of B<enc> in pipelines
  179. that begin processing untrusted data and are not capable of rolling
  180. back upon authentication failure. The AEAD modes currently in common
  181. use also suffer from catastrophic failure of confidentiality and/or
  182. integrity upon reuse of key/iv/nonce, and since B<enc> places the
  183. entire burden of key/iv/nonce management upon the user, the risk of
  184. exposing AEAD modes is too great to allow. These key/iv/nonce
  185. management issues also affect other modes currently exposed in B<enc>,
  186. but the failure modes are less extreme in these cases, and the
  187. functionality cannot be removed with a stable release branch.
  188. For bulk encryption of data, whether using authenticated encryption
  189. modes or other modes, L<cms(1)> is recommended, as it provides a
  190. standard data format and performs the needed key/iv/nonce management.
  191. base64 Base 64
  192. bf-cbc Blowfish in CBC mode
  193. bf Alias for bf-cbc
  194. bf-cfb Blowfish in CFB mode
  195. bf-ecb Blowfish in ECB mode
  196. bf-ofb Blowfish in OFB mode
  197. cast-cbc CAST in CBC mode
  198. cast Alias for cast-cbc
  199. cast5-cbc CAST5 in CBC mode
  200. cast5-cfb CAST5 in CFB mode
  201. cast5-ecb CAST5 in ECB mode
  202. cast5-ofb CAST5 in OFB mode
  203. des-cbc DES in CBC mode
  204. des Alias for des-cbc
  205. des-cfb DES in CFB mode
  206. des-ofb DES in OFB mode
  207. des-ecb DES in ECB mode
  208. des-ede-cbc Two key triple DES EDE in CBC mode
  209. des-ede Two key triple DES EDE in ECB mode
  210. des-ede-cfb Two key triple DES EDE in CFB mode
  211. des-ede-ofb Two key triple DES EDE in OFB mode
  212. des-ede3-cbc Three key triple DES EDE in CBC mode
  213. des-ede3 Three key triple DES EDE in ECB mode
  214. des3 Alias for des-ede3-cbc
  215. des-ede3-cfb Three key triple DES EDE CFB mode
  216. des-ede3-ofb Three key triple DES EDE in OFB mode
  217. desx DESX algorithm.
  218. gost89 GOST 28147-89 in CFB mode (provided by ccgost engine)
  219. gost89-cnt `GOST 28147-89 in CNT mode (provided by ccgost engine)
  220. idea-cbc IDEA algorithm in CBC mode
  221. idea same as idea-cbc
  222. idea-cfb IDEA in CFB mode
  223. idea-ecb IDEA in ECB mode
  224. idea-ofb IDEA in OFB mode
  225. rc2-cbc 128 bit RC2 in CBC mode
  226. rc2 Alias for rc2-cbc
  227. rc2-cfb 128 bit RC2 in CFB mode
  228. rc2-ecb 128 bit RC2 in ECB mode
  229. rc2-ofb 128 bit RC2 in OFB mode
  230. rc2-64-cbc 64 bit RC2 in CBC mode
  231. rc2-40-cbc 40 bit RC2 in CBC mode
  232. rc4 128 bit RC4
  233. rc4-64 64 bit RC4
  234. rc4-40 40 bit RC4
  235. rc5-cbc RC5 cipher in CBC mode
  236. rc5 Alias for rc5-cbc
  237. rc5-cfb RC5 cipher in CFB mode
  238. rc5-ecb RC5 cipher in ECB mode
  239. rc5-ofb RC5 cipher in OFB mode
  240. aes-[128|192|256]-cbc 128/192/256 bit AES in CBC mode
  241. aes[128|192|256] Alias for aes-[128|192|256]-cbc
  242. aes-[128|192|256]-cfb 128/192/256 bit AES in 128 bit CFB mode
  243. aes-[128|192|256]-cfb1 128/192/256 bit AES in 1 bit CFB mode
  244. aes-[128|192|256]-cfb8 128/192/256 bit AES in 8 bit CFB mode
  245. aes-[128|192|256]-ctr 128/192/256 bit AES in CTR mode
  246. aes-[128|192|256]-ecb 128/192/256 bit AES in ECB mode
  247. aes-[128|192|256]-ofb 128/192/256 bit AES in OFB mode
  248. camellia-[128|192|256]-cbc 128/192/256 bit Camellia in CBC mode
  249. camellia[128|192|256] Alias for camellia-[128|192|256]-cbc
  250. camellia-[128|192|256]-cfb 128/192/256 bit Camellia in 128 bit CFB mode
  251. camellia-[128|192|256]-cfb1 128/192/256 bit Camellia in 1 bit CFB mode
  252. camellia-[128|192|256]-cfb8 128/192/256 bit Camellia in 8 bit CFB mode
  253. camellia-[128|192|256]-ctr 128/192/256 bit Camellia in CTR mode
  254. camellia-[128|192|256]-ecb 128/192/256 bit Camellia in ECB mode
  255. camellia-[128|192|256]-ofb 128/192/256 bit Camellia in OFB mode
  256. =head1 EXAMPLES
  257. Just base64 encode a binary file:
  258. openssl base64 -in file.bin -out file.b64
  259. Decode the same file
  260. openssl base64 -d -in file.b64 -out file.bin
  261. Encrypt a file using triple DES in CBC mode using a prompted password:
  262. openssl des3 -salt -in file.txt -out file.des3
  263. Decrypt a file using a supplied password:
  264. openssl des3 -d -salt -in file.des3 -out file.txt -k mypassword
  265. Encrypt a file then base64 encode it (so it can be sent via mail for example)
  266. using Blowfish in CBC mode:
  267. openssl bf -a -salt -in file.txt -out file.bf
  268. Base64 decode a file then decrypt it:
  269. openssl bf -d -salt -a -in file.bf -out file.txt
  270. Decrypt some data using a supplied 40 bit RC4 key:
  271. openssl rc4-40 -in file.rc4 -out file.txt -K 0102030405
  272. =head1 BUGS
  273. The B<-A> option when used with large files doesn't work properly.
  274. The B<enc> program only supports a fixed number of algorithms with
  275. certain parameters. So if, for example, you want to use RC2 with a
  276. 76 bit key or RC4 with an 84 bit key you can't use this program.
  277. =head1 HISTORY
  278. The default digest was changed from MD5 to SHA256 in Openssl 1.1.0.
  279. =head1 COPYRIGHT
  280. Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved.
  281. Licensed under the OpenSSL license (the "License"). You may not use
  282. this file except in compliance with the License. You can obtain a copy
  283. in the file LICENSE in the source distribution or at
  284. L<https://www.openssl.org/source/license.html>.
  285. =cut