0
$\begingroup$

I'm looking to encrypt (rename) mutiple files name based on a passphrase. Currently the passphrase would be numeric but I can change that to something else if required.

I would like to be able to get a encrypted file name in numeric and/or letter (avoid any special char since they are not allowed in filename) and to be able to decrypt the file name using a passphrase.

Is it possible to encrypt the filename with a function (I'm using C#) that would not allow a hacker to reverse engineer the function and then be able to decrypt the filename. Like a one way encryption but with the possibility for me to use a different decryption function on my own system to decrypt the filename.

Thanks for your ideas!

$\endgroup$
3
  • $\begingroup$ Do you want to encrypt only the name of the file, or also the contents of the file? $\endgroup$ May 4, 2015 at 18:18
  • $\begingroup$ A quick google shows that the .Net library System.Security.Cryptography has ALL SORTS of useful goodies in it. You should probably have a look in there for something that you can use. $\endgroup$ May 4, 2015 at 18:21
  • $\begingroup$ you need format-preserving encryption (transforming strings to strings), but I don't got a reference. $\endgroup$
    – SEJPM
    May 4, 2015 at 19:08

1 Answer 1

1
$\begingroup$

SOJPM already noted in the comments format-preserving encryption (Wiki Link), that should do the trick.

Simply speaking, FPE allows you a proper encryption method based on any arbitrary subset you want. In your case, that would be the common symbols in filenames, although you might want to be more restrictive to limit yourself to alphanumeric values.

FPE is a technique, which can be constructed in various ways, a few of them can be found in that wikipedia link at the beginning. I don't know if there are any available implementations of that, so you might have to do some of it on your own.

About your question with a passphrase:

You can do that, by using a well known Password-Based Key Derivation Function(PBKDF), e.g. scrypt or bcrypt to generate a key from your passphrase. And that key is then used in the FPE construction.

$\endgroup$
1
  • $\begingroup$ If it's OK for the encrypted file names to (always) be longer than the originals, it would probably be easiest and safest to just encode the encrypted names in Base36 or Base32. If you wish to support any filenames that the underlying filesystem allows, things get trickier. (For filesystems like NTFS that are case-preserving but not case-sensitive, it might not even be possible.) $\endgroup$ May 5, 2015 at 19:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.