Base64编码安全的文件名? [英] Base64 Encoding safe for filenames?

查看:176
本文介绍了Base64编码安全的文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows和Linux系统上,Base64编码是否安全用于文件名?从我的研究中,我发现用 - _替换结果的所有 / 应该解决任何问题。



任何人都可以提供更多详细信息?



目前在Java中,我使用以下代码:

  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('/','_');


解决方案

修改Base64(当 / = + 被替换)可以安全地创建名称,但不能保证反向由于许多文件系统和URL的不区分大小写而导致转换。



Base64区分大小写,因此在不区分大小写的文件系统的情况下不会保证1对1的映射(所有Windows文件系统,忽略POSIX子系统的情况)。大多数URL也是不区分大小写的,可以防止1对1的映射。



在这种情况下,我会使用Base32 - 你会得到更长的名字,但是Base32编码的值是100%安全的文件/ uri使用,而不替换任何字符,并保证1到1的映射,即使在不敏感的环境(FAT / Win32 NTFS访问)的情况下。



不幸的是,在框架中通常没有内置的这种编码支持。另一方面,代码编写比较简单,或者在线查找。



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


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('/','_');

解决方案

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.

这篇关于Base64编码安全的文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆