Find the original file size of encrypted file

Hi,
I am trying to find out the original file size of an encrypted file in SunOS.
The file was decrypted with gpg command.

I want to know the size of the orginal file without decrypting it. I am using the below command, but it is not working for big files(more than 1 GB).

gpg --passphrase "password" --list-packets <File-Name>

Please help me to find the size of original files without decrypting the data as ther are many files.

Thanks,
Vipin

Could you try:-

gpg -d --passphrase "password" filename | wc -c

Does that do what you need?

The --list-packets option apparently .... List only the sequence of packets. according to my manual pages, and this won't give you the file size, if that's what you are after.

I hope that this helps,
Robin

1 Like

Thanks rbatte1....its working and giving me the result. But it is very slow, if it is a large file.Could you help me to find is there any way we can make the execution fast for this command.

Except that in order to write to a pipe the result has to be decrypted first.

I saw this request earlier and could not think of a way around the requirement of reading the entire file and decrypting the data.

It seems to me like you may not see what is really going on. rbatte's example is very good but it does open and read the file.

You could also decrypt the file to /tmp (tmpfs file system) which in solaris is actually memory manged by the kernel. Not disk. Very fast. Pipes can be implemented as shared memory objects as well. If you do that, delete all the files in /tmp as you go.

i think that if you have a huge input file, it will take time whatever method you use. There is no table-of-contents idea, so there is no way to know what the expected size will be. Perhaps you could consider a different approach:-

  • Get the file name & size of the plain file before encryption[*]Get a checksum of the file after encryption and link to the above

When you need the information, you can get the values from wherever you stored it a validate that the encrypted file is the same one by generating the current checksum.

It will still read the file to generate the checksum when you want to validate it, but it does not need to do decryption processing, so that might save a bit.

Basically though, large files will take time.......

Robin