Base64 编码对文件名安全吗?

Base64 Encoding safe for filenames?(Base64 编码对文件名安全吗?)

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

问题描述

Base64 编码是否可以安全地用于 Windows 和 Linux 系统上的文件名?根据我的研究,我发现用 -_ 替换结果的所有 / 字符应该可以解决任何问题.

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.

谁能提供更多细节?

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

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

推荐答案

修改Base64(当/,=+被替换时)创建名称是安全的,但由于许多文件系统和 url 不区分大小写,因此不能保证反向转换.

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 区分大小写,因此在不区分大小写的文件系统(所有 Windows 文件系统,忽略 POSIX 子系统情况)的情况下,它不能保证一对一的映射.大多数 url 也不区分大小写,防止一对一映射.

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.

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

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 编码对文件名安全吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Base64 编码对文件名安全吗?

基础教程推荐