Score:0

Using openssl smime to email binary files on Linux

mw flag

I want to be able to send automated encrypted email from Linux to Microsoft Outlook user’s email. I know little about S/MIME but I have managed to accomplish sending encrypted text emails using this Linux command line:

openssl smime -encrypt -aes256 -in email_contents.txt -text -subject "Encrypted email test" -to username@domain username.pem | sendmail username@domain

In the above username.pem is the public encryption key previously extracted from a user’s PIV (Personal Identity Verification) card, also known as a CAC card or Smart card. The email recipient, in this case username@domain, can then read that encrypted email in Outlook using their PIV card which has the matching private key. No one else can read the email because they don’t have the PIV card with the private key. What they read in the decrypted email is what was in the text file email_contents.txt. It all works. So far so good.

What I want to do but in my inexperience have not been able to figure out how to do is send a binary file, such as an Excel spreadsheet, in an encrypted mail. Ideally this would be as an attachment (encrypted) to the encrypted email that also has text content explaining what the attachment is about. I know how to have such an attachment to a “plain MIME” non-encrypted email but I need to know how to do it all encrypted, if that is possible. All from the command line so it can be automated.

I have done quite a bit of Google searching (where I figured out how to email an encrypted text message as seen above) but so far can’t figure out emailing an encrypted binary file or encrypted binary attachment.

Anyone know how to do this?

not2savvy avatar
ar flag
openssl smime can encrypt a MIME mail for you, but it’s not suitable to compose the parts of a Multi-part MIME mail which you need here. So you’ll have to compose a Multi-part MIME mail, of which one is the file attachment, first, then use openssl smime to encrypt it. You’ll need additional tools to accomplish that task.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.