PDA

View Full Version : [SOLVED] bash & gpg/openssl/mcrypt, overwrite input file



chukchuck
September 14th, 2011, 10:56 PM
I'm writing a bash script that has to encrypt a file with GPG or OpenSSL or mcrypt but i've a problem: i cannot overwrite input file.
I don't want to shred or wipe the original file, i want to overwrite it.
Is it possible?
There's a way to do this?
Thanks :popcorn:

Vaphell
September 14th, 2011, 11:16 PM
overwrite as in some_command file > file ?
that won't fly
create temporary output file and when the operation ends just move it in the place of original version.

chukchuck
September 15th, 2011, 07:47 AM
overwrite as in some_command file > file ?
that won't fly

That doesn't work...after this command you're unable to decrypt the file!



create temporary output file and when the operation ends just move it in the place of original version.

?? You mean this??


gpg -o file.gpg -c file
mv file.gpg file

fdrake
September 15th, 2011, 08:22 AM
=D> that's it!.. you cannot read and change at the same time an input file in bash.

chukchuck
September 15th, 2011, 11:48 AM
Oh yes i'm an idiot xD the simplest solution is the best solution :D
But i've a last doubt: is this secure?

fdrake
September 15th, 2011, 11:51 AM
Oh yes i'm an idiot xD the simplest solution is the best solution :D
But i've a last doubt: is this secure?

once you mv a file to another there is no way to get back (it gets wipe out of the memory it does not go in the trash) that first file unless you do some kind of disk recovery, but even then, good luck with it!

chukchuck
September 15th, 2011, 12:29 PM
that's good :D