I used to download files and then use openssl to encrypt them, which is not enough for me. How can I encrypt the download gradually as the file is being downloaded?

I thought about using curl and an openssl pipe but cannot figure it out.

Is there any better tool to perform this?

3 Answers 3


The command would simply be:

curl -s "$URL" | openssl aes-256-cbc > "$OUTPUT_FILE"
  • Comments are not for extended discussion; the entire conversation that was taking place here has been moved to chat.
    – Thomas Ward
    Oct 6, 2016 at 13:30

I do not think that this is possible (It seems I have been proven wrong on this).

However, provided the reason this is not enough for you, is that you don't want an unencrypted version of the file being stored on your drive (and potentially being restored by somebody in the future) you could use a ramdisk to temporarily store the file and encrypt it there before moving it to its destination directory.

Depending on your paranoia level and thread scenario, simply using an encrypted drive would suffice.

  • There's nothing in principle to prevent encrypting a stream of data, it's what happens when you download a huge file over HTTPS and it's basically what an encrypted drive would also do.
    – ilkkachu
    Oct 5, 2016 at 16:16
  • 1
    @ilkkachu I understood that from the rather extensive discussion in the comment section of WCCs answer, which should be the accepted ;-). Nonetheless, I will not remove this answer, as I think it provides an alternative which might be useful in other scenarios.
    – Bruni
    Oct 5, 2016 at 16:38

You can also use a mountable, filesystem-level encrypted filesystem, as EncFS or CryFS. Mount your encrypted directory and download files there. Not sure if this solves your problem, as it is not clear to me what exactly your problem is.

  • It would be nice if you could expand your answer a bit by adding some basic instructions (and maybe a link for further reading) on how one can set up such an encrypted container. Thanks and welcome to Ask Ubuntu.
    – Byte Commander
    Oct 8, 2016 at 19:05

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.