Simple way to encode data on flash drive

0

I have a USB flash drive and would like to base-64 (or similar) encode all the files/folders (recursively) under a certain parent directory on it; let's call it "toEncode".

It would be preferable to be able to encode and decode these files whenever I want: decode the toEncode directory, modify any part of its child folders/files, and then re-encode it. I'm on Ubuntu 12.04 desktop. Ideas?

user3178622

Posted 2014-01-20T21:40:30.007

Reputation: 131

1Encoding is not the same as encrypting. The former translates data from one representation to a smaller code set (for example Unicode to ASCII) and the latter translates (generally) into a binary form unreadable without some secret code. – l0b0 – 2014-01-20T21:54:24.350

Thanks but I know the difference and do mean encode! – user3178622 – 2014-01-20T22:19:12.020

1If so, what is the use case? I can't think of any reason why you'd want to do this, but maybe you have one? – l0b0 – 2014-01-20T22:21:45.920

The use case is irrelevant backstory that shouldn't be used to clutter up the SU databases. I'm simply wondering if this is possible and if so how – user3178622 – 2014-01-20T22:36:31.767

You'll have it much easier if you break your problem into its constituents: You want to do one operation recursively on several files; the operation happens to be base64 encoding/decoding. Both parts taken by themselves are trivial, without knowing what you are trying to accomplish it's difficult to give any meaningful advice. – Vucar Timnärakrul – 2014-01-20T22:55:08.827

Why not just write a simple program to do it? It's maybe 200 lines of Java, if you have the Base64 routine already. Probably a bit more complicated in C. Anyone with basic programming skills should be able to do it. – Daniel R Hicks – 2014-01-20T23:15:47.203

Answers

1

To encode:

base64 file.xyz > encoded.b64

To decode:

base64 -d encoded.b64 > file.xyz

For more information:

man base64

To find such commands, it's useful to search using commands like these:

apropos -r 'base.*64'
apt-cache search 'base.*64'

l0b0

Posted 2014-01-20T21:40:30.007

Reputation: 6 306

Awesome thanks @I0b0 (+1) do you know if base64 is recursive and works on directories? – user3178622 – 2014-01-20T22:45:57.820

1

Nope, it's definitely one file at a time. I don't think your use case is really all that common, so it might help avoiding an X-Y problem if you post more details.

– l0b0 – 2014-01-20T22:48:50.483

Of course not: As a filter, by design it works on single files only. You'll have to build the recursion yourself, maybe by a combination of find and a little scripting. – Vucar Timnärakrul – 2014-01-20T22:51:48.173

1

If you're just looking to encrypt data on a flash drive, there are far better tools than trying to do it manually.

http://www.truecrypt.org/

Xavier J

Posted 2014-01-20T21:40:30.007

Reputation: 640

Thanks @codenoire (+1) but I do want base 64 encoding here... Ideas? – user3178622 – 2014-01-20T22:20:22.557

You might be thinking of what happens if you need to stop this sort of operation during the middle of processing a whole bunch of files. Some will be encoded, and some will not. If any of the original set of files were actually already base64-encoded data, you're going to have a heck of a time trying to recover. – Xavier J – 2014-01-20T23:26:01.163