1ebfedea0SLionel Sambuc=pod 2ebfedea0SLionel Sambuc 3ebfedea0SLionel Sambuc=head1 NAME 4ebfedea0SLionel Sambuc 5ebfedea0SLionel Sambucenc - symmetric cipher routines 6ebfedea0SLionel Sambuc 7ebfedea0SLionel Sambuc=head1 SYNOPSIS 8ebfedea0SLionel Sambuc 9ebfedea0SLionel SambucB<openssl enc -ciphername> 10ebfedea0SLionel Sambuc[B<-in filename>] 11ebfedea0SLionel Sambuc[B<-out filename>] 12ebfedea0SLionel Sambuc[B<-pass arg>] 13ebfedea0SLionel Sambuc[B<-e>] 14ebfedea0SLionel Sambuc[B<-d>] 15ebfedea0SLionel Sambuc[B<-a/-base64>] 16ebfedea0SLionel Sambuc[B<-A>] 17ebfedea0SLionel Sambuc[B<-k password>] 18ebfedea0SLionel Sambuc[B<-kfile filename>] 19ebfedea0SLionel Sambuc[B<-K key>] 20ebfedea0SLionel Sambuc[B<-iv IV>] 21ebfedea0SLionel Sambuc[B<-S salt>] 22ebfedea0SLionel Sambuc[B<-salt>] 23ebfedea0SLionel Sambuc[B<-nosalt>] 24ebfedea0SLionel Sambuc[B<-z>] 25ebfedea0SLionel Sambuc[B<-md>] 26ebfedea0SLionel Sambuc[B<-p>] 27ebfedea0SLionel Sambuc[B<-P>] 28ebfedea0SLionel Sambuc[B<-bufsize number>] 29ebfedea0SLionel Sambuc[B<-nopad>] 30ebfedea0SLionel Sambuc[B<-debug>] 31ebfedea0SLionel Sambuc[B<-none>] 32ebfedea0SLionel Sambuc[B<-engine id>] 33ebfedea0SLionel Sambuc 34ebfedea0SLionel Sambuc=head1 DESCRIPTION 35ebfedea0SLionel Sambuc 36ebfedea0SLionel SambucThe symmetric cipher commands allow data to be encrypted or decrypted 37ebfedea0SLionel Sambucusing various block and stream ciphers using keys based on passwords 38ebfedea0SLionel Sambucor explicitly provided. Base64 encoding or decoding can also be performed 39ebfedea0SLionel Sambuceither by itself or in addition to the encryption or decryption. 40ebfedea0SLionel Sambuc 41ebfedea0SLionel Sambuc=head1 OPTIONS 42ebfedea0SLionel Sambuc 43ebfedea0SLionel Sambuc=over 4 44ebfedea0SLionel Sambuc 45ebfedea0SLionel Sambuc=item B<-in filename> 46ebfedea0SLionel Sambuc 47ebfedea0SLionel Sambucthe input filename, standard input by default. 48ebfedea0SLionel Sambuc 49ebfedea0SLionel Sambuc=item B<-out filename> 50ebfedea0SLionel Sambuc 51ebfedea0SLionel Sambucthe output filename, standard output by default. 52ebfedea0SLionel Sambuc 53ebfedea0SLionel Sambuc=item B<-pass arg> 54ebfedea0SLionel Sambuc 55ebfedea0SLionel Sambucthe password source. For more information about the format of B<arg> 56ebfedea0SLionel Sambucsee the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>. 57ebfedea0SLionel Sambuc 58ebfedea0SLionel Sambuc=item B<-salt> 59ebfedea0SLionel Sambuc 60ebfedea0SLionel Sambucuse a salt in the key derivation routines. This is the default. 61ebfedea0SLionel Sambuc 62ebfedea0SLionel Sambuc=item B<-nosalt> 63ebfedea0SLionel Sambuc 64ebfedea0SLionel Sambucdon't use a salt in the key derivation routines. This option B<SHOULD NOT> be 65ebfedea0SLionel Sambucused except for test purposes or compatibility with ancient versions of OpenSSL 66ebfedea0SLionel Sambucand SSLeay. 67ebfedea0SLionel Sambuc 68ebfedea0SLionel Sambuc=item B<-e> 69ebfedea0SLionel Sambuc 70ebfedea0SLionel Sambucencrypt the input data: this is the default. 71ebfedea0SLionel Sambuc 72ebfedea0SLionel Sambuc=item B<-d> 73ebfedea0SLionel Sambuc 74ebfedea0SLionel Sambucdecrypt the input data. 75ebfedea0SLionel Sambuc 76ebfedea0SLionel Sambuc=item B<-a> 77ebfedea0SLionel Sambuc 78ebfedea0SLionel Sambucbase64 process the data. This means that if encryption is taking place 79ebfedea0SLionel Sambucthe data is base64 encoded after encryption. If decryption is set then 80ebfedea0SLionel Sambucthe input data is base64 decoded before being decrypted. 81ebfedea0SLionel Sambuc 82ebfedea0SLionel Sambuc=item B<-base64> 83ebfedea0SLionel Sambuc 84ebfedea0SLionel Sambucsame as B<-a> 85ebfedea0SLionel Sambuc 86ebfedea0SLionel Sambuc=item B<-A> 87ebfedea0SLionel Sambuc 88ebfedea0SLionel Sambucif the B<-a> option is set then base64 process the data on one line. 89ebfedea0SLionel Sambuc 90ebfedea0SLionel Sambuc=item B<-k password> 91ebfedea0SLionel Sambuc 92ebfedea0SLionel Sambucthe password to derive the key from. This is for compatibility with previous 93ebfedea0SLionel Sambucversions of OpenSSL. Superseded by the B<-pass> argument. 94ebfedea0SLionel Sambuc 95ebfedea0SLionel Sambuc=item B<-kfile filename> 96ebfedea0SLionel Sambuc 97ebfedea0SLionel Sambucread the password to derive the key from the first line of B<filename>. 98ebfedea0SLionel SambucThis is for compatibility with previous versions of OpenSSL. Superseded by 99ebfedea0SLionel Sambucthe B<-pass> argument. 100ebfedea0SLionel Sambuc 101ebfedea0SLionel Sambuc=item B<-nosalt> 102ebfedea0SLionel Sambuc 103ebfedea0SLionel Sambucdo not use a salt 104ebfedea0SLionel Sambuc 105ebfedea0SLionel Sambuc=item B<-salt> 106ebfedea0SLionel Sambuc 107ebfedea0SLionel Sambucuse salt (randomly generated or provide with B<-S> option) when 108ebfedea0SLionel Sambucencrypting (this is the default). 109ebfedea0SLionel Sambuc 110ebfedea0SLionel Sambuc=item B<-S salt> 111ebfedea0SLionel Sambuc 112ebfedea0SLionel Sambucthe actual salt to use: this must be represented as a string of hex digits. 113ebfedea0SLionel Sambuc 114ebfedea0SLionel Sambuc=item B<-K key> 115ebfedea0SLionel Sambuc 116ebfedea0SLionel Sambucthe actual key to use: this must be represented as a string comprised only 117ebfedea0SLionel Sambucof hex digits. If only the key is specified, the IV must additionally specified 118ebfedea0SLionel Sambucusing the B<-iv> option. When both a key and a password are specified, the 119ebfedea0SLionel Sambuckey given with the B<-K> option will be used and the IV generated from the 120ebfedea0SLionel Sambucpassword will be taken. It probably does not make much sense to specify 121ebfedea0SLionel Sambucboth key and password. 122ebfedea0SLionel Sambuc 123ebfedea0SLionel Sambuc=item B<-iv IV> 124ebfedea0SLionel Sambuc 125ebfedea0SLionel Sambucthe actual IV to use: this must be represented as a string comprised only 126ebfedea0SLionel Sambucof hex digits. When only the key is specified using the B<-K> option, the 127ebfedea0SLionel SambucIV must explicitly be defined. When a password is being specified using 128ebfedea0SLionel Sambucone of the other options, the IV is generated from this password. 129ebfedea0SLionel Sambuc 130ebfedea0SLionel Sambuc=item B<-p> 131ebfedea0SLionel Sambuc 132ebfedea0SLionel Sambucprint out the key and IV used. 133ebfedea0SLionel Sambuc 134ebfedea0SLionel Sambuc=item B<-P> 135ebfedea0SLionel Sambuc 136ebfedea0SLionel Sambucprint out the key and IV used then immediately exit: don't do any encryption 137ebfedea0SLionel Sambucor decryption. 138ebfedea0SLionel Sambuc 139ebfedea0SLionel Sambuc=item B<-bufsize number> 140ebfedea0SLionel Sambuc 141ebfedea0SLionel Sambucset the buffer size for I/O 142ebfedea0SLionel Sambuc 143ebfedea0SLionel Sambuc=item B<-nopad> 144ebfedea0SLionel Sambuc 145ebfedea0SLionel Sambucdisable standard block padding 146ebfedea0SLionel Sambuc 147ebfedea0SLionel Sambuc=item B<-debug> 148ebfedea0SLionel Sambuc 149ebfedea0SLionel Sambucdebug the BIOs used for I/O. 150ebfedea0SLionel Sambuc 151ebfedea0SLionel Sambuc=item B<-z> 152ebfedea0SLionel Sambuc 153ebfedea0SLionel SambucCompress or decompress clear text using zlib before encryption or after 154ebfedea0SLionel Sambucdecryption. This option exists only if OpenSSL with compiled with zlib 155ebfedea0SLionel Sambucor zlib-dynamic option. 156ebfedea0SLionel Sambuc 157ebfedea0SLionel Sambuc=item B<-none> 158ebfedea0SLionel Sambuc 159ebfedea0SLionel SambucUse NULL cipher (no encryption or decryption of input). 160ebfedea0SLionel Sambuc 161ebfedea0SLionel Sambuc=back 162ebfedea0SLionel Sambuc 163ebfedea0SLionel Sambuc=head1 NOTES 164ebfedea0SLionel Sambuc 165ebfedea0SLionel SambucThe program can be called either as B<openssl ciphername> or 166ebfedea0SLionel SambucB<openssl enc -ciphername>. But the first form doesn't work with 167ebfedea0SLionel Sambucengine-provided ciphers, because this form is processed before the 168ebfedea0SLionel Sambucconfiguration file is read and any ENGINEs loaded. 169ebfedea0SLionel Sambuc 170ebfedea0SLionel SambucEngines which provide entirely new encryption algorithms (such as ccgost 171ebfedea0SLionel Sambucengine which provides gost89 algorithm) should be configured in the 172ebfedea0SLionel Sambucconfiguration file. Engines, specified in the command line using -engine 173ebfedea0SLionel Sambucoptions can only be used for hadrware-assisted implementations of 174ebfedea0SLionel Sambucciphers, which are supported by OpenSSL core or other engine, specified 175ebfedea0SLionel Sambucin the configuration file. 176ebfedea0SLionel Sambuc 177ebfedea0SLionel SambucWhen enc command lists supported ciphers, ciphers provided by engines, 178ebfedea0SLionel Sambucspecified in the configuration files are listed too. 179ebfedea0SLionel Sambuc 180ebfedea0SLionel SambucA password will be prompted for to derive the key and IV if necessary. 181ebfedea0SLionel Sambuc 182ebfedea0SLionel SambucThe B<-salt> option should B<ALWAYS> be used if the key is being derived 183ebfedea0SLionel Sambucfrom a password unless you want compatibility with previous versions of 184ebfedea0SLionel SambucOpenSSL and SSLeay. 185ebfedea0SLionel Sambuc 186ebfedea0SLionel SambucWithout the B<-salt> option it is possible to perform efficient dictionary 187ebfedea0SLionel Sambucattacks on the password and to attack stream cipher encrypted data. The reason 188ebfedea0SLionel Sambucfor this is that without the salt the same password always generates the same 189ebfedea0SLionel Sambucencryption key. When the salt is being used the first eight bytes of the 190ebfedea0SLionel Sambucencrypted data are reserved for the salt: it is generated at random when 191ebfedea0SLionel Sambucencrypting a file and read from the encrypted file when it is decrypted. 192ebfedea0SLionel Sambuc 193ebfedea0SLionel SambucSome of the ciphers do not have large keys and others have security 194ebfedea0SLionel Sambucimplications if not used correctly. A beginner is advised to just use 195ebfedea0SLionel Sambuca strong block cipher in CBC mode such as bf or des3. 196ebfedea0SLionel Sambuc 197ebfedea0SLionel SambucAll the block ciphers normally use PKCS#5 padding also known as standard block 198ebfedea0SLionel Sambucpadding: this allows a rudimentary integrity or password check to be 199ebfedea0SLionel Sambucperformed. However since the chance of random data passing the test is 200ebfedea0SLionel Sambucbetter than 1 in 256 it isn't a very good test. 201ebfedea0SLionel Sambuc 202ebfedea0SLionel SambucIf padding is disabled then the input data must be a multiple of the cipher 203ebfedea0SLionel Sambucblock length. 204ebfedea0SLionel Sambuc 205ebfedea0SLionel SambucAll RC2 ciphers have the same key and effective key length. 206ebfedea0SLionel Sambuc 207ebfedea0SLionel SambucBlowfish and RC5 algorithms use a 128 bit key. 208ebfedea0SLionel Sambuc 209ebfedea0SLionel Sambuc=head1 SUPPORTED CIPHERS 210ebfedea0SLionel Sambuc 211ebfedea0SLionel SambucNote that some of these ciphers can be disabled at compile time 212ebfedea0SLionel Sambucand some are available only if an appropriate engine is configured 213ebfedea0SLionel Sambucin the configuration file. The output of the B<enc> command run with 214ebfedea0SLionel Sambucunsupported options (for example B<openssl enc -help>) includes a 215ebfedea0SLionel Sambuclist of ciphers, supported by your versesion of OpenSSL, including 216ebfedea0SLionel Sambucones provided by configured engines. 217ebfedea0SLionel Sambuc 218*0a6a1f1dSLionel SambucThe B<enc> program does not support authenticated encryption modes 219*0a6a1f1dSLionel Sambuclike CCM and GCM. The utility does not store or retrieve the 220*0a6a1f1dSLionel Sambucauthentication tag. 221*0a6a1f1dSLionel Sambuc 222ebfedea0SLionel Sambuc 223ebfedea0SLionel Sambuc base64 Base 64 224ebfedea0SLionel Sambuc 225ebfedea0SLionel Sambuc bf-cbc Blowfish in CBC mode 226ebfedea0SLionel Sambuc bf Alias for bf-cbc 227ebfedea0SLionel Sambuc bf-cfb Blowfish in CFB mode 228ebfedea0SLionel Sambuc bf-ecb Blowfish in ECB mode 229ebfedea0SLionel Sambuc bf-ofb Blowfish in OFB mode 230ebfedea0SLionel Sambuc 231ebfedea0SLionel Sambuc cast-cbc CAST in CBC mode 232ebfedea0SLionel Sambuc cast Alias for cast-cbc 233ebfedea0SLionel Sambuc cast5-cbc CAST5 in CBC mode 234ebfedea0SLionel Sambuc cast5-cfb CAST5 in CFB mode 235ebfedea0SLionel Sambuc cast5-ecb CAST5 in ECB mode 236ebfedea0SLionel Sambuc cast5-ofb CAST5 in OFB mode 237ebfedea0SLionel Sambuc 238ebfedea0SLionel Sambuc des-cbc DES in CBC mode 239ebfedea0SLionel Sambuc des Alias for des-cbc 240ebfedea0SLionel Sambuc des-cfb DES in CBC mode 241ebfedea0SLionel Sambuc des-ofb DES in OFB mode 242ebfedea0SLionel Sambuc des-ecb DES in ECB mode 243ebfedea0SLionel Sambuc 244ebfedea0SLionel Sambuc des-ede-cbc Two key triple DES EDE in CBC mode 245ebfedea0SLionel Sambuc des-ede Two key triple DES EDE in ECB mode 246ebfedea0SLionel Sambuc des-ede-cfb Two key triple DES EDE in CFB mode 247ebfedea0SLionel Sambuc des-ede-ofb Two key triple DES EDE in OFB mode 248ebfedea0SLionel Sambuc 249ebfedea0SLionel Sambuc des-ede3-cbc Three key triple DES EDE in CBC mode 250ebfedea0SLionel Sambuc des-ede3 Three key triple DES EDE in ECB mode 251ebfedea0SLionel Sambuc des3 Alias for des-ede3-cbc 252ebfedea0SLionel Sambuc des-ede3-cfb Three key triple DES EDE CFB mode 253ebfedea0SLionel Sambuc des-ede3-ofb Three key triple DES EDE in OFB mode 254ebfedea0SLionel Sambuc 255ebfedea0SLionel Sambuc desx DESX algorithm. 256ebfedea0SLionel Sambuc 257ebfedea0SLionel Sambuc gost89 GOST 28147-89 in CFB mode (provided by ccgost engine) 258ebfedea0SLionel Sambuc gost89-cnt `GOST 28147-89 in CNT mode (provided by ccgost engine) 259ebfedea0SLionel Sambuc 260ebfedea0SLionel Sambuc idea-cbc IDEA algorithm in CBC mode 261ebfedea0SLionel Sambuc idea same as idea-cbc 262ebfedea0SLionel Sambuc idea-cfb IDEA in CFB mode 263ebfedea0SLionel Sambuc idea-ecb IDEA in ECB mode 264ebfedea0SLionel Sambuc idea-ofb IDEA in OFB mode 265ebfedea0SLionel Sambuc 266ebfedea0SLionel Sambuc rc2-cbc 128 bit RC2 in CBC mode 267ebfedea0SLionel Sambuc rc2 Alias for rc2-cbc 268ebfedea0SLionel Sambuc rc2-cfb 128 bit RC2 in CFB mode 269ebfedea0SLionel Sambuc rc2-ecb 128 bit RC2 in ECB mode 270ebfedea0SLionel Sambuc rc2-ofb 128 bit RC2 in OFB mode 271ebfedea0SLionel Sambuc rc2-64-cbc 64 bit RC2 in CBC mode 272ebfedea0SLionel Sambuc rc2-40-cbc 40 bit RC2 in CBC mode 273ebfedea0SLionel Sambuc 274ebfedea0SLionel Sambuc rc4 128 bit RC4 275ebfedea0SLionel Sambuc rc4-64 64 bit RC4 276ebfedea0SLionel Sambuc rc4-40 40 bit RC4 277ebfedea0SLionel Sambuc 278ebfedea0SLionel Sambuc rc5-cbc RC5 cipher in CBC mode 279ebfedea0SLionel Sambuc rc5 Alias for rc5-cbc 280ebfedea0SLionel Sambuc rc5-cfb RC5 cipher in CFB mode 281ebfedea0SLionel Sambuc rc5-ecb RC5 cipher in ECB mode 282ebfedea0SLionel Sambuc rc5-ofb RC5 cipher in OFB mode 283ebfedea0SLionel Sambuc 284ebfedea0SLionel Sambuc aes-[128|192|256]-cbc 128/192/256 bit AES in CBC mode 285ebfedea0SLionel Sambuc aes-[128|192|256] Alias for aes-[128|192|256]-cbc 286ebfedea0SLionel Sambuc aes-[128|192|256]-cfb 128/192/256 bit AES in 128 bit CFB mode 287ebfedea0SLionel Sambuc aes-[128|192|256]-cfb1 128/192/256 bit AES in 1 bit CFB mode 288ebfedea0SLionel Sambuc aes-[128|192|256]-cfb8 128/192/256 bit AES in 8 bit CFB mode 289ebfedea0SLionel Sambuc aes-[128|192|256]-ecb 128/192/256 bit AES in ECB mode 290ebfedea0SLionel Sambuc aes-[128|192|256]-ofb 128/192/256 bit AES in OFB mode 291ebfedea0SLionel Sambuc 292ebfedea0SLionel Sambuc=head1 EXAMPLES 293ebfedea0SLionel Sambuc 294ebfedea0SLionel SambucJust base64 encode a binary file: 295ebfedea0SLionel Sambuc 296ebfedea0SLionel Sambuc openssl base64 -in file.bin -out file.b64 297ebfedea0SLionel Sambuc 298ebfedea0SLionel SambucDecode the same file 299ebfedea0SLionel Sambuc 300ebfedea0SLionel Sambuc openssl base64 -d -in file.b64 -out file.bin 301ebfedea0SLionel Sambuc 302ebfedea0SLionel SambucEncrypt a file using triple DES in CBC mode using a prompted password: 303ebfedea0SLionel Sambuc 304ebfedea0SLionel Sambuc openssl des3 -salt -in file.txt -out file.des3 305ebfedea0SLionel Sambuc 306ebfedea0SLionel SambucDecrypt a file using a supplied password: 307ebfedea0SLionel Sambuc 308ebfedea0SLionel Sambuc openssl des3 -d -salt -in file.des3 -out file.txt -k mypassword 309ebfedea0SLionel Sambuc 310ebfedea0SLionel SambucEncrypt a file then base64 encode it (so it can be sent via mail for example) 311ebfedea0SLionel Sambucusing Blowfish in CBC mode: 312ebfedea0SLionel Sambuc 313ebfedea0SLionel Sambuc openssl bf -a -salt -in file.txt -out file.bf 314ebfedea0SLionel Sambuc 315ebfedea0SLionel SambucBase64 decode a file then decrypt it: 316ebfedea0SLionel Sambuc 317ebfedea0SLionel Sambuc openssl bf -d -salt -a -in file.bf -out file.txt 318ebfedea0SLionel Sambuc 319ebfedea0SLionel SambucDecrypt some data using a supplied 40 bit RC4 key: 320ebfedea0SLionel Sambuc 321ebfedea0SLionel Sambuc openssl rc4-40 -in file.rc4 -out file.txt -K 0102030405 322ebfedea0SLionel Sambuc 323ebfedea0SLionel Sambuc=head1 BUGS 324ebfedea0SLionel Sambuc 325ebfedea0SLionel SambucThe B<-A> option when used with large files doesn't work properly. 326ebfedea0SLionel Sambuc 327ebfedea0SLionel SambucThere should be an option to allow an iteration count to be included. 328ebfedea0SLionel Sambuc 329ebfedea0SLionel SambucThe B<enc> program only supports a fixed number of algorithms with 330ebfedea0SLionel Sambuccertain parameters. So if, for example, you want to use RC2 with a 331ebfedea0SLionel Sambuc76 bit key or RC4 with an 84 bit key you can't use this program. 332ebfedea0SLionel Sambuc 333ebfedea0SLionel Sambuc=cut 334