0

I would like to batch obfuscate file names (not file content) with a simple symmetric cipher. So that I can rename them back afterwards. For example, using the online blowfish encryption on http://sladex.org/blowfish.js/ with key "hello", ECB cipher mode and output format hex, the files would be renamed as follows

"file001.dat" -> "76d35b129cf450413745c5da58473475"
"file002.dat" -> "74dcf32b30bed1e53745c5da58473475"
"file003.dat" -> "a387a582c6431b423745c5da58473475"

I have no requirement for a strong cipher, only that files can easily be renamed back again.

Can this be done with the command line on Mac?

1 Answer 1

0

You can use openssl and xxd together for this.

To encrypt the filenames:

% ls
file001.dat file002.dat file003.dat
% for f in *.dat; do; mv $f $(echo $f | openssl blowfish -salt -pass pass:somepassword | xxd -ps -c 200); done
% ls
53616c7465645f5f027d297a5dffe2a6dce4ae35392bfbe8c78acbfa8985081b    53616c7465645f5fff47f252c9403c6f31a23e5fd26578a8d36e24651735dae9
53616c7465645f5f90c1b56fed45fb9b3beb431c4984be0852d6b047c2a564ca

To decrypt:

% for f in 53*; do; mv $f $(echo $f | xxd -ps -r | openssl blowfish -d -salt -pass pass:somepassword); done
% ls
file001.dat file002.dat file003.dat

Probably details I haven't solved here, but the gist is there. If your directory contains only these files, you can skip the funny guess glob of 53*, and just use *.

I'm using zsh, btw. Not sure if the syntax translates to bash, but it should, I think...

1
  • Thanks! Works with zsh, not bash :-) Commented Oct 28, 2022 at 11:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .