How to use pv to show progress of openssl encryption / decryption

encryptionopensslpv

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] [                                             <=>                                                                                                                                                                ]

Best Answer

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"
Related Question