Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Base64 Encoding safe for filenames?

Is Base64 encoding safe to use for filenames on Windows and Linux systems? From my research I have found that replacing all / characters of the result with - or _ should resolve any issues.

Can anyone provide more details on this?

Currently in Java I am using the following peice of code:

MessageDigest md5Digest = MessageDigest.getInstance("MD5"); md5Digest.reset(); md5Digest.update(plainText.getBytes());  byte[] digest = md5Digest.digest();  BASE64Encoder encoder = new BASE64Encoder(); hash = encoder.encode(digest); hash.replace('/','_'); 
like image 393
cweston Avatar asked Oct 15 '10 19:10

cweston


People also ask

Is base64 encoding secure?

Base64 is an encoding scheme originally designed to allow binary data to be represented as ASCII text. Widespread in its use, base64 seems to provide a level of security by making sensitive information difficult to decipher.

Is base64 decode safe?

base64 data is just text. it can't do anything. and whatever you decode from it can be safe as well, if you use that data properly.

What is base64 encoding good for?

Base64 encoding schemes are commonly used when there is a need to encode binary data that needs to be stored and transferred over media that are designed to deal with ASCII. This is to ensure that the data remain intact without modification during transport.

Are base64 strings URL safe?

Encoding data into base64 format By consisting only of ASCII characters, base64 strings are generally url-safe, and that's why they can be used to encode data in Data URLs.


1 Answers

Modified Base64 (when /,= and + are replaced) is safe to create names but does not guarantee reverse transformation due to case insensitivity of many file systems and urls.

Base64 is case sensitive, so it will not guarantee 1-to-1 mapping in cases of case insensitive file systems (all Windows files systems, ignoring POSIX subsystem cases). Most urls also case insensitive preventing 1-to-1 mapping.

I would use Base32 in this case - you'll get names a bit longer, but Base32 encoded values are 100% safe for file/uri usage without replacing any characters and guarantees 1-to-1 mapping even in cases of insensitive environment (FAT/Win32 NTFS access).

Unfortunately there is usually no built-in support for this encoding in frameworks. On other hand code is relatively simple to write yourself or find online.

http://en.wikipedia.org/wiki/Base32.

like image 178
Alexei Levenkov Avatar answered Sep 28 '22 02:09

Alexei Levenkov