3

I need to encrypt and be able to decrypt files with openssl, currently I do this simply with:

openssl enc -aes-256-cbc -salt -in "$input_filename" -out "$output_filename"

and the decryption with:

openssl enc -aes-256-cbc -d -salt -in "$input_filename" -out "$output_filename"

But with large files, I would like to see progress.

I tried different variations of the following (decryption):

pv "$input_filename" | openssl enc -aes-256-cbc -d -salt | pv > "$output_filename"

But this fails to ask me for a password. I am unsure as to how to go about it?

EDIT1:

I found this tar over openssl:

https://stackoverflow.com/a/24704457/1997354

While it could be extremely helpful, I don't get it much.

EDIT2:

Regarding the named pipe:

It almost works. Except for the blinking progress, which I can't show you obviously and the final result looking like this:

enter aes-256-cbc decryption password:
1.25GiB 0:00:16 [75.9MiB/s] [==============================================================================================================================================================================================>] 100%            
1.25GiB 0:00:10 [ 126MiB/s] [                                             <=>                                                                                                                                                                ]
  • This isn’t an answer since your question specifically asks for pv, but you could use progress to track openssl’s progress. – Stephen Kitt Dec 8 '17 at 19:07
5

You should try

openssl enc -aes-256-cbc -d -salt -in "$input_filename" | pv -W >> "$output_filename"

From the Manual:

-W, --wait:

Wait until the first byte has been transferred before showing any progress information or calculating any ETAs. Useful if the program you are piping to or from requires extra information before it starts, eg piping data into gpg(1) or mcrypt(1) which require a passphrase before data can be processed.

which is exactly your case. If you need to see the progress bar, for the reason clearly explained by Weijun Zhou in a comment below, you can reverse the order of the commands in the pipe:

pv -W "$input_filename" | openssl enc -aes-256-cbc -d -salt -out "$output_filename"
2

You need named pipe here.

$ mkfifo mypipe
$ pv < mypipe > "$output_filename"|(pv "$input_filename" | openssl enc -aes-256-cbc -d -salt -out mypipe)

The output of the two pv commands will show alternately at the bottom of your tty window. Not sure whether it is what you really need, though. If you only need the output of the pv in pv "$input_filename", modify the above command accordingly.

Edit

After obtaining more information from the OP, I am now sure that

pv "$input_filename" | openssl enc -aes-256-cbc -d -salt -out "$output_filename"

is enough to address OP's real needs.

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.