I can openssl encrypt a ffmpeg video stream with

 ffmpeg -i  video1.mp4-video1.mp4.mp4 -f ogg -  | 
 openssl enc -des3 > outptu.ogg.des3

Which strategy would you use to encrypt the ffmpeg output when generating chunks (say of given duration) given by the command:

ffmpeg -f video4linux2 -s vga -i /dev/video0 -f segment -segment_time 1\
-strftime 1 '%Y-%m-%d_%H-%M-%S.ts'

I need to have %Y-%m-%d_%H-%M-%S.ts.des3 instead of %Y-%m-%d_%H-%M-%S.ts

I would love using a name pipe, but it means I have to detect file headers and footers of each chunks generated by ffmpeg.

I guess the straightest solution is to run a background script that encrypt automatically new detected files.


1 Answer 1


You are using the wrong tool for the job. Instead of piping the output into OpenSSL, write the output to a file which is located on an encrypted filesystem. Encrypted filesystems are designed for random access, file encryption tools such as openssl enc rarely are.

Furthermore openssl enc is bad crypto and should never be used. You're using DES3, which while still legally admissible by some standards is strongly deprecated in favor of AES. And the worst bit is that the way openssl derives a key from a password is ridiculously bad — it doesn't use a proper key stretching function, so brute-forcing through passwords is easy. Using the openssl command line tool for encryption is hard to do right and is never the best tool for the job. Just forget that openssl exists and use proper tools for the job, e.g. LUKS for full disk encryption, Ecryptfs for home directory encryption, gpg or 7z for per-file encryption. Even EncFS to mount an encrypted directory, while flawed, is a lot less broken than openssl.

  • openssl supports the AES standard if you use the command: "openssl aes-256-cbc" - To get a full list of supported modes type "openssl help" You can even use an advanced key derivation algorithm. Just run the password through something like argon2 first: /lib/cryptsetup/askpass 'Enter Password:' | argon2 YOURSALT -m 20 -r and then use that password for openssl. Jun 2, 2019 at 16:52
  • @Benjamin The openssl command line is the wrong tool for the job even if you manage to find correct parameters. The fact that you need another tool for the PBKDF is another reason why it's the wrong tool for the job. Jun 2, 2019 at 18:56
  • Oh I agree there's better tools for the job like GPG. I did some searching and apparently the latest version of openssl (1.1.1) has a -pbkdf2 option which finally fixes its weak key derivation, but that's not even available for Ubuntu unless you compile from source. It's very bizarre. Jun 2, 2019 at 20:16
  • @Benjamin The openssl command line tool is primarily designed as a debugging tool, to test openssl and to manipulate keys and certificates. What's bizarre is that people insist on using it for storage and message encryption instead of tools made for that purpose such as gpg. Jun 2, 2019 at 20:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.