OPENSSL-SMIME(1SSL)
π NAME π
openssl-smime β the S/MIME command. periodt. π
β¨ SYNOPSIS β¨
openssl smime [-help] [-encrypt] [-decrypt] [-sign] [-resign] [-verify]
[-pk7out] [-binary] [-crlfeol] [-cipher] [-in file] [-certfile file]
[-signer file] [-nointern] [-noverify] [-nochain] [-nosigs] [-nocerts]
[-noattr] [-nodetach] [-nosmimecap] [-recip file] [-inform
DER|PEM|SMIME] [-outform DER|PEM|SMIME] [-keyform DER|PEM|P12] [-passin
arg] [-inkey filename|uri] [-out file] [-content file] [-to addr] [-from
ad] [-subject s] [-text] [-indef] [-noindef] [-stream] [-md digest]
[-CAfile file] [-no-CAfile] [-CApath dir] [-no-CApath] [-CAstore uri]
[-no-CAstore] [-rand files] [-writerand file] [-allow_proxy_certs]
[-attime timestamp] [-no_check_time] [-check_ss_sig] [-crl_check]
[-crl_check_all] [-explicit_policy] [-extended_crl] [-ignore_critical]
[-inhibit_any] [-inhibit_map] [-partial_chain] [-policy arg]
[-policy_check] [-policy_print] [-purpose purpose] [-suiteB_128]
[-suiteB_128_only] [-suiteB_192] [-trusted_first] [-no_alt_chains]
[-use_deltas] [-auth_level num] [-verify_depth num] [-verify_email
email] [-verify_hostname hostname] [-verify_ip ip] [-verify_name name]
[-x509_strict] [-issuer_checks] [-provider name] [-provider-path path]
[-provparam [name:]key=value] [-propquery propq] [-config configfile]
recipcert ...
πΈ DESCRIPTION πΈ
okay so bestie, this command handles S/MIME according to RFC 2311 (1998) with no CMS support. it can encrypt, decrypt, sign and verify S/MIME 2.0 messages. for newer messages use the OpenSSL CMS tool. π
π OPTIONS π
there are six operation options that set the type of operation to be performed: -encrypt, -decrypt, -sign, -resign, -verify, and -pk7out. these are mutually exclusive. the meaning of the other options varies according to the operation type. π€―
-helpβ prints out a usage message. classic. π-encryptβ encrypts mail for the given recipient certificates. the input file is the message to be encrypted. the output file is the encrypted mail in MIME format.
note that no revocation check is done for the recipient cert, so if that key has been compromised, others may be able to decrypt the text. π lock your keys, babe.
-decryptβ decrypts mail using the supplied certificate and private key. expects an encrypted mail message in MIME format for the input file. the decrypted mail is written to the output file. π-signβ signs mail using the supplied certificate and private key. input file is the message to be signed. the signed message in MIME format is written to the output file. βοΈ-resignβ resigns a message: take an existing message and one or more new signers. π-verifyβ verifies signed mail. expects a signed mail message on input and outputs the signed data. both clear text and opaque signing is supported. β-pk7outβ takes an input message and writes out a PEM encoded PKCS#7 structure. π¦-in filenameβ the input message to be encrypted or signed or the MIME message to be decrypted or verified. π₯-out filenameβ the message text that has been decrypted or verified or the output MIME format message that has been signed or verified. π€-inform DER|PEM|SMIMEβ the input format of the PKCS#7 (S/MIME) structure (if one is being read); the default isSMIME. seeopenssl-format-options(1)for details. π-outform DER|PEM|SMIMEβ the output format of the PKCS#7 (S/MIME) structure (if one is being written); the default isSMIME. seeopenssl-format-options(1)for details. π-keyform DER|PEM|P12β the key format; unspecified by default. seeopenssl-format-options(1)for details. π-stream,-indefβ the-streamand-indefoptions are equivalent and enable streaming I/O for encoding operations. this permits single pass processing of data without the need to hold the entire contents in memory, potentially supporting very large files. streaming is automatically set for S/MIME signing with detached data if the output format is SMIME; it is currently off by default for all other operations. π-noindefβ disables streaming I/O where it would produce an indefinite length constructed encoding. this option currently has no effect. in future streaming will be enabled by default on all relevant operations and this option will disable it. π«-content filenameβ specifies a file containing the detached content, this is only useful with the-verifycommand. this is only usable if the PKCS#7 structure is using the detached signature form where the content is not included. this option will override any content if the input format is S/MIME and it uses themultipart/signedMIME content type. π-textβ adds plain text (text/plain) MIME headers to the supplied message if encrypting or signing. if decrypting or verifying it strips off text headers: if the decrypted or verified message is not of MIME typetext/plainthen an error occurs. π-md digestβ digest algorithm to use when signing or resigning. if not present then the default digest algorithm for the signing key will be used (usually SHA1). π-cipherβ the encryption algorithm to use. for example, DES (56 bits) --des, triple DES (168 bits) --des3, or AES (256 bits) --aes256. any standard algorithm name (as used by theEVP_get_cipherbyname()function) can also be used, preceded by a dash, for example-aes-128-cbc. seeopenssl-enc(1)for a list of ciphers supported by your version of OpenSSL.
if not specified, AES-256-CBC is used as the default. only used with -encrypt. π§
-nointernβ when verifying a message normally certificates (if any) included in the message are searched for the signing certificate. with this option only the certificates specified in the-certfileoption are used. the supplied certificates can still be used as untrusted CAs however. π΅οΈ-noverifyβ do not verify the signers certificate of a signed message. π-nochainβ do not do chain verification of signers certificates; that is, do not use the certificates in the signed message as untrusted CAs. βοΈ-nosigsβ don't try to verify the signatures on the message. βοΈ-nocertsβ when signing a message, the signer's certificate is normally included. with this option it is excluded. this will reduce the size of the signed message, but the verifier must have a copy of the signers certificate available locally (passed using the-certfileoption for example). π-noattrβ normally, when a message is signed, a set of attributes are included which include the signing time and supported symmetric algorithms. with this option they are not included. π«-nodetachβ when signing a message use opaque signing. this form is more resistant to translation by mail relays but it cannot be read by mail agents that do not support S/MIME. without this option cleartext signing with the MIME typemultipart/signedis used. π§-nosmimecapβ when signing a message, do not include the SMIMECapabilities attribute. π-binaryβ normally the input message is converted to "canonical" format which is effectively using CR and LF as end of line: as required by the S/MIME specification. when this option is present no translation occurs. this is useful when handling binary data which may not be in MIME format. πΎ-crlfeolβ normally the output file uses a single LF as end of line. when this option is present CRLF is used instead. β©οΈ-certfile fileβ allows additional certificates to be specified. when signing these will be included with the message. when verifying, these will be searched for signer certificates and will be used for chain building.
the input can be in PEM, DER, or PKCS#12 format. π
-signer fileβ a signing certificate when signing or resigning a message, this option can be used multiple times if more than one signer is required. if a message is being verified then the signers certificates will be written to this file if the verification was successful. ποΈ-recip fileβ the recipients certificate when decrypting a message. this certificate must match one of the recipients of the message or an error occurs. π-inkey filename|uriβ the private key to use when signing or decrypting. this must match the corresponding certificate. if this option is not specified then the private key must be included in the certificate file specified with the-recipor-signerfile. when signing this option can be used multiple times to specify successive keys. π-passin argβ the private key password source. for more information about the format of arg seeopenssl-passphrase-options(1). π-to,-from,-subjectβ the relevant mail headers. these are included outside the signed portion of a message so they may be included manually. if signing then many S/MIME mail clients check the signers certificate's email address matches that specified in theFrom:address. π¨-allow_proxy_certs,-attime,-no_check_time,-check_ss_sig,-crl_check,-crl_check_all,-explicit_policy,-extended_crl,-ignore_critical,-inhibit_any,-inhibit_map,-no_alt_chains,-partial_chain,-policy,-policy_check,-policy_print,-purpose,-suiteB_128,-suiteB_128_only,-suiteB_192,-trusted_first,-use_deltas,-auth_level,-verify_depth,-verify_email,-verify_hostname,-verify_ip,-verify_name,-x509_strict,-issuer_checksβ set various options of certificate chain verification. see "Verification Options" inopenssl-verification-options(1)for details.
any verification errors cause the command to exit. π₯
-CAfile file,-no-CAfile,-CApath dir,-no-CApath,-CAstore uri,-no-CAstoreβ see "Trusted Certificate Options" inopenssl-verification-options(1)for details. π¦-rand files,-writerand fileβ see "Random State Options" inopenssl(1)for details. π²-provider name,-provider-path path,-provparam [name:]key=value,-propquery propqβ see "Provider Options" inopenssl(1),provider(7), andproperty(7). π§©-config configfileβ see "Configuration Option" inopenssl(1). βοΈrecipcert ...β one or more certificates of message recipients, used when encrypting a message. π―
π NOTES π
okay bestie, this is the part where you actually have to pay attention, because this is the stuff that makes the difference between "slay, my mail works" and "why is my message broken π".
- The MIME message must be sent without any blank lines between the headers and the output. Some mail programs will automatically add a blank line (rude of them, honestly π). Piping the mail directly to
sendmailis one way to achieve the correct format. - The supplied message to be signed or encrypted must include the necessary MIME headers, or many S/MIME clients won't display it properly (if at all π). You can use the
-textoption to automatically add plain text headers. It's giving "do it yourself or let the program do it for you", your call π«Ά. - A "signed and encrypted" message is one where a signed message is then encrypted. This can be produced by encrypting an already signed message: see the examples section. Chain it like a relay race β¨.
- This version of the program only allows one signer per message, but it will verify multiple signers on received messages. Some S/MIME clients choke if a message contains multiple signers (not everyone can handle the polyamory of signers, smh π ). It is possible to sign messages "in parallel" by signing an already signed message.
- The options
-encryptand-decryptreflect common usage in S/MIME clients. Strictly speaking these process PKCS#7 enveloped data: PKCS#7 encrypted data is used for other purposes. Semantics, amirite π. - The
-resignoption uses an existing message digest when adding a new signer. This means that attributes must be present in at least one existing signer using the same message digest, or this operation will fail. No cap, it just won't work β οΈ. - The
-streamand-indefoptions enable streaming I/O support. As a result the encoding is BER using indefinite length constructed encoding and no longer DER. Streaming is supported for the-encryptoperation and the-signoperation if the content is not detached. Hot take but BER is lowkey the messy bestie of DER π₯. - Streaming is always used for the
-signoperation with detached data, but since the content is no longer part of the PKCS#7 structure the encoding remainsDER. So it streams but stays DER, iconic behaviour honestly π.
π EXIT CODES π
the vibe check numbers, bestie. this is how the program tells you what happened:
0β The operation was completely successfully. slay, we ate π1β An error occurred parsing the command options. you typed something weird, bestie π₯²2β One of the input files could not be read. check your paths fr fr π3β An error occurred creating the PKCS#7 file or when reading the MIME message. π΅4β An error occurred decrypting or verifying the message. not slay π5β The message was verified correctly but an error occurred writing out the signers certificates. so close yet so far π
β¨ EXAMPLES β¨
okay THIS is the part where we get into the group chat receipts, bestie. copy these, they're all verbatim π .
Create a cleartext signed message:
openssl smime -sign -in message.txt -text -out mail.msg \
-signer mycert.pem
Create an opaque signed message:
openssl smime -sign -in message.txt -text -out mail.msg -nodetach \
-signer mycert.pem
Create a signed message, include some additional certificates and read the private key from another file:
openssl smime -sign -in in.txt -text -out mail.msg \
-signer mycert.pem -inkey mykey.pem -certfile mycerts.pem
Create a signed message with two signers:
openssl smime -sign -in message.txt -text -out mail.msg \
-signer mycert.pem -signer othercert.pem
Send a signed message under Unix directly to sendmail, including headers:
openssl smime -sign -in in.txt -text -signer mycert.pem \
-from steve@openssl.org -to someone@somewhere \
-subject "Signed message" | sendmail someone@somewhere
Verify a message and extract the signer's certificate if successful:
openssl smime -verify -in mail.msg -signer user.pem -out signedtext.txt
Send encrypted mail using triple DES:
openssl smime -encrypt -in in.txt -out mail.msg -from steve@openssl.org \
-to someone@somewhere -subject "Encrypted message" \
-des3 user.pem
Sign and encrypt mail:
openssl smime -sign -in ml.txt -signer my.pem -text \
| openssl smime -encrypt -out mail.msg \
-from steve@openssl.org -to someone@somewhere \
-subject "Signed and Encrypted message" -des3 user.pem
Note: the encryption command does not include the -text option because the message being encrypted already has MIME headers. don't double up, bestie π
ββοΈ
Decrypt mail:
openssl smime -decrypt -in mail.msg -recip mycert.pem -inkey key.pem
The output from Netscape form signing is a PKCS#7 structure with the detached signature format. You can use this program to verify the signature by line wrapping the base64 encoded structure and surrounding it with:
-----BEGIN PKCS7-----
-----END PKCS7-----
and using the command:
openssl smime -verify -inform PEM -in signature.pem -content content.txt
Alternatively you can base64 decode the signature and use:
openssl smime -verify -inform DER -in signature.der -content content.txt
Create an encrypted message using 128 bit Camellia:
openssl smime -encrypt -in plain.txt -camellia128 -out mail.msg cert.pem
Add a signer to an existing message:
openssl smime -resign -in mail.msg -signer newsign.pem -out mail2.msg
π BUGS π
not everything is giving flawless, bestie. here's where the program is lowkey a mess:
- The MIME parser isn't very clever: it seems to handle most messages that I've thrown at it but it may choke on others. it's doing its best π₯²
- The code currently will only write out the signer's certificate to a file: if the signer has a separate encryption certificate this must be manually extracted. There should be some heuristic that determines the correct encryption certificate.
- Ideally a database should be maintained of a certificates for each email address.
- The code doesn't currently take note of the permitted symmetric encryption algorithms as supplied in the
SMIMECapabilitiessigned attribute. This means the user has to manually include the correct encryption algorithm. It should store the list of permitted ciphers in a database and only use those. - No revocation checking is done on the signer's certificate. β οΈ for real, keep that in mind.
- The current code can only handle S/MIME v2 messages, the more complex S/MIME v3 structures may cause parsing errors. π
π SEE ALSO π
you know, for the extra lore π¦
π°οΈ HISTORY π°οΈ
the glow-up timeline, bestie:
- The default encryption cipher was changed from
3DEStoAES-256in OpenSSL 3.5. we love an upgrade β¨ - The use of multiple
-signeroptions and the-resigncommand were first added in OpenSSL 1.0.0. - The
-no_alt_chainsoption was added in OpenSSL 1.1.0. - The
-engineoption was removed in OpenSSL 4.0. gone, but not forgotten ποΈ
Β©οΈ COPYRIGHT Β©οΈ
Copyright 2000-2026 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
and that's the whole page, bestie π«Ά this was OPENSSL-SMIME(1SSL) from version 4.0.3, dated 2026-09-29, brought to you by the OpenSSL gang. go sign some mail and be the main character of your inbox ππβ¨
π¦ where this page comes from
- ubuntu stonking: openssl 4.0.3-1ubuntu1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms